Previous 15994 Revisions Next

r937 Saturday 8th September, 2007 at 00:57:50 UTC by Nathan Woods
Updated to 0.118u5 core - some changes in palette and CHD handling are error
prone, so watch out
[docs]messnew.txt
[src/emu]audit.c clifront.c cpuintrf.c cpuintrf.h drawgfx.c drawgfx.h driver.c driver.h emu.mak emuopts.c emuopts.h emupal.c* emupal.h* fileio.c info.c mame.h mamecore.h memconv.h render.c render.h rendlay.c romload.c romload.h sound.c tilemap.h ui.c uigfx.c validity.c video.c
[src/emu/cpu]cpu.mak x86emit.h
[src/emu/cpu/arm7]arm7dasm.c
[src/emu/cpu/h83002]h83002.c h8disasm.c
[src/emu/cpu/nec]necdasm.c
[src/emu/cpu/powerpc]ppc.c ppc.h ppc_ops.c ppcdrc.c
[src/emu/debug]express.c
[src/emu/drivers]empty.c
[src/lib]lib.mak
[src/lib/expat]xmlparse.c
[src/lib/util]bitmap.c bitmap.h chd.c chd.h palette.c* palette.h* png.c
[src/mame]mame.mak mamedriv.c
[src/mame/audio]gottlieb.c
[src/mame/drivers]bankp.c baraduke.c bfm_sc2.c bishjan.c* coolpool.c cps2.c cps3.c cubocd32.c darius.c ddrible.c dec8.c deniam.c docastle.c dynax.c equites.c galaga.c gaplus.c hornet.c ironhors.c istellar.c jrpacman.c ksys573.c lastfght.c legionna.c limenko.c mediagx.c mpu4.c namcoic.c namcona1.c nemesis.c nwk-tr.c pacland.c paradise.c polepos.c rockola.c royalmah.c seibuspi.c speglsht.c* srmp2.c st0016.c taitowlf.c thayers.c thepit.c vamphalf.c vulgus.c wilytowr.c
[src/mame/includes]amiga.h cubocd32.h* docastle.h m107.h m72.h m92.h taitoipt.h
[src/mame/machine]amiga.c bublbobl.c cps2crpt.c cubocd32.c* konamigx.c playch10.c snes.c vsnes.c wd33c93.c wd33c93.h
[src/mame/video]20pacgal.c arabian.c atarigt.c atarimo.c atarisy1.c balsente.c bankp.c bbusters.c bosco.c bwing.c circus.c deco16ic.c deco32.c deco_mlc.c digdug.c djmain.c dkong.c docastle.c equites.c exerion.c gaiden.c galaga.c gaplus.c genesis.c gridlee.c hyprduel.c jalblend.c kaneko16.c konamiic.c m62.c magmax.c mappy.c metro.c mpatrol.c n64.c namcona1.c namcos22.c namcos86.c nbmj8891.c pacland.c pacman.c plygonet.c polepos.c psikyosh.c qix.c rockola.c rungun.c segaic24.c seibuspi.c seta.c snes.c spbactn.c sprint4.c st0016.c stvvdp2.c suprloco.c system1.c system16.c taito_f2.c taito_f3.c taitoic.c taitojc.c tatsumi.c tceptor.c tecmo16.c thepit.c toaplan1.c toypop.c tubep.c twin16.c ultratnk.c vulgus.c wecleman.c xevious.c
[src/mess]image.c image.h mess.h mess.mak
[src/mess/devices]chd_cd.c harddriv.c
[src/mess/machine]gb.c
[src/mess/tools/imgtool]imghd.c stream.c stream.h
[src/mess/video]arcadia.c avigo.c gb.c odyssey2.c pc_t1t.c ted7360.c vc4000.c vic6560.c x68k.c
[src/osd/windows]drawd3d.c drawdd.c windows.mak
[src/tools]chdman.c

src/mame/audio/gottlieb.c
r936r937
1414
1515   if ((data&0x0f) != 0xf) /* interrupt trigered by four low bits (not all 1's) */
1616   {
17      if (sndti_to_sndnum(SOUND_SAMPLES, 0) >= 0)
17      if (sndti_exists(SOUND_SAMPLES, 0))
1818      {
1919         if (!strcmp(Machine->gamedrv->name,"reactor"))   /* reactor */
2020         {
r936r937
9191   if (!strcmp(Machine->gamedrv->name,"reactor"))   /* reactor */
9292   {
9393   }
94   else if (sndti_to_sndnum(SOUND_SAMPLES, 0) != -1)   /* qbert */
94   else if (sndti_exists(SOUND_SAMPLES, 0))   /* qbert */
9595      sample_start(0,44,0);
9696}
9797
src/mame/machine/cubocd32.c
r0r937
1#include "driver.h"
2#include "includes/amiga.h"
3#include "cdrom.h"
4#include "coreutil.h"
5#include "sound/cdda.h"
6
7
8/*********************************************************************************
9
10    Akiko custom chip emulation
11
12The Akiko chip has:
13- built in 1KB NVRAM
14- chunky to planar converter
15- custom CDROM controller
16
17TODO: Add CDDA support
18
19*********************************************************************************/
20
21#define LOG_AKIKO      0
22#define LOG_AKIKO_I2C   0
23#define LOG_AKIKO_CD   0
24
25#define CD_SECTOR_TIME      (1000/((150*1024)/2048))   /* 1X CDROM sector time in msec (300KBps) */
26
27
28/*************************************
29 *
30 * Akiko I2C NVRAM implementation
31 *
32 ************************************/
33
34enum {
35   I2C_WAIT = 0,
36   I2C_DEVICEADDR,
37   I2C_WORDADDR,
38   I2C_DATA
39};
40
41#define   NVRAM_SIZE 1024
42#define   NVRAM_PAGE_SIZE   16   /* max size of one write request */
43
44struct akiko_def
45{
46   /* chunky to planar converter */
47   UINT32   c2p_input_buffer[8];
48   UINT32   c2p_output_buffer[8];
49   UINT32   c2p_input_index;
50   UINT32   c2p_output_index;
51
52   /* i2c bus */
53   int      i2c_state;
54   int      i2c_bitcounter;
55   int      i2c_direction;
56   int      i2c_sda_dir_nvram;
57   int      i2c_scl_out;
58   int      i2c_scl_in;
59   int      i2c_scl_dir;
60   int      i2c_oscl;
61   int      i2c_sda_out;
62   int      i2c_sda_in;
63   int      i2c_sda_dir;
64   int      i2c_osda;
65
66   /* nvram */
67   UINT8   nvram[NVRAM_SIZE];
68   UINT8   nvram_writetmp[NVRAM_PAGE_SIZE];
69   int      nvram_address;
70   int      nvram_writeaddr;
71   int      nvram_rw;
72   UINT8   nvram_byte;
73
74   /* cdrom */
75   UINT32   cdrom_status[2];
76   UINT32   cdrom_address[2];
77   UINT32   cdrom_track_index;
78   UINT32   cdrom_lba_start;
79   UINT32   cdrom_lba_end;
80   UINT32   cdrom_lba_cur;
81   UINT16   cdrom_readmask;
82   UINT16   cdrom_readreqmask;
83   UINT32   cdrom_dmacontrol;
84   UINT32   cdrom_numtracks;
85   UINT8   cdrom_speed;
86   UINT8   cdrom_cmd_start;
87   UINT8   cdrom_cmd_end;
88   UINT8   cdrom_cmd_resp;
89   cdrom_file *cdrom;
90   UINT8 *   cdrom_toc;
91   mame_timer *dma_timer;
92   mame_timer *frame_timer;
93} akiko;
94
95static TIMER_CALLBACK(akiko_dma_proc);
96static TIMER_CALLBACK(akiko_frame_proc);
97
98void amiga_akiko_init(void)
99{
100   akiko.c2p_input_index = 0;
101   akiko.c2p_output_index = 0;
102
103   akiko.i2c_state = I2C_WAIT;
104   akiko.i2c_bitcounter = -1;
105   akiko.i2c_direction = -1;
106   akiko.i2c_sda_dir_nvram = 0;
107   akiko.i2c_scl_out = 0;
108   akiko.i2c_scl_in = 0;
109   akiko.i2c_scl_dir = 0;
110   akiko.i2c_oscl = 0;
111   akiko.i2c_sda_out = 0;
112   akiko.i2c_sda_in = 0;
113   akiko.i2c_sda_dir = 0;
114   akiko.i2c_osda = 0;
115
116   akiko.nvram_address = 0;
117   akiko.nvram_writeaddr = 0;
118   akiko.nvram_rw = 0;
119   akiko.nvram_byte = 0;
120   memset( akiko.nvram, 0, NVRAM_SIZE );
121
122   akiko.cdrom_status[0] = akiko.cdrom_status[1] = 0;
123   akiko.cdrom_address[0] = akiko.cdrom_address[1] = 0;
124   akiko.cdrom_track_index = 0;
125   akiko.cdrom_lba_start = 0;
126   akiko.cdrom_lba_end = 0;
127   akiko.cdrom_lba_cur = 0;
128   akiko.cdrom_readmask = 0;
129   akiko.cdrom_readreqmask = 0;
130   akiko.cdrom_dmacontrol = 0;
131   akiko.cdrom_numtracks = 0;
132   akiko.cdrom_speed = 0;
133   akiko.cdrom_cmd_start = 0;
134   akiko.cdrom_cmd_end = 0;
135   akiko.cdrom_cmd_resp = 0;
136   akiko.cdrom = cdrom_open(get_disk_handle(0));
137   akiko.cdrom_toc = NULL;
138   akiko.dma_timer = mame_timer_alloc(akiko_dma_proc);
139   akiko.frame_timer = mame_timer_alloc(akiko_frame_proc);
140
141   /* create the TOC table */
142   if ( akiko.cdrom != NULL && cdrom_get_last_track(akiko.cdrom) )
143   {
144      UINT8 *p;
145      int      i, addrctrl = cdrom_get_adr_control( akiko.cdrom, 0 );
146      UINT32   discend;
147
148      discend = cdrom_get_track_start(akiko.cdrom,cdrom_get_last_track(akiko.cdrom)-1);
149      discend += cdrom_get_toc(akiko.cdrom)->tracks[cdrom_get_last_track(akiko.cdrom)-1].frames;
150      discend = lba_to_msf(discend);
151
152      akiko.cdrom_numtracks = cdrom_get_last_track(akiko.cdrom)+3;
153
154      akiko.cdrom_toc = (UINT8*)auto_malloc(13*akiko.cdrom_numtracks);
155      memset( akiko.cdrom_toc, 0, 13*akiko.cdrom_numtracks);
156
157      p = akiko.cdrom_toc;
158      p[1] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
159      p[3] = 0xa0; /* first track */
160      p[8] = 1;
161      p += 13;
162      p[1] = 0x01;
163      p[3] = 0xa1; /* last track */
164      p[8] = cdrom_get_last_track(akiko.cdrom);
165      p += 13;
166      p[1] = 0x01;
167      p[3] = 0xa2; /* disc end */
168      p[8] = (discend >> 16 ) & 0xff;
169      p[9] = (discend >> 8 ) & 0xff;
170      p[10] = discend & 0xff;
171      p += 13;
172
173      for( i = 0; i < cdrom_get_last_track(akiko.cdrom); i++ )
174      {
175         UINT32   trackpos = cdrom_get_track_start(akiko.cdrom,i);
176
177         trackpos = lba_to_msf(trackpos);
178         addrctrl = cdrom_get_adr_control( akiko.cdrom, i );
179
180         p[1] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
181         p[3] = dec_2_bcd( i+1 );
182         p[8] = (trackpos >> 16 ) & 0xff;
183         p[9] = (trackpos >> 8 ) & 0xff;
184         p[10] = trackpos & 0xff;
185
186         p += 13;
187      }
188   }
189}
190
191static void akiko_i2c( void )
192{
193    akiko.i2c_sda_in = 1;
194
195    if ( !akiko.i2c_sda_dir_nvram && akiko.i2c_scl_out && akiko.i2c_oscl )
196    {
197      if ( !akiko.i2c_sda_out && akiko.i2c_osda )   /* START-condition? */
198      {
199          akiko.i2c_state = I2C_DEVICEADDR;
200          akiko.i2c_bitcounter = 0;
201          akiko.i2c_direction = -1;
202#if LOG_AKIKO_I2C
203          logerror("START\n");
204#endif
205          return;
206      }
207      else if ( akiko.i2c_sda_out && !akiko.i2c_osda ) /* STOP-condition? */
208      {
209          akiko.i2c_state = I2C_WAIT;
210          akiko.i2c_bitcounter = -1;
211#if LOG_AKIKO_I2C
212          logerror("STOP\n");
213#endif
214          if ( akiko.i2c_direction > 0 )
215          {
216            memcpy( akiko.nvram + ( akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1) ), akiko.nvram_writetmp, NVRAM_PAGE_SIZE );
217            akiko.i2c_direction = -1;
218#if LOG_AKIKO_I2C
219            {
220               int i;
221
222               logerror("NVRAM write address %04X:", akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1));
223               for (i = 0; i < NVRAM_PAGE_SIZE; i++)
224                   logerror("%02X", akiko.nvram_writetmp[i]);
225               logerror("\n");
226            }
227#endif
228          }
229          return;
230      }
231    }
232
233    if ( akiko.i2c_bitcounter >= 0 )
234    {
235      if ( akiko.i2c_direction )
236      {
237          /* Amiga -> NVRAM */
238          if ( akiko.i2c_scl_out && !akiko.i2c_oscl )
239          {
240            if ( akiko.i2c_bitcounter == 8 )
241            {
242                akiko.i2c_sda_in = 0; /* ACK */
243
244                if ( akiko.i2c_direction > 0 )
245                {
246                  akiko.nvram_writetmp[akiko.nvram_writeaddr++] = akiko.nvram_byte;
247                  akiko.nvram_writeaddr &= (NVRAM_PAGE_SIZE - 1);
248                  akiko.i2c_bitcounter = 0;
249                }
250                else
251                {
252                   akiko.i2c_bitcounter = -1;
253                }
254             }
255             else
256             {
257                akiko.nvram_byte <<= 1;
258                akiko.nvram_byte |= akiko.i2c_sda_out;
259                akiko.i2c_bitcounter++;
260            }
261          }
262      }
263      else
264      {
265         /* NVRAM -> Amiga */
266         if ( akiko.i2c_scl_out && !akiko.i2c_oscl && akiko.i2c_bitcounter < 8 )
267         {
268            if ( akiko.i2c_bitcounter == 0 )
269               akiko.nvram_byte = akiko.nvram[akiko.nvram_address];
270
271            akiko.i2c_sda_dir_nvram = 1;
272            akiko.i2c_sda_in = (akiko.nvram_byte & 0x80) ? 1 : 0;
273            akiko.nvram_byte <<= 1;
274            akiko.i2c_bitcounter++;
275
276            if ( akiko.i2c_bitcounter == 8 )
277            {
278#if LOG_AKIKO_I2C
279                logerror("NVRAM sent byte %02X address %04X\n", akiko.nvram[akiko.nvram_address], akiko.nvram_address);
280#endif
281                akiko.nvram_address++;
282                akiko.nvram_address &= NVRAM_SIZE - 1;
283                akiko.i2c_sda_dir_nvram = 0;
284            }
285          }
286
287          if ( !akiko.i2c_sda_out && akiko.i2c_sda_dir && !akiko.i2c_scl_out ) /* ACK from Amiga */
288            akiko.i2c_bitcounter = 0;
289      }
290
291      if ( akiko.i2c_bitcounter >= 0 )
292         return;
293    }
294
295    switch( akiko.i2c_state )
296    {
297      case I2C_DEVICEADDR:
298         if ( ( akiko.nvram_byte & 0xf0 ) != 0xa0 )
299         {
300#if LOG_AKIKO_I2C
301            logerror("WARNING: I2C_DEVICEADDR: device address != 0xA0\n");
302#endif
303            akiko.i2c_state = I2C_WAIT;
304             return;
305         }
306
307         akiko.nvram_rw = (akiko.nvram_byte & 1) ? 0 : 1;
308
309         if ( akiko.nvram_rw )
310         {
311            /* 2 high address bits, only fetched if WRITE = 1 */
312            akiko.nvram_address &= 0xff;
313            akiko.nvram_address |= ((akiko.nvram_byte >> 1) & 3) << 8;
314             akiko.i2c_state = I2C_WORDADDR;
315             akiko.i2c_direction = -1;
316          }
317          else
318          {
319             akiko.i2c_state = I2C_DATA;
320             akiko.i2c_direction = 0;
321             akiko.i2c_sda_dir_nvram = 1;
322         }
323
324         akiko.i2c_bitcounter = 0;
325#if LOG_AKIKO_I2C
326         logerror("I2C_DEVICEADDR: rw %d, address %02Xxx\n", akiko.nvram_rw, akiko.nvram_address >> 8);
327#endif
328      break;
329
330      case I2C_WORDADDR:
331         akiko.nvram_address &= 0x300;
332         akiko.nvram_address |= akiko.nvram_byte;
333
334#if LOG_AKIKO_I2C
335         logerror("I2C_WORDADDR: address %04X\n", akiko.nvram_address);
336#endif
337         if ( akiko.i2c_direction < 0 )
338         {
339            memcpy( akiko.nvram_writetmp, akiko.nvram + (akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1)), NVRAM_PAGE_SIZE);
340             akiko.nvram_writeaddr = akiko.nvram_address & (NVRAM_PAGE_SIZE - 1);
341         }
342
343         akiko.i2c_state = I2C_DATA;
344         akiko.i2c_bitcounter = 0;
345         akiko.i2c_direction = 1;
346      break;
347    }
348}
349
350static void akiko_nvram_write(UINT32 data)
351{
352   int      sda;
353
354   akiko.i2c_oscl = akiko.i2c_scl_out;
355   akiko.i2c_scl_out = BIT(data,31);
356   akiko.i2c_osda = akiko.i2c_sda_out;
357   akiko.i2c_sda_out = BIT(data,30);
358   akiko.i2c_scl_dir = BIT(data,15);
359   akiko.i2c_sda_dir = BIT(data,14);
360
361   sda = akiko.i2c_sda_out;
362    if ( akiko.i2c_oscl != akiko.i2c_scl_out || akiko.i2c_osda != sda )
363    {
364       akiko_i2c();
365       akiko.i2c_oscl = akiko.i2c_scl_out;
366       akiko.i2c_osda = sda;
367    }
368}
369
370static UINT32 akiko_nvram_read(void)
371{
372   UINT32   v = 0;
373
374   if ( !akiko.i2c_scl_dir )
375       v |= akiko.i2c_scl_in ? (1<<31) : 0x00;
376   else
377       v |= akiko.i2c_scl_out ? (1<<31) : 0x00;
378
379   if ( !akiko.i2c_sda_dir )
380       v |= akiko.i2c_sda_in ? (1<<30) : 0x00;
381   else
382       v |= akiko.i2c_sda_out ? (1<<30) : 0x00;
383
384   v |= akiko.i2c_scl_dir ? (1<<15) : 0x00;
385   v |= akiko.i2c_sda_dir ? (1<<14) : 0x00;
386
387    return v;
388}
389
390NVRAM_HANDLER( cd32 )
391{
392   if (read_or_write)
393      /* save the SRAM settings */
394      mame_fwrite(file, akiko.nvram, NVRAM_SIZE);
395   else
396   {
397      /* load the SRAM settings */
398      if (file)
399         mame_fread(file, akiko.nvram, NVRAM_SIZE);
400      else
401         memset(akiko.nvram, 0, NVRAM_SIZE);
402   }
403}
404
405/*************************************
406 *
407 * Akiko Chunky to Planar converter
408 *
409 ************************************/
410
411static void akiko_c2p_write(UINT32 data)
412{
413   akiko.c2p_input_buffer[akiko.c2p_input_index] = data;
414   akiko.c2p_input_index++;
415   akiko.c2p_input_index &= 7;
416   akiko.c2p_output_index = 0;
417}
418
419static UINT32 akiko_c2p_read(void)
420{
421   UINT32 val;
422
423   if ( akiko.c2p_output_index == 0 )
424   {
425      int i;
426
427      for ( i = 0; i < 8; i++ )
428         akiko.c2p_output_buffer[i] = 0;
429
430      for (i = 0; i < 8 * 32; i++) {
431         if (akiko.c2p_input_buffer[7 - (i >> 5)] & (1 << (i & 31)))
432            akiko.c2p_output_buffer[i & 7] |= 1 << (i >> 3);
433      }
434   }
435   akiko.c2p_input_index = 0;
436   val = akiko.c2p_output_buffer[akiko.c2p_output_index];
437   akiko.c2p_output_index++;
438   akiko.c2p_output_index &= 7;
439   return val;
440}
441
442#if LOG_AKIKO
443static const char* akiko_reg_names[] =
444{
445   /*0*/   "ID",
446   /*1*/   "CDROM STATUS 1",
447   /*2*/   "CDROM_STATUS 2",
448   /*3*/   "???",
449   /*4*/   "CDROM ADDRESS 1",
450   /*5*/   "CDROM ADDRESS 2",
451   /*6*/   "CDROM COMMAND 1",
452   /*7*/   "CDROM COMMAND 2",
453   /*8*/   "CDROM READMASK",
454   /*9*/   "CDROM DMACONTROL",
455   /*A*/   "???",
456   /*B*/   "???",
457   /*C*/   "NVRAM",
458   /*D*/   "???",
459   /*E*/   "C2P"
460};
461
462const char* get_akiko_reg_name(int reg)
463{
464   if (reg < 0xf )
465   {
466      return akiko_reg_names[reg];
467   }
468   else
469   {
470      return "???";
471   }
472}
473#endif
474
475/*************************************
476 *
477 * Akiko CDROM Controller
478 *
479 ************************************/
480
481static void akiko_cdda_stop( void )
482{
483   int cddanum = cdda_num_from_cdrom(akiko.cdrom);
484
485   if (cddanum != -1)
486   {
487      cdda_stop_audio(cddanum);
488      mame_timer_reset( akiko.frame_timer, time_never );
489   }
490}
491
492static void akiko_cdda_play( UINT32 lba, UINT32 num_blocks )
493{
494   int cddanum = cdda_num_from_cdrom(akiko.cdrom);
495   if (cddanum != -1)
496   {
497      cdda_start_audio(cddanum, lba, num_blocks);
498      mame_timer_adjust( akiko.frame_timer, MAME_TIME_IN_HZ( 75 ), 0, time_zero );
499   }
500}
501
502static void akiko_cdda_pause( int pause )
503{
504   int cddanum = cdda_num_from_cdrom(akiko.cdrom);
505   if (cddanum != -1)
506   {
507      if (cdda_audio_active(cddanum) && cdda_audio_paused(cddanum) != pause )
508      {
509         cdda_pause_audio(cddanum, pause);
510
511         if ( pause )
512         {
513            mame_timer_reset( akiko.frame_timer, time_never );
514         }
515         else
516         {
517            mame_timer_adjust( akiko.frame_timer, MAME_TIME_IN_HZ( 75 ), 0, time_zero );
518         }
519      }
520   }
521}
522
523static UINT8 akiko_cdda_getstatus( UINT32 *lba )
524{
525   int cddanum = cdda_num_from_cdrom(akiko.cdrom);
526
527   if ( lba ) *lba = 0;
528
529   if (cddanum != -1)
530   {
531      if (cdda_audio_active(cddanum))
532      {
533         if ( lba ) *lba = cdda_get_audio_lba(cddanum);
534
535         if (cdda_audio_paused(cddanum))
536         {
537            return 0x12;   /* audio paused */
538         }
539         else
540         {
541            return 0x11;   /* audio in progress */
542         }
543      }
544      else if (cdda_audio_ended(cddanum))
545      {
546         return 0x13;   /* audio ended */
547      }
548   }
549
550   return 0x15;   /* no audio status */
551}
552
553static void akiko_set_cd_status( UINT32 status )
554{
555   akiko.cdrom_status[0] |= status;
556
557   if ( akiko.cdrom_status[0] & akiko.cdrom_status[1] )
558   {
559#if LOG_AKIKO_CD
560      logerror( "Akiko CD IRQ\n" );
561#endif
562      amiga_custom_w(REG_INTREQ, 0x8000 | INTENA_PORTS, 0);
563   }
564}
565
566static TIMER_CALLBACK(akiko_frame_proc)
567{
568   int cddanum = cdda_num_from_cdrom(akiko.cdrom);
569
570   (void)param;
571
572   if (cddanum != -1)
573   {
574      UINT8   s = akiko_cdda_getstatus(NULL);
575
576      if ( s == 0x11 )
577      {
578         akiko_set_cd_status( 0x80000000 );   /* subcode ready */
579      }
580
581      mame_timer_adjust( akiko.frame_timer, MAME_TIME_IN_HZ( 75 ), 0, time_zero );
582   }
583}
584
585static UINT32 lba_from_triplet( UINT8 *triplet )
586{
587   UINT32   r;
588
589   r = bcd_2_dec(triplet[0]) * (60*75);
590   r += bcd_2_dec(triplet[1]) * 75;
591   r += bcd_2_dec(triplet[2]);
592
593   return r;
594}
595
596static TIMER_CALLBACK(akiko_dma_proc)
597{
598   UINT8   buf[2352];
599   int      index;
600
601   if ( (akiko.cdrom_dmacontrol & 0x04000000) == 0 )
602      return;
603
604   if ( akiko.cdrom_readreqmask == 0 )
605      return;
606
607   index = (akiko.cdrom_lba_cur - akiko.cdrom_lba_start) & 0x0f;
608
609   if ( akiko.cdrom_readreqmask & ( 1 << index ) )
610   {
611      UINT32   track = cdrom_get_track( akiko.cdrom, akiko.cdrom_lba_cur );
612      UINT32   datasize = cdrom_get_toc( akiko.cdrom )->tracks[track].datasize;
613      UINT32   subsize = cdrom_get_toc( akiko.cdrom )->tracks[track].subsize;
614      UINT32   secsize = datasize + subsize;
615      int      i;
616
617      if ( secsize <= (2352-16) )
618      {
619         UINT32   curmsf = lba_to_msf( akiko.cdrom_lba_cur );
620         memset( buf, 0, 16 );
621
622         buf[3] = akiko.cdrom_lba_cur - akiko.cdrom_lba_start;
623         memset( &buf[4], 0xff, 8 );
624
625         buf[12] = (curmsf >> 16) & 0xff;
626         buf[13] = (curmsf >> 8) & 0xff;
627         buf[14] = curmsf & 0xff;
628         buf[15] = 0x01; /* mode1 */
629
630         if ( !cdrom_read_data( akiko.cdrom, akiko.cdrom_lba_cur, &buf[16], CD_TRACK_RAW_DONTCARE ) )
631         {
632            logerror( "AKIKO: Read error trying to read sector %08x!\n", akiko.cdrom_lba_cur );
633            return;
634         }
635
636         if ( subsize )
637         {
638            if ( !cdrom_read_subcode( akiko.cdrom, akiko.cdrom_lba_cur, &buf[16+datasize] ) )
639            {
640               logerror( "AKIKO: Read error trying to read subcode for sector %08x!\n", akiko.cdrom_lba_cur );
641               return;
642            }
643         }
644      }
645      else
646      {
647         if ( !cdrom_read_data( akiko.cdrom, akiko.cdrom_lba_cur, buf, CD_TRACK_RAW_DONTCARE) )
648         {
649            logerror( "AKIKO: Read error trying to read sector %08x!\n", akiko.cdrom_lba_cur );
650            return;
651         }
652
653         if ( subsize )
654         {
655            if ( !cdrom_read_subcode( akiko.cdrom, akiko.cdrom_lba_cur, &buf[datasize] ) )
656            {
657               logerror( "AKIKO: Read error trying to read subcode for sector %08x!\n", akiko.cdrom_lba_cur );
658               return;
659            }
660         }
661      }
662
663#if LOG_AKIKO_CD
664      logerror( "DMA: sector %d - address %08x\n", akiko.cdrom_lba_cur, akiko.cdrom_address[0] + (index*4096) );
665#endif
666
667      for( i = 0; i < 2352; i += 2 )
668      {
669         UINT16   data;
670
671         data = buf[i];
672         data <<= 8;
673         data |= buf[i+1];
674
675         amiga_chip_ram_w( akiko.cdrom_address[0] + (index*4096) + i, data );
676      }
677
678      akiko.cdrom_readmask |= ( 1 << index );
679      akiko.cdrom_readreqmask &= ~( 1 << index );
680      akiko.cdrom_lba_cur++;
681   }
682
683   if ( akiko.cdrom_readreqmask == 0 )
684      akiko_set_cd_status(0x04000000);
685   else
686      mame_timer_adjust( akiko.dma_timer, MAME_TIME_IN_USEC( CD_SECTOR_TIME / akiko.cdrom_speed ), 0, time_zero );
687}
688
689static void akiko_start_dma( void )
690{
691   if ( akiko.cdrom_readreqmask == 0 )
692      return;
693
694   if ( akiko.cdrom_lba_start > akiko.cdrom_lba_end )
695      return;
696
697   if ( akiko.cdrom_speed == 0 )
698      return;
699
700   akiko.cdrom_lba_cur = akiko.cdrom_lba_start;
701
702   mame_timer_adjust( akiko.dma_timer, MAME_TIME_IN_USEC( CD_SECTOR_TIME / akiko.cdrom_speed ), 0, time_zero );
703}
704
705static void akiko_setup_response( int len, UINT8 *r1 )
706{
707   int      resp_addr = akiko.cdrom_address[1];
708   UINT8   resp_csum = 0xff;
709   UINT8   resp_buffer[32];
710   int      i;
711
712   memset( resp_buffer, 0, sizeof( resp_buffer ) );
713
714   for( i = 0; i < len; i++ )
715   {
716      resp_buffer[i] = r1[i];
717      resp_csum -= resp_buffer[i];
718   }
719
720   resp_buffer[len++] = resp_csum;
721
722   for( i = 0; i < len; i++ )
723   {
724      program_write_byte( resp_addr + ((akiko.cdrom_cmd_resp + i) & 0xff), resp_buffer[i] );
725   }
726
727   akiko.cdrom_cmd_resp = (akiko.cdrom_cmd_resp+len) & 0xff;
728
729   akiko_set_cd_status( 0x10000000 ); /* new data available */
730}
731
732static TIMER_CALLBACK( akiko_cd_delayed_cmd )
733{
734   UINT8   resp[32];
735   UINT8   cddastatus;
736
737   if ( akiko.cdrom_status[0] & 0x10000000 )
738      return;
739
740   cddastatus = akiko_cdda_getstatus(NULL);
741
742   if ( cddastatus == 0x11 || cddastatus == 0x12 )
743      return;
744
745   memset( resp, 0, sizeof( resp ) );
746   resp[0] = param;
747
748   param &= 0x0f;
749
750   if ( param == 0x05 )
751   {
752#if LOG_AKIKO_CD
753      logerror( "AKIKO: Completing Command %d\n", param );
754#endif
755
756      resp[0] = 0x06;
757
758      if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
759      {
760         resp[1] = 0x80;
761         akiko_setup_response( 15, resp );
762      }
763      else
764      {
765         resp[1] = 0x00;
766         memcpy( &resp[2], &akiko.cdrom_toc[13*akiko.cdrom_track_index], 13 );
767
768         akiko.cdrom_track_index = ( akiko.cdrom_track_index + 1 ) % akiko.cdrom_numtracks;
769
770         akiko_setup_response( 15, resp );
771      }
772   }
773}
774
775static void akiko_update_cdrom( void )
776{
777   UINT8   resp[32], cmdbuf[32];
778
779   if ( akiko.cdrom_status[0] & 0x10000000 )
780      return;
781
782   while ( akiko.cdrom_cmd_start != akiko.cdrom_cmd_end )
783   {
784      UINT32   cmd_addr = akiko.cdrom_address[1] + 0x200 + akiko.cdrom_cmd_start;
785      int      cmd = program_read_byte( cmd_addr );
786
787      memset( resp, 0, sizeof( resp ) );
788      resp[0] = cmd;
789
790      cmd &= 0x0f;
791
792#if LOG_AKIKO_CD
793      logerror( "CDROM command: %02X\n", cmd );
794#endif
795
796      if ( cmd == 0x02 ) /* pause audio */
797      {
798         resp[1] = 0x00;
799
800         if ( akiko_cdda_getstatus(NULL) == 0x11 )
801            resp[1] = 0x08;
802
803         akiko_cdda_pause( 1 );
804
805         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
806
807         akiko_setup_response( 2, resp );
808      }
809      else if ( cmd == 0x03 ) /* unpause audio (and check audiocd playing status) */
810      {
811         resp[1] = 0x00;
812
813         if ( akiko_cdda_getstatus(NULL) == 0x11 )
814            resp[1] = 0x08;
815
816         akiko_cdda_pause( 0 );
817
818         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
819
820         akiko_setup_response( 2, resp );
821      }
822      else if ( cmd == 0x04 ) /* seek/read/play cd multi command */
823      {
824         int   i;
825         UINT32   startpos, endpos;
826
827         for( i = 0; i < 13; i++ )
828         {
829            cmdbuf[i] = program_read_byte( cmd_addr );
830            cmd_addr &= 0xffffff00;
831            cmd_addr += ( akiko.cdrom_cmd_start + i + 1 ) & 0xff;
832         }
833
834         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+13) & 0xff;
835
836         if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
837         {
838            resp[1] = 0x80;
839            akiko_setup_response( 2, resp );
840         }
841         else
842         {
843            startpos = lba_from_triplet( &cmdbuf[1] );
844            endpos = lba_from_triplet( &cmdbuf[4] );
845
846            akiko_cdda_stop();
847
848            resp[1] = 0x00;
849
850            if ( cmdbuf[7] == 0x80 )
851            {
852#if LOG_AKIKO_CD
853               logerror( "AKIKO CD: PC:%06x Data read - start lba: %08x - end lba: %08x\n", safe_activecpu_get_pc(), startpos, endpos );
854#endif
855               akiko.cdrom_speed = (cmdbuf[8] & 0x40) ? 2 : 1;
856               akiko.cdrom_lba_start = startpos;
857               akiko.cdrom_lba_end = endpos;
858
859               resp[1] = 0x02;
860            }
861            else if ( cmdbuf[10] & 0x04 )
862            {
863               logerror( "AKIKO CD: Audio Play - start lba: %08x - end lba: %08x\n", startpos, endpos );
864               akiko_cdda_play( startpos, endpos - startpos );
865               resp[1] = 0x08;
866            }
867            else
868            {
869#if LOG_AKIKO_CD
870               logerror( "AKIKO CD: Seek - start lba: %08x - end lba: %08x\n", startpos, endpos );
871#endif
872               akiko.cdrom_track_index = 0;
873
874               for( i = 0; i < cdrom_get_last_track(akiko.cdrom); i++ )
875               {
876                  if ( startpos <= cdrom_get_track_start( akiko.cdrom, i ) )
877                  {
878                     /* reset to 0 */
879                     akiko.cdrom_track_index = i + 2;
880                     akiko.cdrom_track_index %= akiko.cdrom_numtracks;
881                     break;
882                  }
883               }
884            }
885
886            akiko_setup_response( 2, resp );
887         }
888      }
889      else if ( cmd == 0x05 ) /* read toc */
890      {
891         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+3) & 0xff;
892
893         mame_timer_set( MAME_TIME_IN_MSEC(1), resp[0], akiko_cd_delayed_cmd );
894
895         break;
896      }
897      else if ( cmd == 0x06 ) /* read subq */
898      {
899         UINT32   lba;
900
901         resp[1] = 0x00;
902
903         (void)akiko_cdda_getstatus( &lba );
904
905         if ( lba > 0 )
906         {
907            UINT32   disk_pos;
908            UINT32   track_pos;
909            UINT32   track;
910            int      addrctrl;
911
912            track = cdrom_get_track(akiko.cdrom, lba);
913            addrctrl = cdrom_get_adr_control(akiko.cdrom, track);
914
915            resp[2] = 0x00;
916            resp[3] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
917            resp[4] = dec_2_bcd(track+1);
918            resp[5] = 0; /* index */
919
920            disk_pos = lba_to_msf(lba);
921            track_pos = lba_to_msf(lba - cdrom_get_track_start(akiko.cdrom, track));
922
923            /* track position */
924            resp[6] = (track_pos >> 16) & 0xff;
925            resp[7] = (track_pos >> 8) & 0xff;
926            resp[8] = track_pos & 0xff;
927
928            /* disk position */
929            resp[9] = (disk_pos >> 24) & 0xff;
930            resp[10] = (disk_pos >> 16) & 0xff;
931            resp[11] = (disk_pos >> 8) & 0xff;
932            resp[12] = disk_pos & 0xff;
933         }
934         else
935         {
936            resp[1] = 0x80;
937         }
938
939         akiko_setup_response( 15, resp );
940      }
941      else if ( cmd == 0x07 )   /* check door status */
942      {
943         resp[1] = 0x01;
944
945         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
946
947         if ( akiko.cdrom == NULL || akiko.cdrom_numtracks == 0 )
948            resp[1] = 0x80;
949
950         akiko_setup_response( 20, resp );
951         break;
952      }
953      else
954      {
955         break;
956      }
957   }
958}
959
960READ32_HANDLER(amiga_akiko32_r)
961{
962   UINT32      retval;
963
964#if LOG_AKIKO
965   if ( offset < (0x30/4) )
966   {
967      logerror( "Reading AKIKO reg %0x [%s] at PC=%06x\n", offset, get_akiko_reg_name(offset), activecpu_get_pc() );
968   }
969#endif
970
971   switch( offset )
972   {
973      case 0x00/4:   /* ID */
974         if ( akiko.cdrom != NULL ) cdda_set_cdrom(0, akiko.cdrom);
975         return 0x0000cafe;
976
977      case 0x04/4:   /* CDROM STATUS 1 */
978         return akiko.cdrom_status[0];
979
980      case 0x08/4:   /* CDROM STATUS 2 */
981         return akiko.cdrom_status[1];
982
983      case 0x10/4:   /* CDROM ADDRESS 1 */
984         return akiko.cdrom_address[0];
985
986      case 0x14/4:   /* CDROM ADDRESS 2 */
987         return akiko.cdrom_address[1];
988
989      case 0x18/4:   /* CDROM COMMAND 1 */
990         akiko_update_cdrom();
991         retval = akiko.cdrom_cmd_start;
992         retval <<= 8;
993         retval |= akiko.cdrom_cmd_resp;
994         retval <<= 8;
995         return retval;
996
997      case 0x1C/4:   /* CDROM COMMAND 2 */
998         akiko_update_cdrom();
999         retval = akiko.cdrom_cmd_end;
1000         retval <<= 16;
1001         return retval;
1002
1003      case 0x20/4:   /* CDROM DMA SECTOR READ MASK */
1004         retval = akiko.cdrom_readmask << 16;
1005         return retval;
1006
1007      case 0x24/4:   /* CDROM DMA ENABLE? */
1008         retval = akiko.cdrom_dmacontrol;
1009         return retval;
1010
1011      case 0x30/4:   /* NVRAM */
1012         return akiko_nvram_read();
1013
1014      case 0x38/4:   /* C2P */
1015         return akiko_c2p_read();
1016
1017      default:
1018         break;
1019   }
1020
1021   return 0;
1022}
1023
1024WRITE32_HANDLER(amiga_akiko32_w)
1025{
1026#if LOG_AKIKO
1027   if ( offset < (0x30/4) )
1028   {
1029      logerror( "Writing AKIKO reg %0x [%s] with %08x at PC=%06x\n", offset, get_akiko_reg_name(offset), data, activecpu_get_pc() );
1030   }
1031#endif
1032
1033   switch( offset )
1034   {
1035      case 0x04/4:   /* CDROM STATUS 1 */
1036         akiko.cdrom_status[0] = data;
1037         break;
1038
1039      case 0x08/4:   /* CDROM STATUS 2 */
1040         akiko.cdrom_status[1] = data;
1041         akiko.cdrom_status[0] &= data;
1042         break;
1043
1044      case 0x10/4:   /* CDROM ADDRESS 1 */
1045         akiko.cdrom_address[0] = data;
1046         break;
1047
1048      case 0x14/4:   /* CDROM ADDRESS 2 */
1049         akiko.cdrom_address[1] = data;
1050         break;
1051
1052      case 0x18/4:   /* CDROM COMMAND 1 */
1053         if ( ( mem_mask & 0x00ff0000 ) == 0 )
1054            akiko.cdrom_cmd_start = ( data >> 16 ) & 0xff;
1055
1056         if ( ( mem_mask & 0x0000ff00 ) == 0 )
1057            akiko.cdrom_cmd_resp = ( data >> 8 ) & 0xff;
1058
1059         akiko_update_cdrom();
1060         break;
1061
1062      case 0x1C/4:   /* CDROM COMMAND 2 */
1063         if ( ( mem_mask & 0x00ff0000 ) == 0 )
1064            akiko.cdrom_cmd_end = ( data >> 16 ) & 0xff;
1065
1066         akiko_update_cdrom();
1067         break;
1068
1069      case 0x20/4:   /* CDROM DMA SECTOR READ REQUEST WRITE */
1070#if LOG_AKIKO_CD
1071         logerror( "Read Req mask W: data %08x - mem mask %08x\n", data, mem_mask );
1072#endif
1073         if ( ( mem_mask & 0xffff0000 ) == 0 )
1074         {
1075            akiko.cdrom_readreqmask = (data >> 16);
1076            akiko.cdrom_readmask = 0;
1077         }
1078         break;
1079
1080      case 0x24/4:   /* CDROM DMA ENABLE? */
1081#if LOG_AKIKO_CD
1082         logerror( "DMA enable W: data %08x - mem mask %08x\n", data, mem_mask );
1083#endif
1084         if ( ( akiko.cdrom_dmacontrol ^ data ) & 0x04000000 )
1085         {
1086            if ( data & 0x04000000 )
1087               akiko_start_dma();
1088         }
1089         akiko.cdrom_dmacontrol = data;
1090         break;
1091
1092      case 0x30/4:
1093         akiko_nvram_write(data);
1094         break;
1095
1096      case 0x38/4:
1097         akiko_c2p_write(data);
1098         break;
1099
1100      default:
1101         break;
1102   }
1103}
src/mame/machine/bublbobl.c
r936r937
2929   cpunum_set_input_line(1, INPUT_LINE_RESET, (data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
3030
3131   /* bit 5 resets mcu */
32   if (Machine->drv->cpu[3].cpu_type)   // only if we have a MCU
32   if (Machine->drv->cpu[3].cpu_type != CPU_DUMMY)   // only if we have a MCU
3333      cpunum_set_input_line(3, INPUT_LINE_RESET, (data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
3434
3535   /* bit 6 enables display */
src/mame/machine/vsnes.c
r936r937
353353         int x = readinputport( 4 );
354354         int y = readinputport( 5 );
355355         UINT32 pix, color_base;
356         pen_t *pens = Machine->pens;
356         const pen_t *pens = Machine->pens;
357357
358358         /* get the pixel at the gun position */
359359         pix = ppu2c0x_get_pixel( 0, x, y );
src/mame/machine/amiga.c
r936r937
178178static TIMER_CALLBACK( amiga_irq_proc );
179179static TIMER_CALLBACK( amiga_blitter_proc );
180180
181
182
183181/*************************************
184182 *
185183 *  Chipmem 16/32 bit access
r936r937
310308   autoconfig_reset();
311309
312310   /* set the overlay bit */
313   amiga_cia_w(0x1001/2, 1, 0);
311   if ( IS_AGA(amiga_intf) )
312   {
313      program_write_byte( 0xbfa001, 1 );
314   }
315   else
316   {
317      amiga_cia_w(0x1001/2, 1, 0);
318   }
314319
315320   if (activecpu_get_pc() < 0x80000)
316321      memory_set_opbase(0);
r936r937
328333   autoconfig_reset();
329334
330335   /* set the overlay bit */
331   amiga_cia_w(0x1001/2, 1, 0);
336   if ( IS_AGA(amiga_intf) )
337   {
338      program_write_byte( 0xbfa001, 1 );
339   }
340   else
341   {
342      amiga_cia_w(0x1001/2, 1, 0);
343   }
332344
333345   /* call the system-specific callback */
334346   if (amiga_intf->reset_callback)
r936r937
974986   /* is there another blitting in progress? */
975987   if (CUSTOM_REG(REG_DMACON) & 0x4000)
976988   {
977      logerror("This program is playing tricks with the blitter\n" );
989      logerror("PC: %08x - This program is playing tricks with the blitter\n", safe_activecpu_get_pc() );
978990      return;
979991   }
980992
r936r937
10121024      blittime = BLITTER_NASTY_DELAY;
10131025   }
10141026
1027   /* AGA has twice the bus bandwidth, so blits take half the time */
1028   if ( IS_AGA(amiga_intf) )
1029      blittime /= 2;
1030
10151031   /* signal blitter busy */
10161032    CUSTOM_REG(REG_DMACON) |= 0x4000;
10171033
r936r937
11301146   CUSTOM_REG(REG_DDFSTOP) = 0xd8;
11311147   CUSTOM_REG(REG_INTENA) = 0x0000;
11321148   CUSTOM_REG(REG_VPOSR) = vidmode;
1149   CUSTOM_REG(REG_SERDATR) = 0x3000;
11331150
11341151   switch (amiga_intf->chip_ram_mask)
11351152   {
11361153      case ANGUS_CHIP_RAM_MASK:
11371154      case FAT_ANGUS_CHIP_RAM_MASK:
1138         CUSTOM_REG(REG_DENISEID) = 0xFFFF;
1155         CUSTOM_REG(REG_DENISEID) = 0x00FF;
11391156         break;
11401157
11411158      case ECS_CHIP_RAM_MASK:
11421159         CUSTOM_REG(REG_VPOSR) |= 0x2000;
1143         CUSTOM_REG(REG_DENISEID) = 0xFFFC;
1160         CUSTOM_REG(REG_DENISEID) = 0x00FC;
11441161         if (IS_AGA(amiga_intf))
11451162         {
11461163            CUSTOM_REG(REG_VPOSR) |= 0x0300;
1147            CUSTOM_REG(REG_DENISEID) = 0xFFF8;
1164            CUSTOM_REG(REG_DENISEID) = 0x00F8;
11481165         }
11491166         break;
11501167   }
r936r937
11641181
11651182   switch (offset & 0xff)
11661183   {
1184      case REG_BLTDDAT:
1185         return CUSTOM_REG(REG_BLTDDAT);
1186
11671187      case REG_DMACONR:
11681188         return CUSTOM_REG(REG_DMACON);
11691189
src/mame/machine/wd33c93.c
r936r937
870870{
871871   return wd33c93_get_xfer_count();
872872}
873/*
874 * wd33c93.c
875 *
876 * WD/AMD 33c93 SCSI controller, as seen in
877 * early PCs, some MSX add-ons, NEC PC-88, and SGI
878 * Indigo, Indigo2, and Indy systems.
879 *
880 * References:
881 * WD 33c93 manual
882 * NetBSD 33c93 driver
883 *
884 */
885
886#include "driver.h"
887#include "state.h"
888#include "wd33c93.h"
889
890#define VERBOSE 0
891
892typedef struct
893{
894   void *data;      // device's "this" pointer
895   pSCSIDispatch handler;   // device's handler routine
896} SCSIDev;
897
898static SCSIDev devices[8];   // SCSI IDs 0-7
899static struct WD33C93interface *intf;
900
901/* wd register names */
902#define WD_OWN_ID               0x00
903#define WD_CONTROL               0x01
904#define WD_TIMEOUT_PERIOD         0x02
905#define WD_CDB_1               0x03
906#define WD_CDB_2               0x04
907#define WD_CDB_3               0x05
908#define WD_CDB_4               0x06
909#define WD_CDB_5               0x07
910#define WD_CDB_6               0x08
911#define WD_CDB_7               0x09
912#define WD_CDB_8               0x0a
913#define WD_CDB_9               0x0b
914#define WD_CDB_10               0x0c
915#define WD_CDB_11               0x0d
916#define WD_CDB_12               0x0e
917#define WD_TARGET_LUN            0x0f
918#define WD_COMMAND_PHASE         0x10
919#define WD_SYNCHRONOUS_TRANSFER      0x11
920#define WD_TRANSFER_COUNT_MSB      0x12
921#define WD_TRANSFER_COUNT         0x13
922#define WD_TRANSFER_COUNT_LSB      0x14
923#define WD_DESTINATION_ID         0x15
924#define WD_SOURCE_ID            0x16
925#define WD_SCSI_STATUS            0x17
926#define WD_COMMAND               0x18
927#define WD_DATA                  0x19
928#define WD_QUEUE_TAG            0x1a
929#define WD_AUXILIARY_STATUS         0x1f
930
931/* WD commands */
932#define WD_CMD_RESET            0x00
933#define WD_CMD_ABORT            0x01
934#define WD_CMD_ASSERT_ATN         0x02
935#define WD_CMD_NEGATE_ACK         0x03
936#define WD_CMD_DISCONNECT         0x04
937#define WD_CMD_RESELECT            0x05
938#define WD_CMD_SEL_ATN            0x06
939#define WD_CMD_SEL               0x07
940#define WD_CMD_SEL_ATN_XFER         0x08
941#define WD_CMD_SEL_XFER            0x09
942#define WD_CMD_RESEL_RECEIVE      0x0a
943#define WD_CMD_RESEL_SEND         0x0b
944#define WD_CMD_WAIT_SEL_RECEIVE      0x0c
945#define WD_CMD_SSCC               0x0d
946#define WD_CMD_SND_DISC            0x0e
947#define WD_CMD_SET_IDI            0x0f
948#define WD_CMD_RCV_CMD            0x10
949#define WD_CMD_RCV_DATA            0x11
950#define WD_CMD_RCV_MSG_OUT         0x12
951#define WD_CMD_RCV               0x13
952#define WD_CMD_SND_STATUS         0x14
953#define WD_CMD_SND_DATA            0x15
954#define WD_CMD_SND_MSG_IN         0x16
955#define WD_CMD_SND               0x17
956#define WD_CMD_TRANS_ADDR         0x18
957#define WD_CMD_XFER_PAD            0x19
958#define WD_CMD_TRANS_INFO         0x20
959#define WD_CMD_TRANSFER_PAD         0x21
960#define WD_CMD_SBT_MODE            0x80
961
962/* ASR register */
963#define ASR_INT                  0x80
964#define ASR_LCI                  0x40
965#define ASR_BSY                  0x20
966#define ASR_CIP                  0x10
967#define ASR_PE                  0x02
968#define ASR_DBR                  0x01
969
970/* SCSI Bus Phases */
971#define PHS_DATA_OUT            0x00
972#define PHS_DATA_IN               0x01
973#define PHS_COMMAND               0x02
974#define PHS_STATUS               0x03
975#define PHS_MESS_OUT            0x06
976#define PHS_MESS_IN               0x07
977
978/* Command Status Register definitions */
979
980  /* reset state interrupts */
981#define CSR_RESET               0x00
982#define CSR_RESET_AF            0x01
983
984  /* successful completion interrupts */
985#define CSR_RESELECT            0x10
986#define CSR_SELECT               0x11
987#define CSR_SEL_XFER_DONE         0x16
988#define CSR_XFER_DONE            0x18
989
990  /* paused or aborted interrupts */
991#define CSR_MSGIN               0x20
992#define CSR_SDP                  0x21
993#define CSR_SEL_ABORT            0x22
994#define CSR_RESEL_ABORT            0x25
995#define CSR_RESEL_ABORT_AM         0x27
996#define CSR_ABORT               0x28
997
998  /* terminated interrupts */
999#define CSR_INVALID               0x40
1000#define CSR_UNEXP_DISC            0x41
1001#define CSR_TIMEOUT               0x42
1002#define CSR_PARITY               0x43
1003#define CSR_PARITY_ATN            0x44
1004#define CSR_BAD_STATUS            0x45
1005#define CSR_UNEXP               0x48
1006
1007  /* service required interrupts */
1008#define CSR_RESEL               0x80
1009#define CSR_RESEL_AM            0x81
1010#define CSR_DISC               0x85
1011#define CSR_SRV_REQ               0x88
1012
1013   /* Own ID/CDB Size register */
1014#define OWNID_EAF               0x08
1015#define OWNID_EHP               0x10
1016#define OWNID_RAF               0x20
1017#define OWNID_FS_8               0x00
1018#define OWNID_FS_12               0x40
1019#define OWNID_FS_16               0x80
1020
1021   /* Control register */
1022#define CTRL_HSP               0x01
1023#define CTRL_HA                  0x02
1024#define CTRL_IDI               0x04
1025#define CTRL_EDI               0x08
1026#define CTRL_HHP               0x10
1027#define CTRL_POLLED               0x00
1028#define CTRL_BURST               0x20
1029#define CTRL_BUS               0x40
1030#define CTRL_DMA               0x80
1031
1032   /* Synchronous Transfer Register */
1033#define STR_FSS                  0x80
1034
1035   /* Destination ID register */
1036#define DSTID_DPD               0x40
1037#define DATA_OUT_DIR            0
1038#define DATA_IN_DIR               1
1039#define DSTID_SCC               0x80
1040
1041   /* Source ID register */
1042#define SRCID_MASK               0x07
1043#define SRCID_SIV               0x08
1044#define SRCID_DSP               0x20
1045#define SRCID_ES               0x40
1046#define SRCID_ER               0x80
1047
1048/* command handler definition */
1049typedef void (*cmd_handler)(void);
1050
1051#define TEMP_INPUT_LEN   65536
1052#define FIFO_SIZE      12
1053
1054/* internal controller data definition */
1055typedef struct
1056{
1057   UINT8      sasr;
1058   UINT8      regs[WD_AUXILIARY_STATUS+1];
1059   UINT8      fifo[FIFO_SIZE];
1060   int         fifo_pos;
1061   UINT8      *temp_input;
1062   int         temp_input_pos;
1063   UINT8      busphase;
1064   UINT8      identify;
1065   int         read_pending;
1066   mame_timer *cmd_timer;
1067} _wd33c93_data;
1068
1069/* local instance of controller data */
1070static _wd33c93_data scsi_data;
1071
1072
1073/* convernience functions */
1074static UINT8 wd33c93_getunit( void )
1075{
1076   /* return the destination unit id */
1077   return scsi_data.regs[WD_DESTINATION_ID] & SRCID_MASK;
1078}
1079
1080static void wd33c93_set_xfer_count( int count )
1081{
1082   /* set the count */
1083   scsi_data.regs[ WD_TRANSFER_COUNT_LSB ] = count & 0xff;
1084   scsi_data.regs[ WD_TRANSFER_COUNT ] = ( count >> 8 ) & 0xff;
1085   scsi_data.regs[ WD_TRANSFER_COUNT_MSB ] = ( count >> 16 ) & 0xff;
1086}
1087
1088static int wd33c93_get_xfer_count( void )
1089{
1090   /* get the count */
1091   int      count = scsi_data.regs[ WD_TRANSFER_COUNT_MSB ];
1092
1093   count <<= 8;
1094   count |= scsi_data.regs[ WD_TRANSFER_COUNT ];
1095   count <<= 8;
1096   count |= scsi_data.regs[ WD_TRANSFER_COUNT_LSB ];
1097
1098   return count;
1099}
1100
1101static void wd33c93_read_data(int bytes, UINT8 *pData)
1102{
1103   UINT8   unit = wd33c93_getunit();
1104
1105   if ( devices[unit].handler )
1106   {
1107      devices[unit].handler(SCSIOP_READ_DATA, devices[unit].data, bytes, pData);
1108   }
1109   else
1110   {
1111      logerror("wd33c93: request for unknown device SCSI ID %d\n", unit);
1112   }
1113}
1114
1115static void wd33c93_complete_immediate( int status )
1116{
1117   /* reset our timer */
1118   mame_timer_reset( scsi_data.cmd_timer, time_never );
1119
1120   /* set the new status */
1121   scsi_data.regs[WD_SCSI_STATUS] = status & 0xff;
1122
1123   /* set interrupt pending */
1124   scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT;
1125
1126   /* check for error conditions */
1127   if ( wd33c93_get_xfer_count() > 0 )
1128   {
1129      /* set data buffer ready */
1130      scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_DBR;
1131   }
1132   else
1133   {
1134      /* clear data buffer ready */
1135      scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR;
1136   }
1137
1138   /* clear command in progress and bus busy */
1139   scsi_data.regs[WD_AUXILIARY_STATUS] &= ~(ASR_CIP | ASR_BSY);
1140
1141   /* if we have a callback, call it */
1142   if (intf && intf->irq_callback)
1143   {
1144      intf->irq_callback(1);
1145   }
1146}
1147
1148static TIMER_CALLBACK(wd33c93_complete_cb)
1149{
1150   wd33c93_complete_immediate( param );
1151}
1152
1153static TIMER_CALLBACK(wd33c93_service_request)
1154{
1155   /* issue a message out request */
1156   wd33c93_complete_immediate(CSR_SRV_REQ | scsi_data.busphase);
1157}
1158
1159static TIMER_CALLBACK(wd33c93_deassert_cip)
1160{
1161   scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_CIP;
1162}
1163
1164static void wd33c93_complete_cmd( UINT8 status )
1165{
1166   /* fire off a timer to complete the command */
1167   mame_timer_adjust( scsi_data.cmd_timer, MAME_TIME_IN_USEC(1), status, time_zero );
1168}
1169
1170/* command handlers */
1171static void wd33c93_invalid_cmd( void )
1172{
1173   logerror( "Unknown/Unimplemented SCSI controller command: %02x (PC=%x)\n", scsi_data.regs[WD_COMMAND], activecpu_get_pc() );
1174
1175   /* complete the command */
1176   wd33c93_complete_cmd( CSR_INVALID );
1177}
1178
1179static void wd33c93_reset_cmd( void )
1180{
1181   int      advanced = 0;
1182
1183   /* see if it wants us to reset with advanced features */
1184   if ( scsi_data.regs[WD_OWN_ID] & OWNID_EAF )
1185   {
1186      advanced = 1;
1187   }
1188
1189   /* clear out all registers */
1190   memset( scsi_data.regs, 0, sizeof( scsi_data.regs ) );
1191
1192   /* complete the command */
1193   wd33c93_complete_cmd(advanced ? CSR_RESET_AF : CSR_RESET);
1194}
1195
1196static void wd33c93_abort_cmd( void )
1197{
1198   /* complete the command */
1199   wd33c93_complete_cmd(CSR_ABORT);
1200}
1201
1202static void wd33c93_disconnect_cmd( void )
1203{
1204   /* complete the command */
1205   scsi_data.regs[WD_AUXILIARY_STATUS] &= ~(ASR_CIP | ASR_BSY);
1206}
1207
1208static void wd33c93_select_cmd( void )
1209{
1210   UINT8   unit = wd33c93_getunit();
1211   UINT8   newstatus;
1212
1213   /* see if we can select that device */
1214   if ( devices[unit].handler )
1215   {
1216      /* device is available - signal selection done */
1217      newstatus = CSR_SELECT;
1218
1219      /* determine the next bus phase depending on the command */
1220      if ( (scsi_data.regs[WD_COMMAND] & 0x7f) == WD_CMD_SEL_ATN )
1221      {
1222         /* /ATN asserted during select: Move to Message Out Phase to read identify */
1223         scsi_data.busphase = PHS_MESS_OUT;
1224      }
1225      else
1226      {
1227         /* No /ATN asserted: Move to Command Phase */
1228         scsi_data.busphase = PHS_COMMAND;
1229      }
1230
1231      /* queue up a service request out in the future */
1232      mame_timer_set( MAME_TIME_IN_USEC(50), 0, wd33c93_service_request );
1233   }
1234   else
1235   {
1236      /* device is not available */
1237      newstatus = CSR_TIMEOUT;
1238   }
1239
1240   /* complete the command */
1241   wd33c93_complete_cmd(newstatus);
1242}
1243
1244static void wd33c93_selectxfer_cmd( void )
1245{
1246   UINT8   unit = wd33c93_getunit();
1247   UINT8   newstatus;
1248
1249   /* see if we can select that device */
1250   if ( devices[unit].handler )
1251   {
1252      if ( scsi_data.regs[WD_COMMAND_PHASE] < 0x45 )
1253      {
1254         /* device is available */
1255         int xfercount;
1256
1257         /* do the request */
1258         xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.regs[WD_CDB_1]);
1259
1260         /* set transfer count */
1261         if ( wd33c93_get_xfer_count() > TEMP_INPUT_LEN )
1262         {
1263            logerror( "WD33C93: Transfer count too big. Please increase TEMP_INPUT_LEN (size=%d)\n", wd33c93_get_xfer_count() );
1264            wd33c93_set_xfer_count( TEMP_INPUT_LEN );
1265         }
1266
1267         scsi_data.read_pending = 1;
1268      }
1269
1270      if ( scsi_data.read_pending )
1271      {
1272         int      len = TEMP_INPUT_LEN;
1273
1274         if ( wd33c93_get_xfer_count() < len ) len = wd33c93_get_xfer_count();
1275
1276         memset( &scsi_data.temp_input[0], 0, TEMP_INPUT_LEN );
1277         wd33c93_read_data( len, &scsi_data.temp_input[0] );
1278         scsi_data.temp_input_pos = 0;
1279         scsi_data.read_pending = 0;
1280      }
1281
1282      scsi_data.regs[WD_TARGET_LUN] = 0;
1283      scsi_data.regs[WD_CONTROL] |= CTRL_EDI;
1284      scsi_data.regs[WD_COMMAND_PHASE] = 0x60;
1285
1286      /* signal transfer ready */
1287      newstatus = CSR_SEL_XFER_DONE;
1288
1289      /* if allowed disconnect, queue a service request */
1290      if ( scsi_data.identify & 0x40 )
1291      {
1292         /* queue disconnect message in */
1293         scsi_data.busphase = PHS_MESS_IN;
1294
1295         /* queue up a service request out in the future */
1296         mame_timer_set( MAME_TIME_IN_MSEC(50), 0, wd33c93_service_request );
1297      }
1298   }
1299   else
1300   {
1301      /* device is not available */
1302      newstatus = CSR_TIMEOUT;
1303
1304      wd33c93_set_xfer_count( 0 );
1305   }
1306
1307   /* complete the command */
1308   wd33c93_complete_cmd(newstatus);
1309}
1310
1311static void wd33c93_negate_ack( void )
1312{
1313   logerror( "WD33C93: ACK Negated\n" );
1314
1315   /* complete the command */
1316   scsi_data.regs[WD_AUXILIARY_STATUS] &= ~(ASR_CIP | ASR_BSY);
1317}
1318
1319static void wd33c93_xferinfo_cmd( void )
1320{
1321   /* make the buffer available right away */
1322   scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_DBR;
1323   scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_CIP;
1324
1325   /* the command will be completed once the data is transferred */
1326   mame_timer_set( MAME_TIME_IN_MSEC(1), 0, wd33c93_deassert_cip );
1327}
1328
1329/* Command handlers */
1330static cmd_handler wd33c93_cmds[0x22] =
1331{
1332   &wd33c93_reset_cmd,      /* 0x00 - WD_CMD_RESET */
1333   &wd33c93_abort_cmd,      /* 0x01 - WD_CMD_ABORT */
1334   &wd33c93_invalid_cmd,   /* 0x02 - WD_CMD_ASSERT_ATN (uninmplemented) */
1335   &wd33c93_negate_ack,   /* 0x03 - WD_CMD_NEGATE_ACK */
1336   &wd33c93_disconnect_cmd,/* 0x04 - WD_CMD_DISCONNECT */
1337   &wd33c93_invalid_cmd,   /* 0x05 - WD_CMD_RESELECT (uninmplemented) */
1338   &wd33c93_select_cmd,   /* 0x06 - WD_CMD_SEL_ATN */
1339   &wd33c93_select_cmd,   /* 0x07 - WD_CMD_SEL */
1340   &wd33c93_selectxfer_cmd,/* 0x08 - WD_CMD_SEL_ATN_XFER */
1341   &wd33c93_selectxfer_cmd,/* 0x09 - WD_CMD_SEL_XFER */
1342   &wd33c93_invalid_cmd,   /* 0x0a - WD_CMD_RESEL_RECEIVE (uninmplemented) */
1343   &wd33c93_invalid_cmd,   /* 0x0b - WD_CMD_RESEL_SEND (uninmplemented) */
1344   &wd33c93_invalid_cmd,   /* 0x0c - WD_CMD_WAIT_SEL_RECEIVE (uninmplemented) */
1345   &wd33c93_invalid_cmd,   /* 0x0d - WD_CMD_SSCC (uninmplemented) */
1346   &wd33c93_invalid_cmd,   /* 0x0e - WD_CMD_SND_DISC (uninmplemented) */
1347   &wd33c93_invalid_cmd,   /* 0x0f - WD_CMD_SET_IDI (uninmplemented) */
1348   &wd33c93_invalid_cmd,   /* 0x10 - WD_CMD_RCV_CMD (uninmplemented) */
1349   &wd33c93_invalid_cmd,   /* 0x11 - WD_CMD_RCV_DATA (uninmplemented) */
1350   &wd33c93_invalid_cmd,   /* 0x12 - WD_CMD_RCV_MSG_OUT (uninmplemented) */
1351   &wd33c93_invalid_cmd,   /* 0x13 - WD_CMD_RCV (uninmplemented) */
1352   &wd33c93_invalid_cmd,   /* 0x14 - WD_CMD_SND_STATUS (uninmplemented) */
1353   &wd33c93_invalid_cmd,   /* 0x15 - WD_CMD_SND_DATA (uninmplemented) */
1354   &wd33c93_invalid_cmd,   /* 0x16 - WD_CMD_SND_MSG_IN (uninmplemented) */
1355   &wd33c93_invalid_cmd,   /* 0x17 - WD_CMD_SND (uninmplemented) */
1356   &wd33c93_invalid_cmd,   /* 0x18 - WD_CMD_TRANS_ADDR (uninmplemented) */
1357   &wd33c93_invalid_cmd,   /* 0x19 - WD_CMD_XFER_PAD (uninmplemented) */
1358   &wd33c93_invalid_cmd,   /* 0x1a - invalid */
1359   &wd33c93_invalid_cmd,   /* 0x1b - invalid */
1360   &wd33c93_invalid_cmd,   /* 0x1c - invalid */
1361   &wd33c93_invalid_cmd,   /* 0x1d - invalid */
1362   &wd33c93_invalid_cmd,   /* 0x1e - invalid */
1363   &wd33c93_invalid_cmd,   /* 0x1f - invalid */
1364   &wd33c93_xferinfo_cmd,   /* 0x20 - WD_CMD_TRANS_INFO) */
1365   &wd33c93_invalid_cmd   /* 0x21 - WD_CMD_TRANSFER_PAD (uninmplemented) */
1366};
1367
1368/* Handle pending commands */
1369static void wd33c93_command( void )
1370{
1371   /* get the command */
1372   UINT8 cmd = scsi_data.regs[WD_COMMAND];
1373
1374   /* check if its within valid bounds */
1375   if ( (cmd & 0x7F) > WD_CMD_TRANSFER_PAD )
1376   {
1377      wd33c93_invalid_cmd();
1378      return;
1379   }
1380
1381   /* call the command handler */
1382   (*wd33c93_cmds[cmd & 0x7F])();
1383}
1384
1385WRITE8_HANDLER(wd33c93_w)
1386{
1387   switch( offset )
1388   {
1389      case 0:
1390      {
1391         /* update register select */
1392         scsi_data.sasr = data & 0x1f;
1393      }
1394      break;
1395
1396      case 1:
1397      {
1398#if VERBOSE
1399         logerror( "WD33C93: PC=%08x - Write REG=%02x, data = %02x\n", safe_activecpu_get_pc(), scsi_data.sasr, data );
1400#endif
1401
1402         /* update the register */
1403         scsi_data.regs[scsi_data.sasr] = data;
1404
1405         /* if we receive a command, schedule to process it */
1406         if ( scsi_data.sasr == WD_COMMAND )
1407         {
1408#if VERBOSE
1409            logerror( "WDC33C93: PC=%08x - Executing command %08x - unit %d\n", safe_activecpu_get_pc(), data, wd33c93_getunit() );
1410#endif
1411
1412            /* signal we're processing it */
1413            scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_CIP;
1414
1415            /* process the command */
1416            wd33c93_command();
1417         }
1418         else if ( scsi_data.sasr == WD_CDB_1 )
1419         {
1420            scsi_data.regs[WD_COMMAND_PHASE] = 0;
1421         }
1422         else if ( scsi_data.sasr == WD_DATA )
1423         {
1424            /* if data was written, and we have a count, send to device */
1425            int      count = wd33c93_get_xfer_count();
1426
1427            if ( scsi_data.regs[WD_COMMAND] & 0x80 )
1428               count = 1;
1429
1430            if ( count-- > 0 )
1431            {
1432               /* write to FIFO */
1433               if ( scsi_data.fifo_pos < FIFO_SIZE )
1434               {
1435                  scsi_data.fifo[scsi_data.fifo_pos++] = data;
1436               }
1437
1438               /* update count */
1439               wd33c93_set_xfer_count( count );
1440
1441               /* if we're done with the write, see where we're at */
1442               if ( count == 0 )
1443               {
1444                  scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT;
1445                  scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR;
1446
1447                  switch( scsi_data.busphase )
1448                  {
1449                     case PHS_MESS_OUT:
1450                     {
1451                        /* reset fifo */
1452                        scsi_data.fifo_pos = 0;
1453
1454                        /* Message out phase. Data is probably SCSI Identify. Move to command phase. */
1455                        scsi_data.busphase = PHS_COMMAND;
1456
1457                        scsi_data.identify = scsi_data.fifo[0];
1458                     }
1459                     break;
1460
1461                     case PHS_COMMAND:
1462                     {
1463                        UINT8   unit = wd33c93_getunit();
1464                        int      xfercount;
1465
1466                        /* Execute the command. Depending on the command, we'll move to data in or out */
1467                        xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.fifo[0]);
1468
1469                        /* reset fifo */
1470                        scsi_data.fifo_pos = 0;
1471
1472                        /* set the new count */
1473                        wd33c93_set_xfer_count( xfercount );
1474
1475                        if ( xfercount == 0 )
1476                        {
1477                           /* move to status phase */
1478                           scsi_data.busphase = PHS_STATUS;
1479                        }
1480                        else
1481                        {
1482                           /* update bus phase */
1483                           if ( scsi_data.fifo[0] == 0x15 || scsi_data.fifo[0] == 0x55 ) /* MODE SELECT */
1484                           {
1485                              scsi_data.busphase = PHS_DATA_OUT;
1486                           }
1487                           else
1488                           {
1489                              scsi_data.busphase = PHS_DATA_IN;
1490                              scsi_data.read_pending = 1;
1491                           }
1492                        }
1493                     }
1494                     break;
1495
1496                     case PHS_DATA_OUT:
1497                     {
1498                        /* write data out to device */
1499                        wd33c93_write_data( scsi_data.fifo_pos, scsi_data.fifo );
1500
1501                        /* reset fifo */
1502                        scsi_data.fifo_pos = 0;
1503
1504                        /* move to status phase */
1505                        scsi_data.busphase = PHS_STATUS;
1506                     }
1507                     break;
1508                  }
1509
1510                  /* complete the command */
1511                  wd33c93_complete_immediate(CSR_XFER_DONE | scsi_data.busphase);
1512               }
1513            }
1514            else
1515            {
1516               logerror( "WD33C93: Sending data to device with transfer count = 0!. Ignoring...\n" );
1517            }
1518         }
1519
1520         /* auto-increment register select if not on special registers */
1521         if ( scsi_data.sasr != WD_COMMAND && scsi_data.sasr != WD_DATA && scsi_data.sasr != WD_AUXILIARY_STATUS )
1522         {
1523            scsi_data.sasr = ( scsi_data.sasr + 1 ) & 0x1f;
1524         }
1525      }
1526      break;
1527
1528      default:
1529      {
1530         logerror( "WD33C93: Write to invalid offset %d (data=%02x)\n", offset, data );
1531      }
1532      break;
1533   }
1534}
1535
1536READ8_HANDLER(wd33c93_r)
1537{
1538   switch( offset )
1539   {
1540      case 0:
1541      {
1542         /* read aux status */
1543         return scsi_data.regs[WD_AUXILIARY_STATUS];
1544      }
1545      break;
1546
1547      case 1:
1548      {
1549         UINT8   ret;
1550
1551         /* if reading status, clear irq flag */
1552         if ( scsi_data.sasr == WD_SCSI_STATUS )
1553         {
1554            scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_INT;
1555
1556            if (intf && intf->irq_callback)
1557            {
1558               intf->irq_callback(0);
1559            }
1560
1561#if VERBOSE
1562            logerror( "WD33C93: PC=%08x - Status read (%02x)\n", safe_activecpu_get_pc(), scsi_data.regs[WD_SCSI_STATUS] );
1563#endif
1564         }
1565         else if ( scsi_data.sasr == WD_DATA )
1566         {
1567            /* we're going to be doing synchronous reads */
1568
1569            /* get the transfer count */
1570            int      count = wd33c93_get_xfer_count();
1571
1572            /* initialize the return value */
1573            scsi_data.regs[WD_DATA] = 0;
1574
1575            if ( count <= 0 && scsi_data.busphase == PHS_MESS_IN )
1576            {
1577               /* move to disconnect */
1578               wd33c93_complete_cmd(CSR_DISC);
1579            }
1580            else if ( count == 1 && scsi_data.busphase == PHS_STATUS )
1581            {
1582               /* update the count */
1583               wd33c93_set_xfer_count( 0 );
1584
1585               /* move to message in phase */
1586               scsi_data.busphase = PHS_MESS_IN;
1587
1588               /* complete the command */
1589               wd33c93_complete_cmd(CSR_XFER_DONE | scsi_data.busphase);
1590            }
1591            else if ( count-- > 0 ) /* make sure we still have data to send */
1592            {
1593               if ( scsi_data.read_pending )
1594               {
1595                  int      len = TEMP_INPUT_LEN;
1596
1597                  if ( (count+1) < len ) len = count+1;
1598                  wd33c93_read_data( len, &scsi_data.temp_input[0] );
1599                  scsi_data.temp_input_pos = 0;
1600                  scsi_data.read_pending = 0;
1601               }
1602
1603               scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_INT;
1604
1605               /* read in one byte */
1606               if ( scsi_data.temp_input_pos < TEMP_INPUT_LEN )
1607                  scsi_data.regs[WD_DATA] = scsi_data.temp_input[scsi_data.temp_input_pos++];
1608
1609               /* update the count */
1610               wd33c93_set_xfer_count( count );
1611
1612               /* transfer finished, see where we're at */
1613               if ( count == 0 )
1614               {
1615                  if ( scsi_data.regs[WD_COMMAND_PHASE] != 0x60 )
1616                  {
1617                     /* move to status phase */
1618                     scsi_data.busphase = PHS_STATUS;
1619
1620                     /* complete the command */
1621                     wd33c93_complete_cmd(CSR_XFER_DONE | scsi_data.busphase);
1622                  }
1623                  else
1624                  {
1625                     scsi_data.regs[WD_AUXILIARY_STATUS] |= ASR_INT;
1626                     scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR;
1627                  }
1628               }
1629            }
1630         }
1631
1632#if VERBOSE
1633         logerror( "WD33C93: PC=%08x - Data read (%02x)\n", safe_activecpu_get_pc(), scsi_data.regs[WD_DATA] );
1634#endif
1635
1636         /* get the register value */
1637         ret = scsi_data.regs[scsi_data.sasr];
1638
1639         /* auto-increment register select if not on special registers */
1640         if ( scsi_data.sasr != WD_COMMAND && scsi_data.sasr != WD_DATA && scsi_data.sasr != WD_AUXILIARY_STATUS )
1641         {
1642            scsi_data.sasr = ( scsi_data.sasr + 1 ) & 0x1f;
1643         }
1644
1645         return ret;
1646      }
1647
1648      default:
1649      {
1650         logerror( "WD33C93: Read from invalid offset %d\n", offset );
1651      }
1652      break;
1653   }
1654
1655   return 0;
1656}
1657
1658extern void wd33c93_init( struct WD33C93interface *interface )
1659{
1660   int i;
1661
1662   // save interface pointer for later
1663   intf = interface;
1664
1665   memset(&scsi_data, 0, sizeof(scsi_data));
1666   memset(devices, 0, sizeof(devices));
1667
1668   // try to open the devices
1669   for (i = 0; i < interface->scsidevs->devs_present; i++)
1670   {
1671      devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler;
1672      interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL);
1673   }
1674
1675   /* allocate a timer for commands */
1676   scsi_data.cmd_timer = mame_timer_alloc(wd33c93_complete_cb);
1677
1678   scsi_data.temp_input = auto_malloc( TEMP_INPUT_LEN );
1679
1680//  state_save_register_item_array("wd33c93", 0, scsi_data);
1681}
1682
1683void wd33c93_get_dma_data( int bytes, UINT8 *pData )
1684{
1685   int      len = bytes;
1686
1687   if ( len >= wd33c93_get_xfer_count() )
1688      len = wd33c93_get_xfer_count();
1689
1690   if ( len == 0 )
1691      return;
1692
1693   if ( (scsi_data.temp_input_pos+len) >= TEMP_INPUT_LEN )
1694   {
1695      logerror( "Reading past end of buffer, increase TEMP_INPUT_LEN size\n" );
1696      len = TEMP_INPUT_LEN - len;
1697   }
1698
1699   memcpy( pData, &scsi_data.temp_input[scsi_data.temp_input_pos], len );
1700
1701   scsi_data.temp_input_pos += len;
1702   len = wd33c93_get_xfer_count() - len;
1703   wd33c93_set_xfer_count(len);
1704}
1705
1706void wd33c93_write_data(int bytes, UINT8 *pData)
1707{
1708   UINT8   unit = wd33c93_getunit();
1709
1710   if (devices[unit].handler)
1711   {
1712      devices[unit].handler(SCSIOP_WRITE_DATA, devices[unit].data, bytes, pData);
1713   }
1714   else
1715   {
1716      logerror("wd33c93: request for unknown device SCSI ID %d\n", unit);
1717   }
1718}
1719
1720void *wd33c93_get_device(int id)
1721{
1722   void *ret;
1723
1724   if (devices[id].handler)
1725   {
1726      devices[id].handler(SCSIOP_GET_DEVICE, devices[id].data, 0, (UINT8 *)&ret);
1727
1728      return ret;
1729   }
1730
1731   return NULL;
1732}
1733
1734void wd33c93_clear_dma(void)
1735{
1736   /* indicate DMA completed by clearing the transfer count */
1737   wd33c93_set_xfer_count(0);
1738   scsi_data.regs[WD_AUXILIARY_STATUS] &= ~ASR_DBR;
1739}
1740
1741int wd33c93_get_dma_count(void)
1742{
1743   return wd33c93_get_xfer_count();
1744}
src/mame/machine/wd33c93.h
r936r937
2525extern WRITE8_HANDLER(wd33c93_w);
2626
2727#endif
28/*
29 * wd33c93.h
30 *
31 */
32
33#ifndef _WD33C93_H_
34#define _WD33C93_H_
35
36#include "machine/scsidev.h"
37
38struct WD33C93interface
39{
40   SCSIConfigTable *scsidevs;      /* SCSI devices */
41   void (*irq_callback)(int state);   /* irq callback */
42};
43
44extern void wd33c93_init( struct WD33C93interface *interface );
45extern void wd33c93_get_dma_data(int bytes, UINT8 *pData);
46extern void wd33c93_write_data(int bytes, UINT8 *pData);
47extern void *wd33c93_get_device(int id);
48extern void wd33c93_set_device(int id, void *);
49extern void wd33c93_clear_dma(void);
50extern int wd33c93_get_dma_count(void);
51extern READ8_HANDLER(wd33c93_r);
52extern WRITE8_HANDLER(wd33c93_w);
53
54#endif
src/mame/machine/cps2crpt.c
r936r937
532532// for the 2nd FN (2x32 bits)
533533static void expand_subkey(UINT32* subkey, UINT16 seed)
534534{
535   // Note that every bit of the seed is used exactly 4 times.
535   // Note that each row of the table is a permutation of the seed bits.
536536   static const int bits[64] =
537537   {
538       5, 10, 14,  9,  4,  0, 15,  6,
539       1,  8,  3,  2, 12,  7, 13, 11,
540       5, 12,  7,  2, 13, 11,  9, 14,
541       4,  1,  6, 10,  8,  0, 15,  3,
542       4, 10,  2,  0,  6,  9, 12,  1,
543      11,  7, 15,  8, 13,  5, 14,  3,
544      14, 11, 12,  7,  4,  5,  2, 10,
545       1, 15,  0,  9,  8,  6, 13,  3,
538       5, 10, 14,  9,  4,  0, 15,  6,  1,  8,  3,  2, 12,  7, 13, 11,
539       5, 12,  7,  2, 13, 11,  9, 14,  4,  1,  6, 10,  8,  0, 15,  3,
540       4, 10,  2,  0,  6,  9, 12,  1, 11,  7, 15,  8, 13,  5, 14,  3,
541      14, 11, 12,  7,  4,  5,  2, 10,  1, 15,  0,  9,  8,  6, 13,  3,
546542   };
547543   int i;
548544
r936r937
559555      const struct optimised_sbox* boxes1, const struct optimised_sbox* boxes2, const struct optimised_sbox* boxes3, const struct optimised_sbox* boxes4,
560556      UINT32 key1, UINT32 key2, UINT32 key3, UINT32 key4)
561557{
562   const UINT8 l0 = BITSWAP8(val, bitsB[7],bitsB[6],bitsB[5],bitsB[4],bitsB[3],bitsB[2],bitsB[1],bitsB[0]);
563   const UINT8 r0 = BITSWAP8(val, bitsA[7],bitsA[6],bitsA[5],bitsA[4],bitsA[3],bitsA[2],bitsA[1],bitsA[0]);
558   UINT8 l = BITSWAP8(val, bitsB[7],bitsB[6],bitsB[5],bitsB[4],bitsB[3],bitsB[2],bitsB[1],bitsB[0]);
559   UINT8 r = BITSWAP8(val, bitsA[7],bitsA[6],bitsA[5],bitsA[4],bitsA[3],bitsA[2],bitsA[1],bitsA[0]);
564560
565   const UINT8 l1 = r0;
566   const UINT8 r1 = l0 ^ fn(r0, boxes1, key1);
561   l ^= fn(r, boxes1, key1);
562   r ^= fn(l, boxes2, key2);
563   l ^= fn(r, boxes3, key3);
564   r ^= fn(l, boxes4, key4);
567565
568   const UINT8 l2 = r1;
569   const UINT8 r2 = l1 ^ fn(r1, boxes2, key2);
570
571   const UINT8 l3 = r2;
572   const UINT8 r3 = l2 ^ fn(r2, boxes3, key3);
573
574   const UINT8 l4 = r3;
575   const UINT8 r4 = l3 ^ fn(r3, boxes4, key4);
576
577566   return
578      (BIT(l4, 0) << bitsA[0]) |
579      (BIT(l4, 1) << bitsA[1]) |
580      (BIT(l4, 2) << bitsA[2]) |
581      (BIT(l4, 3) << bitsA[3]) |
582      (BIT(l4, 4) << bitsA[4]) |
583      (BIT(l4, 5) << bitsA[5]) |
584      (BIT(l4, 6) << bitsA[6]) |
585      (BIT(l4, 7) << bitsA[7]) |
586      (BIT(r4, 0) << bitsB[0]) |
587      (BIT(r4, 1) << bitsB[1]) |
588      (BIT(r4, 2) << bitsB[2]) |
589      (BIT(r4, 3) << bitsB[3]) |
590      (BIT(r4, 4) << bitsB[4]) |
591      (BIT(r4, 5) << bitsB[5]) |
592      (BIT(r4, 6) << bitsB[6]) |
593      (BIT(r4, 7) << bitsB[7]);
567      (BIT(l, 0) << bitsA[0]) |
568      (BIT(l, 1) << bitsA[1]) |
569      (BIT(l, 2) << bitsA[2]) |
570      (BIT(l, 3) << bitsA[3]) |
571      (BIT(l, 4) << bitsA[4]) |
572      (BIT(l, 5) << bitsA[5]) |
573      (BIT(l, 6) << bitsA[6]) |
574      (BIT(l, 7) << bitsA[7]) |
575      (BIT(r, 0) << bitsB[0]) |
576      (BIT(r, 1) << bitsB[1]) |
577      (BIT(r, 2) << bitsB[2]) |
578      (BIT(r, 3) << bitsB[3]) |
579      (BIT(r, 4) << bitsB[4]) |
580      (BIT(r, 5) << bitsB[5]) |
581      (BIT(r, 6) << bitsB[6]) |
582      (BIT(r, 7) << bitsB[7]);
594583}
595584
596585
r936r937
792781   { "xmcotah",  { 0xf5e8dc34,0xa096b217 }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
793782   { "xmcotaj",  { 0x46027315,0xaf8bcd9e }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
794783   { "xmcotaj1", { 0x46027315,0xaf8bcd9e }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
784   { "xmcotaj2", { 0x46027315,0xaf8bcd9e }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
795785   { "xmcotajr", { 0x46027315,0xaf8bcd9e }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
796786   { "xmcotaa",  { 0x0795a4e2,0xdb3f861c }, 0x100000 },   // 0C80 1972 0301  cmpi.l  #$19720301,D0
797787   { "armwar",   { 0x9e9d4c0b,0x8a39081f }, 0x100000 },   // 3039 0080 4020  move.w  $00804020,D0
src/mame/machine/playch10.c
r936r937
221221      int x = readinputport( 5 );
222222      int y = readinputport( 6 );
223223      UINT32 pix, color_base;
224      pen_t *pens = Machine->pens;
224      const pen_t *pens = Machine->pens;
225225
226226      /* no sprite hit (yet) */
227227      ret |= 0x08;
src/mame/machine/konamigx.c
r936r937
221221   int src_pitch, incxy, incxx;
222222   int src_minx, src_maxx, src_miny, src_maxy, cmask;
223223   UINT16 *src_base;
224   UINT32 *pal_base;
224   const pen_t *pal_base;
225225   UINT32 *dst_ptr;
226226
227227   int tx, dst_pitch;
r936r937
476476   UINT8  z8, db0, p8, db1;
477477   UINT8  *ozbuf_ptr;
478478   UINT8  *szbuf_ptr;
479   UINT32 *pal_base;
480   UINT32 *shd_base;
479   const pen_t *pal_base;
480   const pen_t *shd_base;
481481   UINT32 *dst_ptr;
482482
483483   // outter loop
r936r937
523523   src_fh    = 16;
524524   src_base  = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
525525
526   pal_base  = gfx->colortable + (color % gfx->total_colors) * granularity;
526   pal_base  = Machine->remapped_colortable + gfx->color_base + (color % gfx->total_colors) * granularity;
527527   shd_base  = Machine->shadow_table;
528528
529529   dst_ptr   = bitmap->base;
src/mame/machine/snes.c
r936r937
13371337            r = (r * fade) >> 4;
13381338            g = (g * fade) >> 4;
13391339            b = (b * fade) >> 4;
1340            Machine->remapped_colortable[FIXED_COLOUR] = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
1340            /* palette hacks! */
1341            ((pen_t *)Machine->remapped_colortable)[FIXED_COLOUR] = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
13411342         } break;
13421343      case SETINI:   /* Screen mode/video select */
13431344         /* FIXME: We only support line count here */
src/mame/mamedriv.c
r936r937
651651   DRIVER( skykid )   /* (c) 1985 */
652652   DRIVER( skykido )   /* (c) 1985 */
653653   DRIVER( skykidd )   /* (c) 1985 */
654   DRIVER( aliensec )   /* (c) 1985 */
654655   DRIVER( baraduke )   /* (c) 1985 */
655   DRIVER( baraduka )   /* (c) 1985 */
656656   DRIVER( metrocrs )   /* (c) 1985 */
657657   DRIVER( metrocra )   /* (c) 1985 */
658658
r936r937
24872487   DRIVER( xmcota )   /* 05/01/1995 (c) 1994 (Euro) */
24882488   DRIVER( xmcotau )   /* 05/01/1995 (c) 1994 (US) */
24892489   DRIVER( xmcotah )   /* 31/03/1995 (c) 1994 (Hispanic) */
2490   DRIVER( xmcotaj )   /* 19/12/1994 (c) 1994 (Japan) */
2491   DRIVER( xmcotaj1 )   /* 17/12/1994 (c) 1994 (Japan) */
2490   DRIVER( xmcotaj )   /* 22/12/1994 (c) 1994 (Japan) */
2491   DRIVER( xmcotaj1 )   /* 19/12/1994 (c) 1994 (Japan) */
2492   DRIVER( xmcotaj2 )   /* 17/12/1994 (c) 1994 (Japan) */
24922493   DRIVER( xmcotaa )   /* 17/12/1994 (c) 1994 (Asia) */
24932494   DRIVER( xmcotajr )   /* 08/12/1994 (c) 1994 (Japan Rent) */
24942495   DRIVER( nwarr )      /* 16/03/1995 (c) 1995 (Euro) */
r936r937
28462847   DRIVER( dstage )   /* 1999 - Dancing Stage (GN845 VER. EAA) */
28472848   DRIVER( ddru )      /* 1999 - Dance Dance Revolution (GN845 VER. UAA) */
28482849   DRIVER( ddrj )      /* 1998 - Dance Dance Revolution - Internet Ranking Ver (GC845 VER. JBA) */
2849   DRIVER( ddrja )      /* 1998 - Dance Dance Revolution (GC845 VER. JAB) */
2850   DRIVER( ddrja )      /* 1998 - Dance Dance Revolution (GC845 VER. JAA) */
2851   DRIVER( ddrjb )      /* 1998 - Dance Dance Revolution (GC845 VER. JAB) */
28502852   DRIVER( ddra )      /* 1999 - Dance Dance Revolution (GN845 VER. AAA) */
28512853   DRIVER( fbait2bc )   /* 1998 - Fisherman's Bait 2 - A Bass Challenge (GE865 VER. UAB) */
28522854   DRIVER( drmn )      /* 1999 - DrumMania (GQ881 VER. JAD) */
r936r937
28652867   DRIVER( ddr2mc2 )   /* 1999 - Dance Dance Revolution 2nd Mix with beatmaniaIIDX substream CLUB VERSiON 2 (GE984 VER. JAA) */
28662868   DRIVER( gtrfrk2m )   /* 1999 - Guitar Freaks 2nd Mix Ver 1.01 (GQ883 VER. JAD) */
28672869   DRIVER( dsftkd )   /* 1999 - Dancing Stage featuring TRUE KiSS DESTiNATiON (G*884 VER. JAA) */
2868   DRIVER( ddrsbm )   /* 1999 - Dance Dance Revolution Solo Bass Mix (GQ894 VER. JAA) */
2869   DRIVER( ddrs2k )   /* 1999 - Dance Dance Revolution Solo 2000 (GC905 VER. AAA) */
2870   DRIVER( ddrs2kj )   /* 1999 - Dance Dance Revolution Solo 2000 (GC905 VER. JAA) */
28712870   DRIVER( ddr3mk )   /* 2000 - Dance Dance Revolution 3rd Mix - Ver.Korea2 (GN887 VER. KBA) */
28722871   DRIVER( ddr3mka )   /* 2000 - Dance Dance Revolution 3rd Mix - Ver.Korea (GN887 VER. KAA) */
28732872   DRIVER( ddr3ma )   /* 1999 - Dance Dance Revolution 3rd Mix (GN887 VER. AAA) */
28742873   DRIVER( ddr3mj )   /* 1999 - Dance Dance Revolution 3rd Mix (GN887 VER. JAA) */
2874   DRIVER( ddrsbm )   /* 1999 - Dance Dance Revolution Solo Bass Mix (GQ894 VER. JAA) */
2875   DRIVER( ddrs2k )   /* 1999 - Dance Dance Revolution Solo 2000 (GC905 VER. AAA) */
2876   DRIVER( ddrs2kj )   /* 1999 - Dance Dance Revolution Solo 2000 (GC905 VER. JAA) */
2877   DRIVER( dsfdct )   /* 1999 - Dancing Stage featuring Dreams Come True (GC910 VER. JCA) */
2878   DRIVER( dsfdcta )   /* 1999 - Dancing Stage featuring Dreams Come True (GC910 VER. JAA) */
28752879   DRIVER( drmn2m )   /* 1999 - DrumMania 2nd Mix (GE912 VER. JAA) */
28762880   DRIVER( dncfrks )   /* 2000 - Dance Freaks (G*874 VER. KAA) */
28772881   DRIVER( dmx )      /* 2000 - Dance Maniax (G*874 VER. JAA) */
r936r937
28962900   DRIVER( ddrmax )   /* 2001 - DDR Max - Dance Dance Revolution 6th Mix (G*B19 VER. JAA) */
28972901   DRIVER( ddrmax2 )   /* 2002 - DDR Max 2 - Dance Dance Revolution 7th Mix (G*B20 VER. JAA) */
28982902   DRIVER( dsem2 )      /* 2002 - Dancing Stage Euro Mix 2 (G*C23 VER. EAA) */
2903   DRIVER( ddrextrm )   /* 2002 - Dance Dance Revolution Extreme (G*C36 VER. JAA) */
28992904   DRIVER( gtfrk11m )   /* 2004 - Guitar Freaks 11th Mix (G*D39 VER. JAA) */
29002905
29012906   /* Konami Viper games */
r936r937
64926497   /* Seta games */
64936498   DRIVER( hanaawas )   /* (c) SetaKikaku */
64946499   DRIVER( speedatk )   /* CB-0 (c) SetaKikaku */
6500   DRIVER( srmp1 )      /* UB or UC?? (c) 1987 */
64956501   DRIVER( srmp2 )      /* UB or UC?? (c) 1987 */
64966502   DRIVER( srmp3 )      /* ZA-0? (c) 1988 */
64976503   DRIVER( mjyuugi )   /* (c) 1990 Visco */
r936r937
69036909   DRIVER( mjfriday )   /* "26" (c) [1989] Dynax */
69046910   DRIVER( jantouki )   /* "27" Jantouki 1989 Dynax */
69056911   DRIVER( mjifb )      /* "29" 1990 Dynax */
6912   DRIVER( cafetime )   /* 1992 Dynax */
69066913   DRIVER( janptr96 )   /* 1996 Dynax */
69076914   DRIVER( sprtmtch )   /* "31" (c) 1989 Dynax + Fabtek license */
69086915   DRIVER( maya )      /* (c) 1994 Promat */
r936r937
69106917   DRIVER( mcnpshnt )   /* "33" Mahjong Campus Hunting 1990 Dynax */
69116918   DRIVER( 7jigen )   /* "37" 7jigen no Youseitachi 1990 Dynax */
69126919   DRIVER( neruton )   /* "45" Neruton Haikujiradan 1990 Dynax */
6920   DRIVER( mjcomv1 )   /* 1991 Dynax */
69136921   DRIVER( shpeng )   /* (c) 1995 WSAC Systems */
69146922   DRIVER( tenkai )   /* 1991 Dynax */
69156923   DRIVER( tenkai2b )   /* 1991 Dynax */
r936r937
72407248   /* Scorpion 2+Video Board Games */
72417249   DRIVER( qntoondo )   /* 1993 */
72427250   DRIVER( quintoon )   /* 1993 */
7251   DRIVER( quintono )   /* 1993 */
72437252   DRIVER( qntoond )   /* 1993 */
72447253   DRIVER( pokio )      /* 1994 */
72457254   DRIVER( slotsnl )   /* 1995 */
r936r937
74737482   DRIVER( puzlbang )   /* (c) 1999 Omega System */
74747483   DRIVER( suplup )   /* (c) 1999 Omega System */
74757484   DRIVER( vamphalf )   /* (c) 1999 DanBi & F2 System */
7485   DRIVER( dquizgo2 )   /* (c) 2000 Semicom */
74767486   DRIVER( misncrft )   /* (c) 2000 Sun */
74777487   DRIVER( hidnctch )   /* (c) 1998 Eolith */
74787488   DRIVER( puzzlekg )   /* (c) 1998 Eolith */
r936r937
76427652   DRIVER( go2000 )   /* (c) 2000 SA */
76437653   DRIVER( mirax )      /* (c) 1985 Current Technologies */
76447654   DRIVER( lastfght )   /* (c) 2000 Subsino */
7655   DRIVER( bishjan )   /* (c) 1999 Subsino */
76457656   DRIVER( sliver )   /* (c) 1996 Hollow Corp */
76467657   DRIVER( intrscti )   /* ???? */
76477658   DRIVER( pasha2 )   /* (c) 1998 Dong Sung */
src/mame/includes/taitoipt.h
r936r937
377377#define TAITO_JOY_DUAL_UDRL(PL_L, PL_H) \
378378   TAITO_GENERIC_JOY_DUAL_UDRL(PL_L, PL_H)
379379
380/*******************************************************************************
381
382    Input port macros used by many games in mutiple Taito drivers
383
384*******************************************************************************/
385
386
387/**************************** Machine Dip Swicthes ****************************/
388
389/* with location */
390#define TAITO_DSWA_BITS_2_TO_3_LOC(DIPBANK) \
391   PORT_SERVICE_DIPLOC( 0x04, IP_ACTIVE_LOW, #DIPBANK":3" ) \
392   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION(#DIPBANK":4") \
393   PORT_DIPSETTING(    0x00, DEF_STR( Off ) ) \
394   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
395
396#define TAITO_DSWA_BITS_1_TO_3_LOC(DIPBANK) \
397   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION(#DIPBANK":2") \
398   PORT_DIPSETTING(    0x02, DEF_STR( Off ) ) \
399   PORT_DIPSETTING(    0x00, DEF_STR( On ) ) \
400   TAITO_DSWA_BITS_2_TO_3_LOC(DIPBANK)
401
402#define TAITO_MACHINE_COCKTAIL_LOC(DIPBANK) \
403   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION(#DIPBANK":1") \
404   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) ) \
405   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) ) \
406   TAITO_DSWA_BITS_1_TO_3_LOC(DIPBANK)
407
408#define TAITO_MACHINE_NO_COCKTAIL_LOC(DIPBANK) \
409   PORT_DIPUNUSED_DIPLOC( 0x01, IP_ACTIVE_LOW, #DIPBANK":1" ) \
410   TAITO_DSWA_BITS_1_TO_3_LOC(DIPBANK)
411
412
413/* without location */
414#define TAITO_DSWA_BITS_2_TO_3 \
415   PORT_SERVICE( 0x04, IP_ACTIVE_LOW ) \
416   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Demo_Sounds ) ) \
417   PORT_DIPSETTING(    0x00, DEF_STR( Off ) ) \
418   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
419
420#define TAITO_DSWA_BITS_1_TO_3 \
421   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) ) \
422   PORT_DIPSETTING(    0x02, DEF_STR( Off ) ) \
423   PORT_DIPSETTING(    0x00, DEF_STR( On ) ) \
424   TAITO_DSWA_BITS_2_TO_3
425
426#define TAITO_MACHINE_COCKTAIL \
427   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) \
428   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) ) \
429   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) ) \
430   TAITO_DSWA_BITS_1_TO_3
431
432#define TAITO_MACHINE_NO_COCKTAIL \
433   PORT_DIPUNUSED( 0x01, IP_ACTIVE_LOW ) \
434   TAITO_DSWA_BITS_1_TO_3
435
436
437/**************************** Coinage Dip Swicthes ****************************/
438
439/* with location */
440#define TAITO_COINAGE_JAPAN_OLD_COIN_A_LOC(DIPBANK) \
441   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) PORT_DIPLOCATION(#DIPBANK":5,6") \
442   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) ) \
443   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) ) \
444   PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) ) \
445   PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
446
447#define TAITO_COINAGE_JAPAN_OLD_COIN_B_LOC(DIPBANK) \
448   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION(#DIPBANK":7,8") \
449   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
450   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) ) \
451   PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) ) \
452   PORT_DIPSETTING(    0x80, DEF_STR( 1C_2C ) )
453
454#define TAITO_COINAGE_JAPAN_NEW_COIN_A_LOC(DIPBANK) \
455   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) PORT_DIPLOCATION(#DIPBANK":5,6") \
456   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
457   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) ) \
458   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) ) \
459   PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
460
461#define TAITO_COINAGE_JAPAN_NEW_COIN_B_LOC(DIPBANK) \
462   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION(#DIPBANK":7,8") \
463   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
464   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
465   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) ) \
466   PORT_DIPSETTING(    0x80, DEF_STR( 1C_2C ) )
467
468#define TAITO_COINAGE_WORLD_COIN_A_LOC(DIPBANK) \
469   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) PORT_DIPLOCATION(#DIPBANK":5,6") \
470   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) ) \
471   PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) ) \
472   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) ) \
473   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
474
475#define TAITO_COINAGE_WORLD_COIN_B_LOC(DIPBANK) \
476   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION(#DIPBANK":7,8") \
477   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_2C ) ) \
478   PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) ) \
479   PORT_DIPSETTING(    0x40, DEF_STR( 1C_4C ) ) \
480   PORT_DIPSETTING(    0x00, DEF_STR( 1C_6C ) )
481
482#define TAITO_COINAGE_US_COIN_START_LOC(DIPBANK) \
483   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coinage ) ) PORT_DIPLOCATION(#DIPBANK":5,6") \
484   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) ) \
485   PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) ) \
486   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) ) \
487   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
488
489#define TAITO_COINAGE_US_COIN_CONT_LOC(DIPBANK) \
490   PORT_DIPNAME( 0xc0, 0xc0, "Price to Continue" ) PORT_DIPLOCATION(#DIPBANK":7,8") \
491   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
492   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
493   PORT_DIPSETTING(    0x80, DEF_STR( 1C_1C ) ) \
494   PORT_DIPSETTING(    0xc0, "Same as Start" )
495
496#define TAITO_COINAGE_JAPAN_OLD_LOC(DIPBANK) \
497   TAITO_COINAGE_JAPAN_OLD_COIN_A_LOC(DIPBANK) \
498   TAITO_COINAGE_JAPAN_OLD_COIN_B_LOC(DIPBANK)
499
500#define TAITO_COINAGE_JAPAN_NEW_LOC(DIPBANK) \
501   TAITO_COINAGE_JAPAN_NEW_COIN_A_LOC(DIPBANK) \
502   TAITO_COINAGE_JAPAN_NEW_COIN_B_LOC(DIPBANK)
503
504#define TAITO_COINAGE_WORLD_LOC(DIPBANK) \
505   TAITO_COINAGE_WORLD_COIN_A_LOC(DIPBANK) \
506   TAITO_COINAGE_WORLD_COIN_B_LOC(DIPBANK)
507
508#define TAITO_COINAGE_US_LOC(DIPBANK) \
509   TAITO_COINAGE_US_COIN_START_LOC(DIPBANK) \
510   TAITO_COINAGE_US_COIN_CONT_LOC(DIPBANK)
511
512
513/* without location */
514#define TAITO_COINAGE_JAPAN_OLD_COIN_A \
515   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) \
516   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) ) \
517   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) ) \
518   PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) ) \
519   PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
520
521#define TAITO_COINAGE_JAPAN_OLD_COIN_B \
522   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) \
523   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
524   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) ) \
525   PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) ) \
526   PORT_DIPSETTING(    0x80, DEF_STR( 1C_2C ) )
527
528#define TAITO_COINAGE_JAPAN_NEW_COIN_A \
529   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) \
530   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
531   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) ) \
532   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) ) \
533   PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
534
535#define TAITO_COINAGE_JAPAN_NEW_COIN_B \
536   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) \
537   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
538   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
539   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) ) \
540   PORT_DIPSETTING(    0x80, DEF_STR( 1C_2C ) )
541
542#define TAITO_COINAGE_WORLD_COIN_A \
543   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) \
544   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) ) \
545   PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) ) \
546   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) ) \
547   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
548
549#define TAITO_COINAGE_WORLD_COIN_B \
550   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) \
551   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_2C ) ) \
552   PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) ) \
553   PORT_DIPSETTING(    0x40, DEF_STR( 1C_4C ) ) \
554   PORT_DIPSETTING(    0x00, DEF_STR( 1C_6C ) )
555
556#define TAITO_COINAGE_US_COIN_START \
557   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coinage ) ) \
558   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) ) \
559   PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) ) \
560   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) ) \
561   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
562
563#define TAITO_COINAGE_US_COIN_CONT \
564   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Continue_Price ) ) \
565   PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) ) \
566   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) ) \
567   PORT_DIPSETTING(    0x80, DEF_STR( 1C_1C ) ) \
568   PORT_DIPSETTING(    0xc0, "Same as Start" )
569
570#define TAITO_COINAGE_JAPAN_OLD \
571   TAITO_COINAGE_JAPAN_OLD_COIN_A \
572   TAITO_COINAGE_JAPAN_OLD_COIN_B
573
574#define TAITO_COINAGE_JAPAN_NEW \
575   TAITO_COINAGE_JAPAN_NEW_COIN_A \
576   TAITO_COINAGE_JAPAN_NEW_COIN_B
577
578#define TAITO_COINAGE_WORLD \
579   TAITO_COINAGE_WORLD_COIN_A \
580   TAITO_COINAGE_WORLD_COIN_B
581
582#define TAITO_COINAGE_US \
583   TAITO_COINAGE_US_COIN_START \
584   TAITO_COINAGE_US_COIN_CONT
585
586
587/************************** Difficulty Dip Swicthes ***************************/
588
589/* with location */
590#define TAITO_DIFFICULTY_LOC(DIPBANK) \
591   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ) ) PORT_DIPLOCATION(#DIPBANK":1,2") \
592   PORT_DIPSETTING(    0x02, DEF_STR( Easy ) ) \
593   PORT_DIPSETTING(    0x03, DEF_STR( Medium ) ) \
594   PORT_DIPSETTING(    0x01, DEF_STR( Hard ) ) \
595   PORT_DIPSETTING(    0x00, DEF_STR( Hardest ) )
596
597/* without location */
598#define TAITO_DIFFICULTY \
599   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ) ) \
600   PORT_DIPSETTING(    0x02, DEF_STR( Easy ) ) \
601   PORT_DIPSETTING(    0x03, DEF_STR( Medium ) ) \
602   PORT_DIPSETTING(    0x01, DEF_STR( Hard ) ) \
603   PORT_DIPSETTING(    0x00, DEF_STR( Hardest ) )
604
605
606/************************** Joysticks and buttons *****************************/
607
608/* generic (might be moved elsewhere) */
609#define INPUT_GENERIC_JOY_LOW_NIBBLE(PL, STATE, WAY, B01, B02, B04, B08) \
610   PORT_BIT( 0x01, STATE, IPT_JOYSTICK_##B01 ) WAY PORT_PLAYER(PL) \
611   PORT_BIT( 0x02, STATE, IPT_JOYSTICK_##B02 ) WAY PORT_PLAYER(PL) \
612   PORT_BIT( 0x04, STATE, IPT_JOYSTICK_##B04 ) WAY PORT_PLAYER(PL) \
613   PORT_BIT( 0x08, STATE, IPT_JOYSTICK_##B08 ) WAY PORT_PLAYER(PL)
614
615#define INPUT_GENERIC_JOY_HIGH_NIBBLE(PL, STATE, WAY, B10, B20, B40, B80) \
616   PORT_BIT( 0x10, STATE, IPT_JOYSTICK_##B10 ) WAY PORT_PLAYER(PL) \
617   PORT_BIT( 0x20, STATE, IPT_JOYSTICK_##B20 ) WAY PORT_PLAYER(PL) \
618   PORT_BIT( 0x40, STATE, IPT_JOYSTICK_##B40 ) WAY PORT_PLAYER(PL) \
619   PORT_BIT( 0x80, STATE, IPT_JOYSTICK_##B80 ) WAY PORT_PLAYER(PL)
620
621
622/* Taito generic (more might be needed) */
623#define TAITO_GENERIC_JOY_MONO_UDLR(PL) \
624   INPUT_GENERIC_JOY_LOW_NIBBLE(PL, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, LEFT, RIGHT)
625
626#define TAITO_GENERIC_JOY_MONO_UDRL(PL) \
627   INPUT_GENERIC_JOY_LOW_NIBBLE(PL, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, RIGHT, LEFT)
628
629#define TAITO_GENERIC_JOY_MONO_LRUD(PL) \
630   INPUT_GENERIC_JOY_LOW_NIBBLE(PL, IP_ACTIVE_LOW, PORT_8WAY, LEFT, RIGHT, UP, DOWN)
631
632#define TAITO_GENERIC_JOY_DUAL_UDLR(PL_L, PL_H) \
633   INPUT_GENERIC_JOY_LOW_NIBBLE(PL_L, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, LEFT, RIGHT) \
634   INPUT_GENERIC_JOY_HIGH_NIBBLE(PL_H, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, LEFT, RIGHT)
635
636#define TAITO_GENERIC_JOY_DUAL_UDRL(PL_L, PL_H) \
637   INPUT_GENERIC_JOY_LOW_NIBBLE(PL_L, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, RIGHT, LEFT) \
638   INPUT_GENERIC_JOY_HIGH_NIBBLE(PL_H, IP_ACTIVE_LOW, PORT_8WAY, UP, DOWN, RIGHT, LEFT)
639
640
641#define TAITO_GENERIC_BUTTONS_LOW_NIBBLE(PL, STATE, BUTTON_A, BUTTON_B, BUTTON_C) \
642   PORT_BIT( 0x01, STATE, IPT_##BUTTON_A ) PORT_PLAYER(PL) \
643   PORT_BIT( 0x02, STATE, IPT_##BUTTON_B ) PORT_PLAYER(PL) \
644   PORT_BIT( 0x04, STATE, IPT_##BUTTON_C ) PORT_PLAYER(PL)
645   /* DO NOT fill bit 3 as it may be defined as START button ! */
646
647#define TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, STATE, BUTTON_A, BUTTON_B, BUTTON_C) \
648   PORT_BIT( 0x10, STATE, IPT_##BUTTON_A ) PORT_PLAYER(PL) \
649   PORT_BIT( 0x20, STATE, IPT_##BUTTON_B ) PORT_PLAYER(PL) \
650   PORT_BIT( 0x40, STATE, IPT_##BUTTON_C ) PORT_PLAYER(PL)
651   /* DO NOT fill bit 7 as it may be defined as START button ! */
652
653#define TAITO_GENERIC_1_BUTTON(PL) \
654   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, UNKNOWN, UNKNOWN) \
655   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
656
657#define TAITO_GENERIC_2_BUTTONS(PL) \
658   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, BUTTON2, UNKNOWN) \
659   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
660
661#define TAITO_GENERIC_3_BUTTONS(PL) \
662   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, BUTTON2, BUTTON3) \
663   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
664
665#define TAITO_GENERIC_1_BUTTON_START(PL) \
666   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, UNKNOWN, UNKNOWN) \
667   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START##PL )
668
669#define TAITO_GENERIC_2_BUTTONS_START(PL) \
670   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, BUTTON2, UNKNOWN) \
671   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START##PL )
672
673#define TAITO_GENERIC_3_BUTTONS_START(PL) \
674   TAITO_GENERIC_BUTTONS_HIGH_NIBBLE(PL, IP_ACTIVE_LOW, BUTTON1, BUTTON2, BUTTON3) \
675   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START##PL )
676
677
678/* Taito games (more might be needed) */
679#define TAITO_JOY_UDLR_1_BUTTON(PL) \
680   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
681   TAITO_GENERIC_1_BUTTON(PL)
682
683#define TAITO_JOY_UDLR_2_BUTTONS(PL) \
684   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
685   TAITO_GENERIC_2_BUTTONS(PL)
686
687#define TAITO_JOY_UDLR_3_BUTTONS(PL) \
688   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
689   TAITO_GENERIC_3_BUTTONS(PL)
690
691#define TAITO_JOY_UDRL_1_BUTTON(PL) \
692   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
693   TAITO_GENERIC_1_BUTTON(PL)
694
695#define TAITO_JOY_UDRL_2_BUTTONS(PL) \
696   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
697   TAITO_GENERIC_2_BUTTONS(PL)
698
699#define TAITO_JOY_UDRL_3_BUTTONS(PL) \
700   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
701   TAITO_GENERIC_3_BUTTONS(PL)
702
703#define TAITO_JOY_LRUD_1_BUTTON(PL) \
704   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
705   TAITO_GENERIC_1_BUTTON(PL)
706
707#define TAITO_JOY_LRUD_2_BUTTONS(PL) \
708   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
709   TAITO_GENERIC_2_BUTTONS(PL)
710
711#define TAITO_JOY_LRUD_3_BUTTONS(PL) \
712   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
713   TAITO_GENERIC_3_BUTTONS(PL)
714
715
716#define TAITO_JOY_UDLR_1_BUTTON_START(PL) \
717   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
718   TAITO_GENERIC_1_BUTTON_START(PL)
719
720#define TAITO_JOY_UDLR_2_BUTTONS_START(PL) \
721   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
722   TAITO_GENERIC_2_BUTTONS_START(PL)
723
724#define TAITO_JOY_UDLR_3_BUTTONS_START(PL) \
725   TAITO_GENERIC_JOY_MONO_UDLR(PL) \
726   TAITO_GENERIC_3_BUTTONS_START(PL)
727
728#define TAITO_JOY_UDRL_1_BUTTON_START(PL) \
729   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
730   TAITO_GENERIC_1_BUTTONS_START(PL)
731
732#define TAITO_JOY_UDRL_2_BUTTONS_START(PL) \
733   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
734   TAITO_GENERIC_2_BUTTONS_START(PL)
735
736#define TAITO_JOY_UDRL_3_BUTTONS_START(PL) \
737   TAITO_GENERIC_JOY_MONO_UDRL(PL) \
738   TAITO_GENERIC_3_BUTTONS_START(PL)
739
740#define TAITO_JOY_LRUD_1_BUTTON_START(PL) \
741   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
742   TAITO_GENERIC_1_BUTTON_START(PL)
743
744#define TAITO_JOY_LRUD_2_BUTTONS_START(PL) \
745   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
746   TAITO_GENERIC_2_BUTTONS_START(PL)
747
748#define TAITO_JOY_LRUD_3_BUTTONS_START(PL) \
749   TAITO_GENERIC_JOY_MONO_LRUD(PL) \
750   TAITO_GENERIC_3_BUTTONS_START(PL)
751
752
753#define TAITO_JOY_DUAL_UDLR(PL_L, PL_H) \
754   TAITO_GENERIC_JOY_DUAL_UDLR(PL_L, PL_H)
755
756#define TAITO_JOY_DUAL_UDRL(PL_L, PL_H) \
757   TAITO_GENERIC_JOY_DUAL_UDRL(PL_L, PL_H)
758
src/mame/includes/cubocd32.h
r0r937
1/***************************************************************************
2
3CuboCD32 definitions
4
5***************************************************************************/
6
7#ifndef __CUBOCD32_H__
8#define __CUBOCD32_H__
9
10extern void amiga_akiko_init(void);
11extern NVRAM_HANDLER( cd32 );
12extern READ32_HANDLER(amiga_akiko32_r);
13extern WRITE32_HANDLER(amiga_akiko32_w);
14
15#endif /* __CUBOCD32_H__ */
src/mame/includes/docastle.h
r936r937
1717WRITE8_HANDLER( docastle_flipscreen_on_w );
1818
1919PALETTE_INIT( docastle );
20PALETTE_INIT( dorunrun );
2120VIDEO_START( docastle );
21VIDEO_START( dorunrun );
2222VIDEO_UPDATE( docastle );
2323
src/mame/includes/m92.h
r936r937
2323
2424VIDEO_START( m92 );
2525VIDEO_UPDATE( m92 );
26/*************************************************************************
27
28    Irem M92 hardware
29
30*************************************************************************/
31
32/*----------- defined in video/m92.c -----------*/
33
34extern int m92_raster_irq_position, m92_raster_enable;
35extern UINT16 *m92_vram_data, *m92_spritecontrol;
36
37extern UINT8 m92_sprite_buffer_busy, m92_game_kludge;
38
39WRITE16_HANDLER( m92_spritecontrol_w );
40WRITE16_HANDLER( m92_videocontrol_w );
41READ16_HANDLER( m92_paletteram_r );
42WRITE16_HANDLER( m92_paletteram_w );
43WRITE16_HANDLER( m92_vram_w );
44WRITE16_HANDLER( m92_pf1_control_w );
45WRITE16_HANDLER( m92_pf2_control_w );
46WRITE16_HANDLER( m92_pf3_control_w );
47WRITE16_HANDLER( m92_master_control_w );
48
49VIDEO_START( m92 );
50VIDEO_UPDATE( m92 );
src/mame/includes/amiga.h
r936r937
292292#define AMIGA_68000_NTSC_CLOCK      7159090 /* Hz */
293293#define AMIGA_68000_PAL_CLOCK      7093790 /* Hz */
294294#define AMIGA_68EC020_NTSC_CLOCK   14318180 /* Hz */
295#define CDTV_CLOCK_X1               28636363
296#define CDTV_CLOCK_X5               28375160
295#define AMIGA_68EC020_PAL_CLOCK      14187580 /* Hz */
296#define CDTV_CLOCK_X1               28636363 /* Hz */
297#define CDTV_CLOCK_X5               28375160 /* Hz */
297298
298299
299300#define ANGUS_CHIP_RAM_MASK      0x07fffe
src/mame/includes/m107.h
r936r937
1717VIDEO_START( m107 );
1818WRITE16_HANDLER( m107_control_w );
1919WRITE16_HANDLER( m107_vram_w );
20/*************************************************************************
21
22    Irem M107 hardware
23
24*************************************************************************/
25
26
27/*----------- defined in video/m107.c -----------*/
28
29extern UINT16 *m107_vram_data;
30extern UINT8 m107_spritesystem;
31extern UINT16 m107_raster_irq_position;
32
33WRITE16_HANDLER( m107_spritebuffer_w );
34VIDEO_UPDATE( m107 );
35VIDEO_UPDATE( dsoccr );
36VIDEO_START( m107 );
37WRITE16_HANDLER( m107_control_w );
38WRITE16_HANDLER( m107_vram_w );
src/mame/includes/m72.h
r936r937
3838
3939VIDEO_UPDATE( m72 );
4040VIDEO_UPDATE( majtitle );
41/*************************************************************************
42
43    Irem M72 hardware
44
45*************************************************************************/
46
47/*----------- defined in video/m72.c -----------*/
48
49extern UINT16 *m72_videoram1,*m72_videoram2,*majtitle_rowscrollram;
50
51MACHINE_RESET( m72 );
52MACHINE_RESET( xmultipl );
53MACHINE_RESET( kengo );
54
55INTERRUPT_GEN( m72_interrupt );
56
57VIDEO_START( m72 );
58VIDEO_START( rtype2 );
59VIDEO_START( majtitle );
60VIDEO_START( hharry );
61VIDEO_START( poundfor );
62
63READ16_HANDLER( m72_palette1_r );
64READ16_HANDLER( m72_palette2_r );
65WRITE16_HANDLER( m72_palette1_w );
66WRITE16_HANDLER( m72_palette2_w );
67WRITE16_HANDLER( m72_videoram1_w );
68WRITE16_HANDLER( m72_videoram2_w );
69WRITE16_HANDLER( m72_irq_line_w );
70WRITE16_HANDLER( m72_scrollx1_w );
71WRITE16_HANDLER( m72_scrollx2_w );
72WRITE16_HANDLER( m72_scrolly1_w );
73WRITE16_HANDLER( m72_scrolly2_w );
74WRITE16_HANDLER( m72_dmaon_w );
75WRITE16_HANDLER( m72_port02_w );
76WRITE16_HANDLER( rtype2_port02_w );
77WRITE16_HANDLER( majtitle_gfx_ctrl_w );
78
79VIDEO_UPDATE( m72 );
80VIDEO_UPDATE( majtitle );
src/mame/mame.mak
r936r937
163163CPUS += M37702
164164CPUS += M37710
165165CPUS += PPC403
166CPUS += PPC601
166167CPUS += PPC602
167168CPUS += PPC603
168169CPUS += MPC8240
r936r937
364365   $(MAMEOBJ)/sigma.a \
365366   $(MAMEOBJ)/snk.a \
366367   $(MAMEOBJ)/stern.a \
368   $(MAMEOBJ)/subsino.a \
367369   $(MAMEOBJ)/sun.a \
368370   $(MAMEOBJ)/suna.a \
369371   $(MAMEOBJ)/tad.a \
r936r937
476478   $(DRIVERS)/alg.o \
477479   $(MACHINE)/amiga.o $(AUDIO)/amiga.o $(VIDEO)/amiga.o \
478480   $(DRIVERS)/arcadia.o \
479   $(DRIVERS)/cubocd32.o \
481   $(DRIVERS)/cubocd32.o $(MACHINE)/cubocd32.o \
480482   $(DRIVERS)/mquake.o \
481483   $(DRIVERS)/upscope.o \
482484
r936r937
12441246   $(DRIVERS)/macs.o \
12451247   $(DRIVERS)/seta.o $(VIDEO)/seta.o \
12461248   $(DRIVERS)/seta2.o $(VIDEO)/seta2.o \
1249   $(DRIVERS)/speglsht.o \
12471250   $(DRIVERS)/speedatk.o $(VIDEO)/speedatk.o \
12481251   $(DRIVERS)/srmp2.o $(VIDEO)/srmp2.o \
12491252   $(DRIVERS)/srmp6.o \
r936r937
12781281   $(DRIVERS)/mazerbla.o \
12791282   $(DRIVERS)/supdrapo.o \
12801283
1284$(MAMEOBJ)/subsino.a: \
1285   $(DRIVERS)/bishjan.o \
1286   $(DRIVERS)/lastfght.o \
1287
12811288$(MAMEOBJ)/sun.a: \
12821289   $(DRIVERS)/arabian.o $(VIDEO)/arabian.o \
12831290   $(DRIVERS)/ikki.o $(VIDEO)/ikki.o \
r936r937
15761583   $(DRIVERS)/kyugo.o $(VIDEO)/kyugo.o \
15771584   $(DRIVERS)/ladyfrog.o $(VIDEO)/ladyfrog.o \
15781585   $(DRIVERS)/laserbas.o \
1579   $(DRIVERS)/lastfght.o \
15801586   $(DRIVERS)/lethalj.o $(VIDEO)/lethalj.o \
15811587   $(DRIVERS)/limenko.o \
15821588   $(DRIVERS)/ltcasino.o \
src/mame/video/xevious.c
r936r937
1717static tilemap *fg_tilemap,*bg_tilemap;
1818static INT32 xevious_bs[2];
1919
20static colortable *xevious_colortable;
21
2022/***************************************************************************
2123
2224  Convert the color PROMs into a more useable format.
r936r937
3638{
3739   int i;
3840   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
39   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
4041
42   xevious_colortable = colortable_alloc(machine, 128+1);
4143
4244   for (i = 0;i < 128;i++)
4345   {
4446      int bit0,bit1,bit2,bit3,r,g,b;
4547
46
4748      /* red component */
4849      bit0 = (color_prom[0] >> 0) & 0x01;
4950      bit1 = (color_prom[0] >> 1) & 0x01;
r936r937
6364      bit3 = (color_prom[2*256] >> 3) & 0x01;
6465      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
6566
66      palette_set_color(machine,i,MAKE_RGB(r,g,b));
67      colortable_palette_set_color(xevious_colortable,i,MAKE_RGB(r,g,b));
6768      color_prom++;
6869   }
6970
7071   /* color 0x80 is used by sprites to mark transparency */
71   palette_set_color(machine,0x80,MAKE_RGB(0,0,0));
72   colortable_palette_set_color(xevious_colortable,0x80,MAKE_RGB(0,0,0));
7273
7374   color_prom += 128;  /* the bottom part of the PROM is unused */
7475   color_prom += 2*256;
r936r937
7778   /* background tiles */
7879   for (i = 0;i < TOTAL_COLORS(1);i++)
7980   {
80      COLOR(1,i) = (color_prom[0] & 0x0f) | ((color_prom[TOTAL_COLORS(1)] & 0x0f) << 4);
81      colortable_entry_set_value(xevious_colortable, machine->gfx[1]->color_base + i,
82            (color_prom[0] & 0x0f) | ((color_prom[TOTAL_COLORS(1)] & 0x0f) << 4));
8183
8284      color_prom++;
8385   }
r936r937
8890   {
8991      int c = (color_prom[0] & 0x0f) | ((color_prom[TOTAL_COLORS(2)] & 0x0f) << 4);
9092
91      if (c & 0x80) COLOR(2,i) = c & 0x7f;
92      else COLOR(2,i) = 0x80; /* transparent */
93      colortable_entry_set_value(xevious_colortable, machine->gfx[2]->color_base + i,
94            (c & 0x80) ? (c & 0x7f) : 0x80);
9395
9496      color_prom++;
9597   }
r936r937
98100   /* foreground characters */
99101   for (i = 0;i < TOTAL_COLORS(0);i++)
100102   {
101      if (i % 2 == 0) COLOR(0,i) = 0x80;  /* transparent */
102      else COLOR(0,i) = i / 2;
103      colortable_entry_set_value(xevious_colortable, machine->gfx[0]->color_base + i,
104            (i % 2 != 0) ? (i / 2) : 0x80);
103105   }
104106}
105107
r936r937
108110PALETTE_INIT( battles )
109111{
110112   int i;
111   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
112   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
113113
114   xevious_colortable = colortable_alloc(machine, 128+1);
114115
115116   for (i = 0;i < 128;i++)
116117   {
117118      int bit0,bit1,bit2,bit3,r,g,b;
118119
119
120120      /* red component */
121121      bit0 = (color_prom[0] >> 0) & 0x01;
122122      bit1 = (color_prom[0] >> 1) & 0x01;
r936r937
136136      bit3 = (color_prom[2*256] >> 3) & 0x01;
137137      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
138138
139      palette_set_color(machine,i,MAKE_RGB(r,g,b));
139      colortable_palette_set_color(xevious_colortable,i,MAKE_RGB(r,g,b));
140140      color_prom++;
141141   }
142142
143143   /* color 0x80 is used by sprites to mark transparency */
144   palette_set_color(machine,0x80,MAKE_RGB(0,0,0));
144   colortable_palette_set_color(xevious_colortable,0x80,MAKE_RGB(0,0,0));
145145
146146   color_prom += 128;  /* the bottom part of the PROM is unused */
147147   color_prom += 2*256;
r936r937
150150   /* background tiles */
151151   for (i = 0;i < TOTAL_COLORS(1);i++)
152152   {
153      COLOR(1,i) = (color_prom[0] & 0x0f) | ((color_prom[0x400] & 0x0f) << 4);
153      colortable_entry_set_value(xevious_colortable, machine->gfx[1]->color_base + i,
154            (color_prom[0] & 0x0f) | ((color_prom[0x400] & 0x0f) << 4));
154155
155156      color_prom++;
156157   }
r936r937
161162   {
162163      int c = (color_prom[0] & 0x0f) | ((color_prom[0x400] & 0x0f) << 4);
163164
164      if (c & 0x80) COLOR(2,i) = c & 0x7f;
165      else COLOR(2,i) = 0x80; /* transparent */
165      colortable_entry_set_value(xevious_colortable, machine->gfx[2]->color_base + i,
166            (c & 0x80) ? (c & 0x7f) : 0x80);
166167
167168      color_prom++;
168169   }
r936r937
170171   /* foreground characters */
171172   for (i = 0;i < TOTAL_COLORS(0);i++)
172173   {
173      if (i % 2 == 0) COLOR(0,i) = 0x80;  /* transparent */
174      else COLOR(0,i) = i / 2;
174      colortable_entry_set_value(xevious_colortable, machine->gfx[0]->color_base + i,
175            (i % 2 != 0) ? (i / 2) : 0x80);
175176   }
176177}
177178
r936r937
192193       timing signals, while x flip is done by selecting the 2nd character set.
193194       We reproduce this here, but since the tilemap system automatically flips
194195       characters when screen is flipped, we have to flip them back. */
196   UINT8 color = ((attr & 0x03) << 4) | ((attr & 0x3c) >> 2);
195197   SET_TILE_INFO(
196198         0,
197199         xevious_fg_videoram[tile_index] | (flip_screen ? 0x100 : 0),
198         ((attr & 0x03) << 4) | ((attr & 0x3c) >> 2),
200         color,
199201         TILE_FLIPYX((attr & 0xc0) >> 6) ^ (flip_screen ? TILE_FLIPX : 0));
200202}
201203
r936r937
203205{
204206   UINT8 code = xevious_bg_videoram[tile_index];
205207   UINT8 attr = xevious_bg_colorram[tile_index];
208   UINT8 color = ((attr & 0x3c) >> 2) | ((code & 0x80) >> 3) | ((attr & 0x03) << 5);
206209   SET_TILE_INFO(
207210         1,
208211         code + ((attr & 0x01) << 8),
209         ((attr & 0x3c) >> 2) | ((code & 0x80) >> 3) | ((attr & 0x03) << 5),
212         color,
210213         TILE_FLIPYX((attr & 0xc0) >> 6));
211214}
212215
r936r937
433436      if ((spriteram[offs + 1] & 0x40) == 0)  /* I'm not sure about this one */
434437      {
435438         int bank,code,color,flipx,flipy;
439         UINT32 transmask;
436440
437
438441         if (spriteram_3[offs] & 0x80)
439442         {
440443            bank = 2;
r936r937
456459         }
457460         sx = spriteram_2[offs + 1] - 40 + 0x100*(spriteram_3[offs + 1] & 1);
458461         sy = 28*8-spriteram_2[offs]-1;
462
463         transmask = colortable_get_transpen_mask(xevious_colortable, machine->gfx[bank], color, 0x80);
464
459465         if (spriteram_3[offs] & 2)  /* double height (?) */
460466         {
461467            if (spriteram_3[offs] & 1)  /* double width, double height */
r936r937
464470               drawgfx(bitmap,machine->gfx[bank],
465471                     code+3,color,flipx,flipy,
466472                     flipx ? sx : sx+16,flipy ? sy-16 : sy,
467                     cliprect,TRANSPARENCY_COLOR,0x80);
473                     cliprect,TRANSPARENCY_PENS,transmask);
468474               drawgfx(bitmap,machine->gfx[bank],
469475                     code+1,color,flipx,flipy,
470476                     flipx ? sx : sx+16,flipy ? sy : sy-16,
471                     cliprect,TRANSPARENCY_COLOR,0x80);
477                     cliprect,TRANSPARENCY_PENS,transmask);
472478            }
473479            code &= ~2;
474480            drawgfx(bitmap,machine->gfx[bank],
475481                  code+2,color,flipx,flipy,
476482                  flipx ? sx+16 : sx,flipy ? sy-16 : sy,
477                  cliprect,TRANSPARENCY_COLOR,0x80);
483                  cliprect,TRANSPARENCY_PENS,transmask);
478484            drawgfx(bitmap,machine->gfx[bank],
479485                  code,color,flipx,flipy,
480486                  flipx ? sx+16 : sx,flipy ? sy : sy-16,
481                  cliprect,TRANSPARENCY_COLOR,0x80);
487                  cliprect,TRANSPARENCY_PENS,transmask);
482488         }
483489         else if (spriteram_3[offs] & 1) /* double width */
484490         {
r936r937
486492            drawgfx(bitmap,machine->gfx[bank],
487493                  code,color,flipx,flipy,
488494                  flipx ? sx+16 : sx,flipy ? sy-16 : sy,
489                  cliprect,TRANSPARENCY_COLOR,0x80);
495                  cliprect,TRANSPARENCY_PENS,transmask);
490496            drawgfx(bitmap,machine->gfx[bank],
491497                  code+1,color,flipx,flipy,
492498                  flipx ? sx : sx+16,flipy ? sy-16 : sy,
493                  cliprect,TRANSPARENCY_COLOR,0x80);
499                  cliprect,TRANSPARENCY_PENS,transmask);
494500         }
495501         else   /* normal */
496502         {
497503            drawgfx(bitmap,machine->gfx[bank],
498504                  code,color,flipx,flipy,sx,sy,
499                  cliprect,TRANSPARENCY_COLOR,0x80);
505                  cliprect,TRANSPARENCY_PENS,transmask);
500506         }
501507      }
502508   }
src/mame/video/deco_mlc.c
r936r937
9595   }
9696
9797   {
98      if( gfx && gfx->colortable )
98      if( gfx )
9999      {
100         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
100         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
101101         int source_base1 = (code1 % gfx->total_elements) * gfx->height;
102102         int source_base2 = (code2 % gfx->total_elements) * gfx->height;
103103
src/mame/video/rungun.c
r936r937
101101   decodegfx(machine->gfx[ttl_gfx_index], memory_region(REGION_GFX3), 0, machine->gfx[ttl_gfx_index]->total_elements);
102102
103103   if (machine->drv->color_table_len)
104   {
105           machine->gfx[ttl_gfx_index]->colortable = machine->remapped_colortable;
106104           machine->gfx[ttl_gfx_index]->total_colors = machine->drv->color_table_len / 16;
107   }
108105   else
109   {
110           machine->gfx[ttl_gfx_index]->colortable = machine->pens;
111106           machine->gfx[ttl_gfx_index]->total_colors = machine->drv->total_colors / 16;
112   }
113107
114108   // create the tilemap
115109   ttl_tilemap = tilemap_create(ttl_get_tile_info, tilemap_scan_rows, TILEMAP_TYPE_PEN, 8, 8, 64, 32);
src/mame/video/docastle.c
r936r937
1111#include "driver.h"
1212#include "includes/docastle.h"
1313
14static tilemap *bg_tilemap, *fg_tilemap;
14static tilemap *docastle_tilemap;
1515
1616/***************************************************************************
1717
r936r937
3030  bit 0 -- 390 ohm resistor  -- BLUE
3131
3232***************************************************************************/
33static void convert_color_prom(running_machine *machine,UINT16 *colortable,const UINT8 *color_prom,
34      int priority)
33PALETTE_INIT( docastle )
3534{
36   int i,j;
35   int i;
3736
38
3937   for (i = 0;i < 256;i++)
4038   {
4139      int bit0,bit1,bit2,r,g,b;
4240
43
4441      /* red component */
4542      bit0 = (*color_prom >> 5) & 0x01;
4643      bit1 = (*color_prom >> 6) & 0x01;
r936r937
5754      bit2 = (*color_prom >> 1) & 0x01;
5855      b = 0x23 * bit0 + 0x4b * bit1 + 0x91 * bit2;
5956
60      palette_set_color(machine,i,MAKE_RGB(r,g,b));
57      /* because the graphics are decoded as 4bpp with the top bit used for transparency
58           or priority, we create matching 3bpp sets of palette entries, which effectively
59           ignores the value of the top bit */
60      palette_set_color(machine, ((i & 0xf8) << 1) | 0x00 | (i & 0x07), MAKE_RGB(r,g,b));
61      palette_set_color(machine, ((i & 0xf8) << 1) | 0x08 | (i & 0x07), MAKE_RGB(r,g,b));
6162      color_prom++;
6263   }
63
64   /* reserve one color for the transparent pen (none of the game colors can have */
65   /* these RGB components) */
66   palette_set_color(machine,256,MAKE_RGB(1,1,1));
67   /* and the last color for the sprite covering pen */
68   palette_set_color(machine,257,MAKE_RGB(2,2,2));
69
70
71   /* characters */
72   /* characters have 4 bitplanes, but they actually have only 8 colors. The fourth */
73   /* plane is used to select priority over sprites. The meaning of the high bit is */
74   /* reversed in Do's Castle wrt the other games. */
75
76   /* first create a table with all colors, used to draw the background */
77   for (i = 0;i < 32;i++)
78   {
79      for (j = 0;j < 8;j++)
80      {
81         colortable[16*i+j] = 8*i+j;
82         colortable[16*i+j+8] = 8*i+j;
83      }
84   }
85   /* now create a table with only the colors which have priority over sprites, used */
86   /* to draw the foreground. */
87   for (i = 0;i < 32;i++)
88   {
89      for (j = 0;j < 8;j++)
90      {
91         if (priority == 0)   /* Do's Castle */
92         {
93            colortable[32*16+16*i+j] = 256;   /* high bit clear means less priority than sprites */
94            colortable[32*16+16*i+j+8] = 8*i+j;
95         }
96         else   /* Do Wild Ride, Do Run Run, Kick Rider */
97         {
98            colortable[32*16+16*i+j] = 8*i+j;
99            colortable[32*16+16*i+j+8] = 256;   /* high bit set means less priority than sprites */
100         }
101      }
102   }
103
104   /* sprites */
105   /* sprites have 4 bitplanes, but they actually have only 8 colors. The fourth */
106   /* plane is used for transparency. */
107   for (i = 0;i < 32;i++)
108   {
109      /* build two versions of the colortable, one with the covering color
110           mapped to transparent, and one with all colors but the covering one
111           mapped to transparent. */
112      for (j = 0;j < 16;j++)
113      {
114         if (j < 8)
115            colortable[64*16+16*i+j] = 256;   /* high bit clear means transparent */
116         else if (j == 15)
117            colortable[64*16+16*i+j] = 256;   /* sprite covering color */
118         else
119            colortable[64*16+16*i+j] = 8*i+(j&7);
120      }
121      for (j = 0;j < 16;j++)
122      {
123         if (j == 15)
124            colortable[64*16+32*16+16*i+j] = 257;   /* sprite covering color */
125         else
126            colortable[64*16+32*16+16*i+j] = 256;
127      }
128   }
12964}
13065
131PALETTE_INIT( docastle )
132{
133   convert_color_prom(machine,colortable,color_prom,0);
134}
135
136PALETTE_INIT( dorunrun )
137{
138   convert_color_prom(machine,colortable,color_prom,1);
139}
140
14166WRITE8_HANDLER( docastle_videoram_w )
14267{
14368   videoram[offset] = data;
144   tilemap_mark_tile_dirty(bg_tilemap, offset);
145   tilemap_mark_tile_dirty(fg_tilemap, offset);
69   tilemap_mark_tile_dirty(docastle_tilemap, offset);
14670}
14771
14872WRITE8_HANDLER( docastle_colorram_w )
14973{
15074   colorram[offset] = data;
151   tilemap_mark_tile_dirty(bg_tilemap, offset);
152   tilemap_mark_tile_dirty(fg_tilemap, offset);
75   tilemap_mark_tile_dirty(docastle_tilemap, offset);
15376}
15477
15578READ8_HANDLER( docastle_flipscreen_off_r )
15679{
15780   flip_screen_set(0);
158   tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
81   tilemap_mark_all_tiles_dirty(docastle_tilemap);
15982   return 0;
16083}
16184
16285READ8_HANDLER( docastle_flipscreen_on_r )
16386{
16487   flip_screen_set(1);
165   tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
88   tilemap_mark_all_tiles_dirty(docastle_tilemap);
16689   return 1;
16790}
16891
16992WRITE8_HANDLER( docastle_flipscreen_off_w )
17093{
17194   flip_screen_set(0);
172   tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
95   tilemap_mark_all_tiles_dirty(docastle_tilemap);
17396}
17497
17598WRITE8_HANDLER( docastle_flipscreen_on_w )
17699{
177100   flip_screen_set(1);
178   tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
101   tilemap_mark_all_tiles_dirty(docastle_tilemap);
179102}
180103
181static TILE_GET_INFO( get_bg_tile_info )
104static TILE_GET_INFO( get_tile_info )
182105{
183106   int code = videoram[tile_index] + 8 * (colorram[tile_index] & 0x20);
184107   int color = colorram[tile_index] & 0x1f;
r936r937
186109   SET_TILE_INFO(0, code, color, 0);
187110}
188111
189static TILE_GET_INFO( get_fg_tile_info )
112static void video_start_common(running_machine *machine, UINT32 tile_transmask)
190113{
191   int code = videoram[tile_index] + 8 * (colorram[tile_index] & 0x20);
192   int color = (colorram[tile_index] & 0x1f) + 32;
193
194   SET_TILE_INFO(0, code, color, 0);
114   docastle_tilemap = tilemap_create(get_tile_info, tilemap_scan_rows, TILEMAP_TYPE_PEN, 8, 8, 32, 32);
115   tilemap_set_transmask(docastle_tilemap, 0, tile_transmask, 0x0000);
195116}
196117
197118VIDEO_START( docastle )
198119{
199   bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
200      TILEMAP_TYPE_PEN, 8, 8, 32, 32);
120   video_start_common(machine, 0x00ff);
121}
201122
202   fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_rows,
203      TILEMAP_TYPE_COLORTABLE, 8, 8, 32, 32);
204
205   tilemap_set_transparent_pen(fg_tilemap, 256);
123VIDEO_START( dorunrun )
124{
125   video_start_common(machine, 0xff00);
206126}
207127
208128static void draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect)
r936r937
282202            color,
283203            flipx,flipy,
284204            sx,sy,
285            cliprect,TRANSPARENCY_COLOR,256,
205            cliprect,TRANSPARENCY_PENS,0x80ff,
286206            0x00);
287207
288208      /* then draw the mask, behind the background but obscuring following sprites */
289209      pdrawgfx(bitmap,machine->gfx[1],
290210            code,
291            color + 32,
211            color,
292212            flipx,flipy,
293213            sx,sy,
294            cliprect,TRANSPARENCY_COLOR,256,
214            cliprect,TRANSPARENCY_PENS,0x7fff,
295215            0x02);
296216   }
297217}
298218
299219VIDEO_UPDATE( docastle )
300220{
301   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
221   tilemap_draw(bitmap, cliprect, docastle_tilemap, TILEMAP_DRAW_OPAQUE, 0);
302222   draw_sprites(machine, bitmap, cliprect);
303   tilemap_draw(bitmap, cliprect, fg_tilemap, 0, 0);
223   tilemap_draw(bitmap, cliprect, docastle_tilemap, TILEMAP_DRAW_LAYER0, 0);
304224   return 0;
305225}
src/mame/video/arabian.c
r936r937
370370
371371VIDEO_UPDATE( arabian )
372372{
373   pen_t *colortable = &machine->remapped_colortable[(arabian_video_control >> 3) << 8];
373   const pen_t *colortable = &machine->remapped_colortable[(arabian_video_control >> 3) << 8];
374374   int y;
375375
376376   /* render the screen from the bitmap */
src/mame/video/seibuspi.c
r936r937
329329            UINT8 alpha = alpha_table[global_pen];
330330            if (alpha)
331331            {
332               p[i] = alpha_blend16(p[i], gfx->colortable[global_pen]);
332               p[i] = alpha_blend16(p[i], Machine->remapped_colortable[gfx->color_base + global_pen]);
333333            }
334334            else
335335            {
336               p[i] = gfx->colortable[global_pen];
336               p[i] = Machine->remapped_colortable[gfx->color_base + global_pen];
337337            }
338338         }
339339         dp_i += xd;
src/mame/video/gaplus.c
r936r937
1313UINT8 *gaplus_spriteram;
1414
1515static tilemap *bg_tilemap;
16static colortable *gaplus_colortable;
1617
1718
1819/***************************************************************************
r936r937
3132PALETTE_INIT( gaplus )
3233{
3334   int i;
34   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
35   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
3635
36   /* allocate the colortable */
37   gaplus_colortable = colortable_alloc(machine, 256);
3738
38   for (i = 0;i < machine->drv->total_colors;i++)
39   for (i = 0;i < 256;i++)
3940   {
4041      int bit0,bit1,bit2,bit3,r,g,b;
4142
42
4343      /* red component */
4444      bit0 = (color_prom[i] >> 0) & 0x01;
4545      bit1 = (color_prom[i] >> 1) & 0x01;
r936r937
5959      bit3 = (color_prom[i + 0x200] >> 3) & 0x01;
6060      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
6161
62      palette_set_color(machine,i,MAKE_RGB(r,g,b));
62      colortable_palette_set_color(gaplus_colortable,i,MAKE_RGB(r,g,b));
6363   }
6464
6565   color_prom += 0x300;
6666   /* color_prom now points to the beginning of the lookup table */
6767
68
6968   /* characters use colors 0xf0-0xff */
70   for (i = 0;i < TOTAL_COLORS(0);i++)
71      COLOR(0,i) = 0xf0 + (*(color_prom++) & 0x0f);
69   for (i = 0;i < machine->gfx[0]->total_colors * machine->gfx[0]->color_granularity;i++)
70      colortable_entry_set_value(gaplus_colortable, machine->gfx[0]->color_base + i, 0xf0 + (*color_prom++ & 0x0f));
7271
7372   /* sprites */
74   for (i = 0;i < TOTAL_COLORS(1);i++)
73   for (i = 0;i < machine->gfx[1]->total_colors * machine->gfx[1]->color_granularity;i++)
7574   {
76      COLOR(1,i) = (color_prom[0] & 0x0f) + ((color_prom[0x200] & 0x0f) << 4);
75      colortable_entry_set_value(gaplus_colortable, machine->gfx[1]->color_base + i, (color_prom[0] & 0x0f) + ((color_prom[0x200] & 0x0f) << 4));
7776      color_prom++;
7877   }
7978}
r936r937
105104{
106105   UINT8 attr = gaplus_videoram[tile_index + 0x400];
107106   tileinfo->category = (attr & 0x40) >> 6;
107   tileinfo->group = attr & 0x3f;
108108   SET_TILE_INFO(
109109         0,
110110         gaplus_videoram[tile_index] + ((attr & 0x80) << 1),
r936r937
196196
197197VIDEO_START( gaplus )
198198{
199   bg_tilemap = tilemap_create(get_tile_info,tilemap_scan,TILEMAP_TYPE_COLORTABLE,8,8,36,28);
199   bg_tilemap = tilemap_create(get_tile_info,tilemap_scan,TILEMAP_TYPE_PEN,8,8,36,28);
200200
201   tilemap_set_transparent_pen(bg_tilemap, 0xff);
201   colortable_configure_tilemap_groups(gaplus_colortable, bg_tilemap, machine->gfx[0], 0xff);
202202
203203   spriteram = gaplus_spriteram + 0x780;
204204   spriteram_2 = spriteram + 0x800;
r936r937
310310                  color,
311311                  flipx,flipy,
312312                  sx + 16*x,sy + 16*y,
313                  cliprect,TRANSPARENCY_COLOR,0xff);
313                  cliprect,TRANSPARENCY_PENS,
314                  colortable_get_transpen_mask(gaplus_colortable, machine->gfx[1], color, 0xff));
314315            }
315316         }
316317      }
src/mame/video/system1.c
r936r937
254254{
255255   int sy,row,height,src,bank;
256256   UINT8 *sprite_base;
257   pen_t *sprite_palette;
257   const pen_t *sprite_palette;
258258   INT16 skip;   /* bytes to skip before drawing each row (can be negative) */
259259   UINT8 *gfx;
260260
src/mame/video/stvvdp2.c
r936r937
24092409      clip=&myclip;
24102410   }
24112411
2412   if( gfx && gfx->colortable )
2412   if( gfx )
24132413   {
2414      const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2414      const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
24152415      UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
24162416
24172417      //int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
r936r937
24852485            /* case 0: TRANSPARENCY_NONE */
24862486            if (transparency == TRANSPARENCY_NONE)
24872487            {
2488               if (gfx->flags & GFX_PACKED)
2488               if (gfx->flags & GFX_ELEMENT_PACKED)
24892489               {
24902490                  for( y=sy; y<ey; y++ )
24912491                  {
r936r937
25242524            /* case 1: TRANSPARENCY_PEN */
25252525            if (transparency == TRANSPARENCY_PEN)
25262526            {
2527               if (gfx->flags & GFX_PACKED)
2527               if (gfx->flags & GFX_ELEMENT_PACKED)
25282528               {
25292529                  for( y=sy; y<ey; y++ )
25302530                  {
r936r937
25852585            /* case : STV_TRANSPARENCY_ADD_BLEND */
25862586            if (transparency == STV_TRANSPARENCY_ADD_BLEND )
25872587            {
2588               if (gfx->flags & GFX_PACKED)
2588               if (gfx->flags & GFX_ELEMENT_PACKED)
25892589               {
25902590                  for( y=sy; y<ey; y++ )
25912591                  {
src/mame/video/balsente.c
r936r937
155155   {
156156      if (ypos >= (16 + BALSENTE_VBEND) && ypos >= cliprect->min_y && ypos <= cliprect->max_y)
157157      {
158         UINT32 *pens = &machine->pens[palettebank_vis * 256];
158         const pen_t *pens = &machine->pens[palettebank_vis * 256];
159159         UINT8 *old = &local_videoram[(ypos - BALSENTE_VBEND) * 256 + xpos];
160160         int currx = xpos;
161161
r936r937
222222
223223VIDEO_UPDATE( balsente )
224224{
225   pen_t *pens = &machine->pens[palettebank_vis * 256];
225   const pen_t *pens = &machine->pens[palettebank_vis * 256];
226226   int y, i;
227227
228228   /* draw scanlines from the VRAM directly */
src/mame/video/deco32.c
r936r937
487487   }
488488
489489   {
490      if( gfx && gfx->colortable )
490      if( gfx )
491491      {
492         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
492         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
493493         int source_base = (code % gfx->total_elements) * gfx->height;
494494
495495         if (sprite_screen_width && sprite_screen_height)
r936r937
14131413*/
14141414static void mixDualAlphaSprites(running_machine* machine, mame_bitmap *bitmap, const rectangle *cliprect, const gfx_element *gfx0, const gfx_element *gfx1, int mixAlphaTilemap)
14151415{
1416   const pen_t *pal0 = gfx0->colortable;
1417   const pen_t *pal1 = gfx1->colortable;
1418   const pen_t *pal2 = (deco32_pri&1) ? machine->gfx[1]->colortable : machine->gfx[2]->colortable;
1416   const pen_t *pal0 = &machine->remapped_colortable[gfx0->color_base];
1417   const pen_t *pal1 = &machine->remapped_colortable[gfx1->color_base];
1418   const pen_t *pal2 = &machine->remapped_colortable[(deco32_pri&1) ? machine->gfx[1]->color_base : machine->gfx[2]->color_base];
14191419   int x,y;
14201420
14211421   /* Mix sprites into main bitmap, based on priority & alpha */
src/mame/video/gaiden.c
r936r937
240240   if (sy > ey) return;
241241
242242   {
243      pen_t *paldata = machine->pens;
243      const pen_t *paldata = machine->pens;
244244      UINT32 *end;
245245
246246      UINT16 *sd1 = src1->base;                                    /* source data   */
src/mame/video/namcona1.c
r936r937
238238
239239      gfx0 = allocgfx( &cg_layout );
240240      gfx1 = allocgfx( &shape_layout );
241         gfx0->colortable = machine->remapped_colortable;
242241         gfx0->total_colors = machine->drv->total_colors/256;
243242         machine->gfx[0] = gfx0;
244243
245         gfx1->colortable = machine->remapped_colortable;
246244         gfx1->total_colors = machine->drv->total_colors/2;
247245         machine->gfx[1] = gfx1;
248246} /* namcona1_vh_start */
r936r937
279277      mask = machine->gfx[1];
280278      code %= gfx->total_elements;
281279      color %= gfx->total_colors;
282      paldata = &gfx->colortable[gfx->color_granularity * color];
280      paldata = &machine->remapped_colortable[gfx->color_base + gfx->color_granularity * color];
283281      gfx_addr = gfx->gfxdata + code * gfx->char_modulo;
284282      gfx_pitch = gfx->line_modulo;
285283      mask_addr = mask->gfxdata + code * mask->char_modulo;
r936r937
403401      gfx = machine->gfx[0];
404402      code %= gfx->total_elements;
405403      color %= gfx->total_colors;
406      paldata = &gfx->colortable[gfx->color_granularity * color];
404      paldata = &machine->remapped_colortable[gfx->color_base + gfx->color_granularity * color];
407405      gfx_addr = gfx->gfxdata + code * gfx->char_modulo;
408406      gfx_pitch = gfx->line_modulo;
409407
r936r937
558556   gfx_element *pGfx;
559557
560558   pGfx = machine->gfx[0];
561   paldata = &pGfx->colortable[pGfx->color_granularity * tilemap_palette_bank[which]];
559   paldata = &machine->remapped_colortable[pGfx->color_base + pGfx->color_granularity * tilemap_palette_bank[which]];
562560
563561   /* draw one scanline at a time */
564562   clip.min_x = cliprect->min_x;
src/mame/video/dkong.c
r936r937
236236         palette_set_color_rgb(machine,i,r,g,b);
237237      }
238238
239   palette_normalize_range(machine, 0, 255, 0, 255);
239   palette_normalize_range(machine->palette, 0, 255, 0, 255);
240240
241241   color_prom += 512;
242242   /* color_prom now points to the beginning of the character color codes */
r936r937
299299
300300      palette_set_color_rgb(machine,RADARSCP_GRID_COL_OFFSET + i,r,g,b);
301301   }
302   palette_normalize_range(machine, 0, RADARSCP_GRID_COL_OFFSET+7, 0, 255);
302   palette_normalize_range(machine->palette, 0, RADARSCP_GRID_COL_OFFSET+7, 0, 255);
303303
304304
305305
r936r937
364364
365365      palette_set_color_rgb(machine,RADARSCP_GRID_COL_OFFSET + i,r,g,b);
366366   }
367   palette_normalize_range(machine, 0, RADARSCP_GRID_COL_OFFSET+7, 0, 255);
367   palette_normalize_range(machine->palette, 0, RADARSCP_GRID_COL_OFFSET+7, 0, 255);
368368
369369   color_prom += 512;
370370   /* color_prom now points to the beginning of the character color codes */
r936r937
414414
415415   rgb = compute_res_net_all(color_prom, &dkong3_decode_info, &dkong3_net_info);
416416   palette_set_colors(machine, 0, rgb, 256);
417   palette_normalize_range(machine, 0, 255, 0, 255);
417   palette_normalize_range(machine->palette, 0, 255, 0, 255);
418418   free(rgb);
419419
420420   color_prom += 1024;
src/mame/video/sprint4.c
r936r937
9494
9595VIDEO_EOF( sprint4 )
9696{
97   UINT16 BG = machine->gfx[0]->colortable[0];
97   UINT16 BG = machine->remapped_colortable[machine->gfx[0]->color_base];
9898
9999   int i;
100100
src/mame/video/kaneko16.c
r936r937
395395      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
396396      const rectangle *clip,int priority)
397397{
398   const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
398   const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
399399   UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
400400
401401   int sprite_screen_height = ((1<<16)*gfx->height+0x8000)>>16;
src/mame/video/20pacgal.c
r936r937
5959
6060WRITE8_HANDLER( pacgal_lookup_w )
6161{
62   Machine->game_colortable[offset] = data & 0x0f;
63   Machine->remapped_colortable[offset] = Machine->pens[data & 0x0f];
62   /* palette hacks! */
63   ((UINT16 *)Machine->game_colortable)[offset] = data & 0x0f;
64   ((pen_t *)Machine->remapped_colortable)[offset] = Machine->pens[data & 0x0f];
6465}
6566
6667WRITE8_HANDLER( pacgal_active_game_w )
src/mame/video/spbactn.c
r936r937
3535   if (sy > ey) return;
3636
3737   {
38      pen_t *paldata = machine->pens;
38      const pen_t *paldata = machine->pens;
3939      UINT32 *end;
4040
4141      UINT16 *sd1 = src1->base;                                    /* source data   */
src/mame/video/system16.c
r936r937
208208   int shadow,
209209   int shadow_pen, int eos )
210210{
211   const pen_t *shadow_base = machine->gfx[0]->colortable + (machine->drv->total_colors/2);
211   const pen_t *shadow_base = machine->remapped_colortable + machine->gfx[0]->color_base + (machine->drv->total_colors/2);
212212   const UINT8 *source;
213213   int full_shadow=shadow&SYS16_SPR_SHADOW;
214214   int partial_shadow=shadow&SYS16_SPR_PARTIAL_SHADOW;
r936r937
339339
340340static void draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int b3d ) //*
341341{
342   const pen_t *base_pal = machine->gfx[0]->colortable;
342   const pen_t *base_pal = machine->remapped_colortable + machine->gfx[0]->color_base;
343343   const UINT8 *base_gfx = memory_region(REGION_GFX2);
344344   const int gfx_rom_size = memory_region_length(REGION_GFX2);
345345   const UINT16 *source = sys16_spriteram;
src/mame/video/atarimo.c
r936r937
239239   mo->gfxelement[idx] = *machine->gfx[idx];
240240   mo->gfxgranularity[idx] = mo->gfxelement[idx].color_granularity;
241241   mo->gfxelement[idx].color_granularity = 1;
242   mo->gfxelement[idx].colortable = machine->remapped_colortable;
242   mo->gfxelement[idx].color_base = 0;
243243   mo->gfxelement[idx].total_colors = 65536;
244244}
245245
src/mame/video/polepos.c
r936r937
1515
1616static UINT16 road16_vscroll;
1717
18static colortable *polepos_colortable;
1819static tilemap *bg_tilemap,*tx_tilemap;
1920static int polepos_chacl;
2021
r936r937
3940{
4041   int i, j;
4142
43   /* allocate the colortable */
44   polepos_colortable = colortable_alloc(machine, 128);
45
4246   /*******************************************************
4347     * Color PROMs
4448     * Sheet 15B: middle, 136014-137,138,139
r936r937
8387      bit3 = (color_prom[0x200 + i] >> 3) & 1;
8488      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
8589
86      palette_set_color(machine,i,MAKE_RGB(r,g,b));
90      colortable_palette_set_color(polepos_colortable,i,MAKE_RGB(r,g,b));
8791   }
8892
8993   /*******************************************************
r936r937
9498   for (i = 0; i < 64*4; i++)
9599   {
96100      int color = color_prom[0x300 + i];
97      colortable[0x0000 + i] = (color != 15) ? (0x020 + color) : 0x2f;
98      colortable[0x0100 + i] = (color != 15) ? (0x060 + color) : 0x2f;
101      colortable_entry_set_value(polepos_colortable, 0x0000 + i, (color != 15) ? (0x020 + color) : 0x2f);
102      colortable_entry_set_value(polepos_colortable, 0x0100 + i, (color != 15) ? (0x060 + color) : 0x2f);
99103   }
100104
101105   /*******************************************************
r936r937
107111   for (i = 0; i < 64*4; i++)
108112   {
109113      int color = color_prom[0x400 + i];
110      colortable[0x0200 + i] = 0x000 + color;
114      colortable_entry_set_value(polepos_colortable, 0x0200 + i, 0x000 + color);
111115   }
112116
113117   /*******************************************************
r936r937
118122   for (i = 0; i < 64*16; i++)
119123   {
120124      int color = color_prom[0xc00 + i];
121      colortable[0x0300 + i] = (color != 15) ? (0x010 + color) : 0x1f;
122      colortable[0x0700 + i] = (color != 15) ? (0x050 + color) : 0x1f;
125      colortable_entry_set_value(polepos_colortable, 0x0300 + i, (color != 15) ? (0x010 + color) : 0x1f);
126      colortable_entry_set_value(polepos_colortable, 0x0700 + i, (color != 15) ? (0x050 + color) : 0x1f);
123127   }
124128
125129   /*******************************************************
r936r937
131135   for (i = 0; i < 64*16; i++)
132136   {
133137      int color = color_prom[0x800 + i];
134      colortable[0x0b00 + i] = 0x040 + color;
138      colortable_entry_set_value(polepos_colortable, 0x0b00 + i, 0x040 + color);
135139   }
136140
137141   /* 136014-142, 136014-143, 136014-144 Vertical position modifiers */
r936r937
185189         code,
186190         color,
187191         0);
192   tileinfo->group = color;
188193}
189194
190195
r936r937
198203VIDEO_START( polepos )
199204{
200205   bg_tilemap = tilemap_create(bg_get_tile_info,tilemap_scan_cols,TILEMAP_TYPE_PEN,8,8,64,16);
201   tx_tilemap = tilemap_create(tx_get_tile_info,tilemap_scan_rows,TILEMAP_TYPE_COLORTABLE,8,8,32,32);
206   tx_tilemap = tilemap_create(tx_get_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,32,32);
202207
203   tilemap_set_transparent_pen(tx_tilemap, 0x2f);
208   colortable_configure_tilemap_groups(polepos_colortable, tx_tilemap, machine->gfx[0], 0x2f);
204209}
205210
206211
r936r937
354359   const UINT8 *road_bits2 = memory_region(REGION_GFX5) + 0x4000;
355360   int x, y, i;
356361
357
358362   /* loop over the lower half of the screen */
359363   for (y = 128; y < 256; y++)
360364   {
361365      int xoffs, yoffs, xscroll, roadpal;
362366      UINT8 scanline[256 + 8];
363367      UINT8 *dest = scanline;
364      pen_t *colortable;
368      const pen_t *colortable;
365369
366370      /* first add the vertical position modifier and the vertical scroll */
367371      yoffs = ((polepos_vertical_position_modifier[y] + road16_vscroll) >> 3) & 0x1ff;
r936r937
370374      roadpal = polepos_road16_memory[yoffs] & 15;
371375
372376      /* this becomes the palette base for the scanline */
373      colortable = &machine->remapped_colortable[0x0b00 + (roadpal << 6)];
377      colortable = &machine->pens[0x0b00 + (roadpal << 6)];
374378
375379      /* now fetch the horizontal scroll offset for this scanline */
376380      xoffs = polepos_road16_memory[0x380 + (y & 0x7f)] & 0x3ff;
r936r937
430434   const gfx_element *gfx = machine->gfx[big ? 3 : 2];
431435   UINT8 *gfxdata = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
432436   UINT8 *scaling_rom = memory_region(REGION_GFX6);
433   pen_t *colortable = gfx->colortable + color * gfx->color_granularity;
437   UINT32 transmask = colortable_get_transpen_mask(polepos_colortable, gfx, color, 0x1f);
438   int coloroffs = gfx->color_base + color * gfx->color_granularity;
434439   int x,y;
435440
436441   if (flipx) flipx = big ? 0x1f : 0x0f;
r936r937
455460         {
456461            if (xx < 0x100)
457462            {
458               int pen = colortable[src[offs/2 ^ flipx]];
463               int pen = src[offs/2 ^ flipx];
459464
460               if (pen != 0x1f)
461                  *BITMAP_ADDR16(bitmap, yy, xx) = pen;
465               if (!((transmask >> pen) & 1))
466                  *BITMAP_ADDR16(bitmap, yy, xx) = pen + coloroffs;
462467            }
463468            offs++;
464469
src/mame/video/taitoic.c
r936r937
15721572      machine->gfx[gfx_index] = allocgfx(&TC0080VCO_charlayout);
15731573
15741574      /* set the color information */
1575      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
15761575      machine->gfx[gfx_index]->total_colors = 64;   // is this correct ?
15771576      TC0080VCO_tx_gfx = gfx_index;
15781577
r936r937
23372336      machine->gfx[gfx_index] = allocgfx(&TC0100SCN_charlayout);
23382337
23392338      /* set the color information */
2340      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
23412339      machine->gfx[gfx_index]->total_colors = 64;
23422340
23432341      TC0100SCN_tx_gfx[i] = gfx_index;
r936r937
32043202      machine->gfx[gfx_index] = allocgfx(&TC0480SCP_charlayout);
32053203
32063204      /* set the color information */
3207      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
32083205      machine->gfx[gfx_index]->total_colors = 64;
32093206
32103207      TC0480SCP_tx_gfx = gfx_index;
src/mame/video/namcos86.c
r936r937
365365
366366   fillbitmap(priority_bitmap, 0, cliprect);
367367
368   fillbitmap(bitmap,machine->gfx[0]->colortable[8*backcolor+7],cliprect);
368   fillbitmap(bitmap,machine->remapped_colortable[machine->gfx[0]->color_base + 8*backcolor+7],cliprect);
369369
370370   for (layer = 0;layer < 8;layer++)
371371   {
src/mame/video/bbusters.c
r936r937
148148
149149static void bbusters_draw_block(running_machine *machine, mame_bitmap *dest,int x,int y,int size,int flipx,int flipy,UINT32 sprite,int color,int bank,int block)
150150{
151   const pen_t *pal = &machine->gfx[bank]->colortable[machine->gfx[bank]->color_granularity * (color % machine->gfx[bank]->total_colors)];
151   const pen_t *pal = &machine->remapped_colortable[machine->gfx[bank]->color_base + machine->gfx[bank]->color_granularity * (color % machine->gfx[bank]->total_colors)];
152152   UINT32 xinc=(scale_line_count * 0x10000 ) / size;
153153   UINT8 pixel;
154154   int x_index;
src/mame/video/hyprduel.c
r936r937
471471            gfx.width = width;
472472            gfx.height = height;
473473            gfx.total_elements = 1;
474            gfx.color_depth = 256;
474475            gfx.color_granularity = 256;
475            gfx.colortable = machine->remapped_colortable;
476            gfx.color_base = 0;
476477            gfx.total_colors = 0x20;
477478            gfx.pen_usage = NULL;
478479            gfx.gfxdata = gfxdata;
r936r937
500501            gfx.width = width;
501502            gfx.height = height;
502503            gfx.total_elements = 1;
504            gfx.color_depth = 16;
503505            gfx.color_granularity = 16;
504            gfx.colortable = Machine->remapped_colortable;
506            gfx.color_base = 0;
505507            gfx.total_colors = 0x200;
506508            gfx.pen_usage = NULL;
507509            gfx.gfxdata = gfxdata;
508510            gfx.line_modulo = width/2;
509511            gfx.char_modulo = 0;   /* doesn't matter */
510            gfx.flags = GFX_PACKED;
512            gfx.flags = GFX_ELEMENT_PACKED;
511513
512514            /* Bounds checking */
513515            if ( (gfxdata + width/2 * height - 1) >= gfx_max )
src/mame/video/segaic24.c
r936r937
166166   machine->gfx[sys24_char_gfx_index] = allocgfx(&sys24_char_layout);
167167
168168   if (machine->drv->color_table_len)
169   {
170      machine->gfx[sys24_char_gfx_index]->colortable = machine->remapped_colortable;
171169      machine->gfx[sys24_char_gfx_index]->total_colors = machine->drv->color_table_len / 16;
172   }
173170   else
174   {
175      machine->gfx[sys24_char_gfx_index]->colortable = machine->pens;
176171      machine->gfx[sys24_char_gfx_index]->total_colors = machine->drv->total_colors / 16;
177   }
178172
179173   state_save_register_global_pointer(sys24_tile_ram, 0x10000/2);
180174   state_save_register_global_pointer(sys24_char_ram, 0x80000/2);
r936r937
340334   const UINT16 *source  = ((UINT16 *)bm->base) + sx + sy*bm->rowpixels;
341335   const UINT8  *trans = ((UINT8 *) tm->base) + sx + sy*tm->rowpixels;
342336   UINT16       *dest = dm->base;
343   pen_t        *pens   = machine->pens;
337   const pen_t  *pens   = machine->pens;
344338
345339   tpri |= TILEMAP_PIXEL_LAYER0;
346340
src/mame/video/toaplan1.c
r936r937
945945      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
946946      const rectangle *clip,int priority)
947947{
948   const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
948   const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
949949   UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
950950
951951   int sprite_screen_height = ((1<<16)*gfx->height+0x8000)>>16;
src/mame/video/taitojc.c
r936r937
205205
206206   /* set the color information */
207207   if (machine->drv->color_table_len)
208   {
209      machine->gfx[taitojc_gfx_index]->colortable = machine->remapped_colortable;
210208      machine->gfx[taitojc_gfx_index]->total_colors = machine->drv->color_table_len / 16;
211   }
212209   else
213   {
214      machine->gfx[taitojc_gfx_index]->colortable = machine->pens;
215210      machine->gfx[taitojc_gfx_index]->total_colors = machine->drv->total_colors / 16;
216   }
217211
218212   taitojc_texture = auto_malloc(0x400000);
219213
src/mame/video/st0016.c
r936r937
1212
1313UINT32 st0016_game;
1414
15
1615static INT32 st0016_spr_bank,st0016_spr2_bank,st0016_pal_bank,st0016_char_bank;
1716static int spr_dx,spr_dy;
1817
19
2018static UINT8 st0016_vregs[0xc0];
2119static int st0016_ramgfx;
2220
21//super eagle shot
22static mame_bitmap *speglsht_bitmap;
23extern UINT32 *speglsht_framebuffer;
24extern UINT32  speglsht_videoreg;
2325
24
25
2626static const gfx_layout charlayout =
2727{
2828   8,8,
r936r937
203203         else
204204         {
205205            /* samples ? sound dma ? */
206            // speaglsht:  unknown DMA copy : src - 2B6740, dst - 4400, len - 1E400
206207            logerror("unknown DMA copy : src - %X, dst - %X, len - %X, PC - %X\n",srcadr,dstadr,length,activecpu_get_previouspc());
207208            break;
208209         }
r936r937
443444VIDEO_START( st0016 )
444445{
445446   int gfx_index=0;
446
447447   st0016_charram=auto_malloc(ST0016_MAX_CHAR_BANK*ST0016_CHAR_BANK_SIZE);
448448   st0016_spriteram=auto_malloc(ST0016_MAX_SPR_BANK*ST0016_SPR_BANK_SIZE);
449449   st0016_paletteram=auto_malloc(ST0016_MAX_PAL_BANK*ST0016_PAL_BANK_SIZE);
r936r937
459459   machine->gfx[gfx_index] = allocgfx(&charlayout);
460460
461461   /* set the color information */
462   machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
462   machine->gfx[gfx_index]->color_base = 0;
463463   machine->gfx[gfx_index]->total_colors = 0x40;
464464   st0016_ramgfx = gfx_index;
465465
466   spr_dx=0;
467   spr_dy=0;
468
466469   switch(st0016_game&0x3f)
467470   {
468471      case 0: //renju kizoku
r936r937
477480         spr_dy=8;
478481      break;
479482
483      case 3: //super eagle shot
484         speglsht_bitmap = auto_bitmap_alloc( 512, 5122, BITMAP_FORMAT_INDEXED16 );
485      break;
486
480487      case 4: //mayjinsen 1&2
481488         video_screen_set_visarea(0, 0,32*8-1,0,28*8-1);
482489      break;
r936r937
489496         video_screen_set_visarea(0, 0,383,0,383);
490497      break;
491498
492
493      default:
494         spr_dx=0;
495         spr_dy=0;
496499   }
497500
498501   st0016_save_init();
r936r937
596599}
597600
598601
602#define PLOT_PIXEL_RGB(x,y,r,g,b)   if(y>=0 && x>=0 && x<512 && y<512) \
603{ \
604      *BITMAP_ADDR32(bitmap, y, x) = (b) | ((g)<<8) | ((r)<<16); \
605}
606
599607VIDEO_UPDATE( st0016 )
600608{
609
601610#ifdef MAME_DEBUG
602611   if(input_code_pressed_once(KEYCODE_Z))
603612   {
r936r937
620629   }
621630#endif
622631
623   if(ISMACS1)
632   if((st0016_game&0x3f)==3)
624633   {
625      if(!(readinputportbytag("SYS1")&1))   //fake coins - MACS2 system
634      //super eagle shot
635      int x,y,dy;
636
637      fillbitmap(speglsht_bitmap,machine->pens[0],&machine->screen[0].visarea);
638      dy=(speglsht_videoreg&0x20)?(256*512):0; //visible frame
639
640      for(y=0;y<256;y++)
626641      {
627         macs_ram2[0]++;
642         for(x=0;x<512;x++)
643         {
644            int tmp=dy+y*512+x;
645            PLOT_PIXEL_RGB(x-67,y-5,(speglsht_framebuffer[tmp]>>0)&0xff,(speglsht_framebuffer[tmp]>>8)&0xff,(speglsht_framebuffer[tmp]>>16)&0xff);
646         }
628647      }
648
649      //draw st0016 gfx to temporary bitmap (indexed 16)
650      draw_bgmap(machine, speglsht_bitmap,cliprect,0);
651       draw_sprites(machine, speglsht_bitmap,cliprect);
652      draw_bgmap(machine, speglsht_bitmap,cliprect,1);
653
654      //copy temporary bitmap to rgb 32 bit bitmap
655      for(y=cliprect->min_y; y<cliprect->max_y;y++)
656      {
657         UINT16 *srcline = BITMAP_ADDR16(speglsht_bitmap, y, 0);
658         for(x=cliprect->min_x; x<cliprect->max_x;x++)
659         {
660            if(srcline[x])
661            {
662               rgb_t color=palette_get_color(Machine, srcline[x]);
663               PLOT_PIXEL_RGB(x,y,RGB_RED(color),RGB_GREEN(color),RGB_BLUE(color));
664            }
665         }
666      }
629667   }
668   else
669   {
670      if(ISMACS1)
671      {
672         if(!(readinputportbytag("SYS1")&1))   //fake coins - MACS2 system
673         {
674            macs_ram2[0]++;
675         }
676      }
630677
631   fillbitmap(bitmap,machine->pens[UNUSED_PEN],&machine->screen[0].visarea);
632   draw_bgmap(machine, bitmap,cliprect,0);
633    draw_sprites(machine, bitmap,cliprect);
634   draw_bgmap(machine, bitmap,cliprect,1);
678      fillbitmap(bitmap,machine->pens[UNUSED_PEN],&machine->screen[0].visarea);
679      draw_bgmap(machine, bitmap,cliprect,0);
680       draw_sprites(machine, bitmap,cliprect);
681      draw_bgmap(machine, bitmap,cliprect,1);
682   }
635683   return 0;
636684}
637685
src/mame/video/qix.c
r936r937
311311#endif
312312
313313   /* return the pens we are going to use to update the display */
314   return &machine->pens[qix_palettebank * 256];
314   return (void *)&machine->pens[qix_palettebank * 256];
315315}
316316
317317
src/mame/video/snes.c
r936r937
17821782      r = ((col & 0x1f) * fade) >> 4;
17831783      g = (((col & 0x3e0) >> 5) * fade) >> 4;
17841784      b = (((col & 0x7c00) >> 10) * fade) >> 4;
1785      machine->remapped_colortable[ii] = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
1785      /* palette hacks! */
1786      ((pen_t *)machine->remapped_colortable)[ii] = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
17861787   }
17871788}
17881789
src/mame/video/bankp.c
r936r937
1515static int priority;
1616
1717static tilemap *bg_tilemap, *fg_tilemap;
18static colortable *bankp_colortable;
1819
20
1921/***************************************************************************
2022
2123  Convert the color PROMs into a more useable format.
r936r937
4446   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
4547   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
4648
49   /* allocate the colortable */
50   bankp_colortable = colortable_alloc(machine, 32);
4751
48   for (i = 0;i < machine->drv->total_colors;i++)
52   for (i = 0;i < 32;i++)
4953   {
5054      int bit0,bit1,bit2,r,g,b;
5155
52
5356      /* red component */
5457      bit0 = (*color_prom >> 0) & 0x01;
5558      bit1 = (*color_prom >> 1) & 0x01;
r936r937
6669      bit2 = (*color_prom >> 7) & 0x01;
6770      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
6871
69      palette_set_color(machine,i,MAKE_RGB(r,g,b));
72      colortable_palette_set_color(bankp_colortable,i,MAKE_RGB(r,g,b));
7073
7174      color_prom++;
7275   }
r936r937
7477   /* color_prom now points to the beginning of the lookup table */
7578
7679   /* charset #1 lookup table */
77   for (i = 0;i < TOTAL_COLORS(0);i++)
78      COLOR(0,i) = *(color_prom++) & 0x0f;
80   for (i = 0;i < machine->gfx[0]->total_colors * machine->gfx[0]->color_granularity;i++)
81      colortable_entry_set_value(bankp_colortable, machine->gfx[0]->color_base + i, *color_prom++ & 0x0f);
7982
8083   color_prom += 128;   /* skip the bottom half of the PROM - seems to be not used */
8184
8285   /* charset #2 lookup table */
83   for (i = 0;i < TOTAL_COLORS(1);i++)
84      COLOR(1,i) = *(color_prom++) & 0x0f;
86   for (i = 0;i < machine->gfx[1]->total_colors * machine->gfx[1]->color_granularity;i++)
87      colortable_entry_set_value(bankp_colortable, machine->gfx[1]->color_base + i, *color_prom++ & 0x0f);
8588
8689   /* the bottom half of the PROM seems to be not used */
8790}
r936r937
139142   int flags = (bankp_colorram2[tile_index] & 0x08) ? TILE_FLIPX : 0;
140143
141144   SET_TILE_INFO(1, code, color, flags);
145   tileinfo->group = color;
142146}
143147
144148static TILE_GET_INFO( get_fg_tile_info )
r936r937
148152   int flags = (colorram[tile_index] & 0x04) ? TILE_FLIPX : 0;
149153
150154   SET_TILE_INFO(0, code, color, flags);
155   tileinfo->group = color;
151156}
152157
153158VIDEO_START( bankp )
154159{
155160   bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
156      TILEMAP_TYPE_COLORTABLE, 8, 8, 32, 32);
161      TILEMAP_TYPE_PEN, 8, 8, 32, 32);
157162
158163   fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_rows,
159      TILEMAP_TYPE_COLORTABLE, 8, 8, 32, 32);
164      TILEMAP_TYPE_PEN, 8, 8, 32, 32);
160165
161   tilemap_set_transparent_pen(bg_tilemap, 0);
162   tilemap_set_transparent_pen(fg_tilemap, 0);
166   colortable_configure_tilemap_groups(bankp_colortable, bg_tilemap, machine->gfx[1], 0);
167   colortable_configure_tilemap_groups(bankp_colortable, fg_tilemap, machine->gfx[0], 0);
163168}
164169
165170VIDEO_UPDATE( bankp )
src/mame/video/wecleman.c
r936r937
2626   UINT8 *pen_data;   /* points to top left corner of tile data */
2727   int line_offset;
2828
29   pen_t *pal_data;
29   const pen_t *pal_data;
3030
3131   int x_offset, y_offset;
3232   int tile_width, tile_height;
r936r937
104104
105105static void get_sprite_info(running_machine *machine)
106106{
107   pen_t *base_pal = machine->remapped_colortable;
107   const pen_t *base_pal = machine->remapped_colortable;
108108   UINT8 *base_gfx = memory_region(REGION_GFX1);
109109   int gfx_max     = memory_region_length(REGION_GFX1);
110110
r936r937
202202#define PRECISION_Y 20
203203#define FPY_HALF (1<<(PRECISION_Y-1))
204204
205   pen_t *pal_base;
205   const pen_t *pal_base;
206206   int src_f0y, src_fdy, src_f0x, src_fdx, src_fpx;
207207   int x1, x2, y1, y2, dx, dy, sx, sy;
208208   int xcount0=0, ycount0=0;
r936r937
559559
560560
561561   UINT8 *src_ptr;
562   pen_t *pal_ptr, *rgb_ptr;
562   const pen_t *pal_ptr, *rgb_ptr;
563563
564564   int scrollx, sy, sx;
565565   int mdy, tdy, i;
r936r937
653653{
654654   UINT8 *src_base, *src_ptr;
655655   UINT16 *tmap_ptr, *dst_base, *dst_ptr;
656   pen_t *pal_base, *pal_ptr;
656   const pen_t *pal_base, *pal_ptr;
657657
658658   int tilew, tileh;
659659   int tmskipx, tmskipy, tmscanx, tmmaskx, tmmasky;
r936r937
10141014
10151015VIDEO_UPDATE ( wecleman )
10161016{
1017   pen_t *mrct;
1017   const pen_t *mrct;
10181018   int video_on;
10191019   int fg_x, bg_x, fg_y, bg_y;
10201020   int cloud_sx, cloud_sy;
r936r937
10491049   }
10501050
10511051   // temporary fix for ranking screen tile masking
1052   mrct[0x27] = mrct[0x24];
1052   /* palette hacks! */
1053   ((pen_t *)mrct)[0x27] = mrct[0x24];
10531054
10541055   get_sprite_info(machine);
10551056
r936r937
10641065   // draws the cloud layer; needs work
10651066   if (cloud_visible)
10661067   {
1067      mrct[0] = mrct[0x40] = mrct[0x200] = mrct[0x205];
1068      /* palette hacks! */
1069      ((pen_t *)mrct)[0] = ((pen_t *)mrct)[0x40] = ((pen_t *)mrct)[0x200] = ((pen_t *)mrct)[0x205];
10681070
10691071      if (video_on)
10701072         draw_cloud(machine,
src/mame/video/bosco.c
r936r937
1111
1212
1313#define MAX_STARS 252
14#define STARS_COLOR_BASE 32
14#define STARS_COLOR_BASE (64*4+64*4+4)
1515
1616static UINT32 stars_scrollx;
1717static UINT32 stars_scrolly;
r936r937
2626UINT8 *bosco_radarattr;
2727static UINT8 *bosco_radarx,*bosco_radary;
2828
29static colortable *bosco_colortable;
2930
31
3032PALETTE_INIT( bosco )
3133{
3234   int i;
33   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
34   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
3535
36   bosco_colortable = colortable_alloc(machine, 32+64);
3637
38   /* core palette */
3739   for (i = 0;i < 32;i++)
3840   {
3941      int bit0,bit1,bit2,r,g,b;
r936r937
5254      bit2 = ((*color_prom) >> 7) & 0x01;
5355      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
5456
55      palette_set_color(machine,i,MAKE_RGB(r,g,b));
57      colortable_palette_set_color(bosco_colortable,i,MAKE_RGB(r,g,b));
5658      color_prom++;
5759   }
5860
59   /* characters / sprites */
60   for (i = 0;i < 64*4;i++)
61   {
62      colortable[i] = (color_prom[i] & 0x0f) + 0x10;   /* chars */
63      colortable[i+64*4] = (color_prom[i] & 0x0f);   /* sprites */
64   }
65
66   /* bullets lookup table */
67   /* they use colors 28-31, I think - PAL 5A controls it */
68   for (i = 0;i < 4;i++)
69   {
70      COLOR(2,i) = 31-i;
71      COLOR(2,i+4) = 0;   // transparent
72   }
73
74   /* now the stars */
61   /* palette for the stars */
7562   for (i = 0;i < 64;i++)
7663   {
7764      int bits,r,g,b;
78      static const int map[4] = { 0x00, 0x47, 0x97, 0xde };
65      static const int map[4] = { 0x00, 0x47, 0x97 ,0xde };
7966
8067      bits = (i >> 0) & 0x03;
8168      r = map[bits];
r936r937
8471      bits = (i >> 4) & 0x03;
8572      b = map[bits];
8673
87      palette_set_color(machine,i + 32,MAKE_RGB(r,g,b));
74      colortable_palette_set_color(bosco_colortable,32 + i,MAKE_RGB(r,g,b));
8875   }
76
77   /* characters / sprites */
78   for (i = 0;i < 64*4;i++)
79   {
80      colortable_entry_set_value(bosco_colortable, i, (color_prom[i] & 0x0f) + 0x10);   /* chars */
81      colortable_entry_set_value(bosco_colortable, i+64*4, color_prom[i] & 0x0f);   /* sprites */
82   }
83
84   /* bullets lookup table */
85   /* they use colors 28-31, I think - PAL 5A controls it */
86   for (i = 0;i < 4;i++)
87      colortable_entry_set_value(bosco_colortable, 64*4+64*4+i, 31-i);
88
89   /* now the stars */
90   for (i = 0;i < 64;i++)
91      colortable_entry_set_value(bosco_colortable, 64*4+64*4+4+i, 32 + i);
8992}
9093
9194
r936r937
107110{
108111   UINT8 attr = bosco_videoram[ram_offs + tile_index + 0x800];
109112   tileinfo->category = (attr & 0x20) >> 5;
113   tileinfo->group = attr & 0x3f;
110114   SET_TILE_INFO(
111115         0,
112116         bosco_videoram[ram_offs + tile_index],
r936r937
134138
135139VIDEO_START( bosco )
136140{
137
138141   bg_tilemap = tilemap_create(bg_get_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,32,32);
139142   fg_tilemap = tilemap_create(fg_get_tile_info,fg_tilemap_scan,  TILEMAP_TYPE_PEN,8,8, 8,32);
140143
144   colortable_configure_tilemap_groups(bosco_colortable, bg_tilemap, machine->gfx[0], 0x1f);
145   colortable_configure_tilemap_groups(bosco_colortable, fg_tilemap, machine->gfx[0], 0x1f);
146
141147   tilemap_set_scrolldx(bg_tilemap,3,3);
142148
143149   spriteram_size = 0x0c;
r936r937
217223      int sy = 240 - spriteram_2[offs];
218224      int flipx = spriteram[offs] & 1;
219225      int flipy = spriteram[offs] & 2;
226      int color = spriteram_2[offs + 1] & 0x3f;
220227      if (flip_screen) sx += 32-2;
221228
222229      drawgfx(bitmap,machine->gfx[1],
223230            (spriteram[offs] & 0xfc) >> 2,
224            spriteram_2[offs + 1] & 0x3f,
231            color,
225232            flipx,flipy,
226233            sx,sy,
227            cliprect,TRANSPARENCY_COLOR,0x0f);
234            cliprect,TRANSPARENCY_PENS,
235            colortable_get_transpen_mask(bosco_colortable, machine->gfx[1], color, 0x0f));
228236   }
229237}
230238
r936r937
246254            0,
247255            0,0,
248256            x,y,
249            cliprect,TRANSPARENCY_COLOR,0);
257            cliprect,TRANSPARENCY_PENS,0xf0);
250258   }
251259}
252260
253261
254262static void draw_stars(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect )
255263{
256
257264   if (1)
258
259265   {
260      int bpen,star_cntr;
266      int star_cntr;
261267      int set_a, set_b;
262268
263269      /* two sets of stars controlled by these bits */
264
265270      set_a = bosco_starblink[0];
266271      set_b = bosco_starblink[1] |0x2;
267272
268      bpen = machine->pens[0x1f];
269273      for (star_cntr = 0;star_cntr < MAX_STARS;star_cntr++)
270274      {
271275         int x,y;
272276
273277         if   ( (set_a == star_seed_tab[star_cntr].set) ||  ( set_b == star_seed_tab[star_cntr].set) )
274278         {
279            x = (  star_seed_tab[star_cntr].x + stars_scrollx) % 256;
280            y = (  star_seed_tab[star_cntr].y + stars_scrolly) % 256;
275281
276
277                                x = (  star_seed_tab[star_cntr].x + stars_scrollx) % 256;
278                                y = (  star_seed_tab[star_cntr].y + stars_scrolly) % 256;
279
280282            /* dont draw the stars that are off the screen */
281283            if ( x < 224 && y < 224 )
282             {
283
284            {
284285               if (flip_screen) x += 64;
285286
286287               if (y >= machine->screen[0].visarea.min_y && y <= machine->screen[0].visarea.max_y)
287               {
288                  if (*BITMAP_ADDR16(bitmap, y, x) == bpen)
289                     *BITMAP_ADDR16(bitmap, y, x) = STARS_COLOR_BASE + star_seed_tab[star_cntr].col;
290               }
288                  *BITMAP_ADDR16(bitmap, y, x) = STARS_COLOR_BASE + star_seed_tab[star_cntr].col;
291289             }
292290         }
293
294291      }
295292   }
296
297
298293}
299294
300295
r936r937
315310      fg_clip.min_x = 28*8;
316311   }
317312
313   fillbitmap(bitmap,get_black_pen(machine),cliprect);
314   draw_stars(machine, bitmap,cliprect);
315
318316   tilemap_draw(bitmap,&bg_clip,bg_tilemap,0,0);
319317   tilemap_draw(bitmap,&fg_clip,fg_tilemap,0,0);
320318
r936r937
326324
327325   draw_bullets(machine, bitmap,cliprect);
328326
329   draw_stars(machine, bitmap,cliprect);
330327   return 0;
331328}
332329
src/mame/video/namcos22.c
r936r937
778778
779779      clip=&myclip;
780780   }
781   if( gfx && gfx->colortable )
781   if( gfx )
782782   {
783      const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
783      const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
784784      UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
785785      int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
786786      int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
src/mame/video/rockola.c
r936r937
1616
1717static tilemap *bg_tilemap, *fg_tilemap;
1818
19static rgb_t palette[64];
20
21#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
22#define COLOR(gfxn,offs) (Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs)
23
24
25
1926/***************************************************************************
2027
2128  Convert the color PROMs into a more useable format.
r936r937
2734{
2835   int i;
2936
30   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
31   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
32
3337   for (i = 0; i < machine->drv->total_colors; i++)
3438   {
3539      int bit0, bit1, bit2, r, g, b;
r936r937
5862
5963      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
6064
61      palette_set_color(machine,i, MAKE_RGB(r, g, b));
65      palette[i] = MAKE_RGB(r, g, b);
6266
6367      color_prom++;
6468   }
r936r937
6670   backcolor = 0;   /* background color can be changed by the game */
6771
6872   for (i = 0; i < TOTAL_COLORS(0); i++)
69      COLOR(0, i) = i;
73      palette_set_color(machine, COLOR(0, i), palette[i]);
7074
7175   for (i = 0; i < TOTAL_COLORS(1); i++)
7276   {
7377      if (i % 4 == 0)
74         COLOR(1, i) = 4 * backcolor + 0x20;
78         palette_set_color(machine, COLOR(1, i), palette[4 * backcolor + 0x20]);
7579      else
76         COLOR(1, i) = i + 0x20;
80         palette_set_color(machine, COLOR(1, i), palette[i + 0x20]);
7781   }
7882}
7983
r936r937
118122      backcolor = data & 7;
119123
120124      for (i = 0;i < 32;i += 4)
121         Machine->gfx[1]->colortable[i] = Machine->pens[4 * backcolor + 0x20];
122
123      tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
125         palette_set_color(Machine, COLOR(1, i), palette[4 * backcolor + 0x20]);
124126   }
125127
126128   /* bit 3 selects char bank */
r936r937
196198{
197199   int i;
198200
199   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
200   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
201
202201   for (i = 0; i < machine->drv->total_colors; i++)
203202   {
204203      int bit0, bit1, bit2, r, g, b;
r936r937
227226
228227      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
229228
230      palette_set_color(machine, i, MAKE_RGB(r, g, b));
229      palette[i] = MAKE_RGB(r, g, b);
231230
232231      color_prom++;
233232   }
r936r937
235234   backcolor = 0;   /* background color can be changed by the game */
236235
237236   for (i = 0; i < TOTAL_COLORS(0); i++)
238      COLOR(0, i) = 4 * (i % 4) + (i / 4);
237      palette_set_color(machine, COLOR(0, i), palette[4 * (i % 4) + (i / 4)]);
239238
240239   for (i = 0; i < TOTAL_COLORS(1); i++)
241240   {
242241      if (i % 4 == 0)
243         COLOR(1, i) = backcolor + 0x10;
242         palette_set_color(machine, COLOR(1, i), palette[backcolor + 0x10]);
244243      else
245         COLOR(1, i) = 4 * (i % 4) + (i / 4) + 0x10;
244         palette_set_color(machine, COLOR(1, i), palette[4 * (i % 4) + (i / 4) + 0x10]);
246245   }
247246}
248247
r936r937
276275      backcolor = data & 0x03;
277276
278277      for (i = 0; i < 16; i += 4)
279         Machine->gfx[1]->colortable[i] = Machine->pens[backcolor + 0x10];
280
281      tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
278         palette_set_color(Machine, COLOR(1, i), palette[backcolor + 0x10]);
282279   }
283280}
284281
src/mame/video/atarisy1.c
r936r937
654654   decodegfx(machine->gfx[gfx_index], &memory_region(REGION_GFX2)[0x80000 * (bank_index - 1)], 0, machine->gfx[gfx_index]->total_elements);
655655
656656   /* set the color information */
657   machine->gfx[gfx_index]->colortable = &machine->remapped_colortable[256];
657   machine->gfx[gfx_index]->color_base = 256;
658658   machine->gfx[gfx_index]->color_granularity = 8;
659659   machine->gfx[gfx_index]->total_colors = 0x40;
660660   bank_color_shift[gfx_index] = bpp - 3;
src/mame/video/tceptor.c
r936r937
295295   decodegfx(machine->gfx[gfx_index], memory_region(region), 0, machine->gfx[gfx_index]->total_elements);
296296
297297   /* set the color information */
298   machine->gfx[gfx_index]->colortable = &machine->remapped_colortable[2048];
298   machine->gfx[gfx_index]->color_base = 2048;
299299   machine->gfx[gfx_index]->total_colors = 64;
300300}
301301
r936r937
306306   decodegfx(machine->gfx[gfx_index], data, 0, machine->gfx[gfx_index]->total_elements);
307307
308308   /* set the color information */
309   machine->gfx[gfx_index]->colortable = &machine->remapped_colortable[1024];
309   machine->gfx[gfx_index]->color_base = 1024;
310310   machine->gfx[gfx_index]->total_colors = 64;
311311}
312312
src/mame/video/metro.c
r936r937
652652            gfx.width = width;
653653            gfx.height = height;
654654            gfx.total_elements = 1;
655            gfx.color_depth = 256;
655656            gfx.color_granularity = 256;
656            gfx.colortable = machine->remapped_colortable;
657            gfx.color_base = 0;
657658            gfx.total_colors = 0x20;
658659            gfx.pen_usage = NULL;
659660            gfx.gfxdata = gfxdata;
r936r937
681682            gfx.width = width;
682683            gfx.height = height;
683684            gfx.total_elements = 1;
685            gfx.color_depth = 16;
684686            gfx.color_granularity = 16;
685            gfx.colortable = machine->remapped_colortable;
687            gfx.color_base = 0;
686688            gfx.total_colors = 0x200;
687689            gfx.pen_usage = NULL;
688690            gfx.gfxdata = gfxdata;
689691            gfx.line_modulo = width/2;
690692            gfx.char_modulo = 0;   /* doesn't matter */
691            gfx.flags = GFX_PACKED;
693            gfx.flags = GFX_ELEMENT_PACKED;
692694
693695            /* Bounds checking */
694696            if ( (gfxdata + width/2 * height - 1) >= gfx_max )
src/mame/video/jalblend.c
r936r937
8585   else      { ystart = 0;      yend = high; yinc = +1; }
8686
8787   /* Start drawing */
88   if( gfx && gfx->colortable )
88   if( gfx )
8989   {
9090      for (ytile = ystart; ytile != yend; ytile += yinc )
9191      {
9292         for (xtile = xstart; xtile != xend; xtile += xinc )
9393         {
94            const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
95            const UINT8 *alpha = &jal_blend_table[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
94            const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
95            const UINT8 *alpha = &jal_blend_table[gfx->color_granularity * (color % gfx->total_colors)];
9696            int source_base = ((code + code_offset++) % gfx->total_elements) * gfx->height;
9797
9898            int x_index_base, y_index, sx, sy, ex, ey;
src/mame/video/nbmj8891.c
r936r937
323323static void update_pixel1(int x, int y)
324324{
325325   UINT8 color = nbmj8891_videoram1[(y * Machine->screen[0].width) + x];
326   *BITMAP_ADDR16(nbmj8891_tmpbitmap1, y, x) = Machine->pens[color];
326   *BITMAP_ADDR16(nbmj8891_tmpbitmap1, y, x) = Machine->pens[(color == 0x7f) ? 0xff : color];
327327}
328328
329329static TIMER_CALLBACK( blitter_timer_callback )
r936r937
512512   nbmj8891_clut = auto_malloc(0x800 * sizeof(UINT8));
513513   memset(nbmj8891_videoram0, 0xff, (machine->screen[0].width * machine->screen[0].height * sizeof(UINT8)));
514514   memset(nbmj8891_videoram1, 0xff, (machine->screen[0].width * machine->screen[0].height * sizeof(UINT8)));
515   machine->pens[0x07f] = 0xff;   /* palette_transparent_pen */
516515   gfxdraw_mode = 1;
517516}
518517
src/mame/video/seta.c
r936r937
278278         if (ACCESSING_LSB)
279279         {
280280            seta_coin_lockout_w (data & 0x0f);
281            if (sndti_to_sndnum(SOUND_X1_010, 0) >= 0)
281            if (sndti_exists(SOUND_X1_010, 0))
282282               seta_sound_enable_w (data & 0x20);
283283            coin_counter_w(0,data & 0x01);
284284            coin_counter_w(1,data & 0x02);
src/mame/video/plygonet.c
r936r937
7070   decodegfx(machine->gfx[ttl_gfx_index], memory_region(REGION_GFX1), 0, machine->gfx[ttl_gfx_index]->total_elements);
7171
7272   if (machine->drv->color_table_len)
73   {
74           machine->gfx[ttl_gfx_index]->colortable = machine->remapped_colortable;
7573           machine->gfx[ttl_gfx_index]->total_colors = machine->drv->color_table_len / 16;
76   }
7774   else
78   {
79           machine->gfx[ttl_gfx_index]->colortable = machine->pens;
8075           machine->gfx[ttl_gfx_index]->total_colors = machine->drv->total_colors / 16;
81   }
8276
8377   // create the tilemap
8478   ttl_tilemap = tilemap_create(ttl_get_tile_info, tilemap_scan_rows, TILEMAP_TYPE_PEN, 8, 8, 64, 32);
src/mame/video/magmax.c
r936r937
141141         UINT32 rom15F_addr   = (((scroll_v + v) & 0x07)<<2) + (map_v_scr_100<<5);
142142         UINT32 map_v_scr_1fe_6 =((scroll_v + v) & 0x1fe)<<6;
143143
144         pen_t *pens = &machine->pens[2*16 + (map_v_scr_100>>1)];
144         const pen_t *pens = &machine->pens[2*16 + (map_v_scr_100>>1)];
145145
146146         if (!map_v_scr_100)
147147         {
src/mame/video/deco16ic.c
r936r937
837837   int ox,oy,cx,cy;
838838   int x_index,y_index,x,y;
839839
840   const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
840   const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
841841   int source_base = (code % gfx->total_elements) * gfx->height;
842842
843843   /* check bounds */
src/mame/video/gridlee.c
r936r937
131131
132132VIDEO_UPDATE( gridlee )
133133{
134   pen_t *pens = &machine->pens[palettebank_vis * 32];
134   const pen_t *pens = &machine->pens[palettebank_vis * 32];
135135   int x, y, i;
136136
137137   /* draw scanlines from the VRAM directly */
src/mame/video/m62.c
r936r937
178178   palette_set_colors(machine, 0x100, rgb, 0x100);
179179   free(rgb);
180180
181   palette_normalize_range(machine, 0x000, 0x1ff, 0x00, 0xff);
181   palette_normalize_range(machine->palette, 0x000, 0x1ff, 0x00, 0xff);
182182
183183   /* we'll need this at run time */
184184   sprite_height_prom = color_prom + 0x600;
r936r937
197197   palette_set_colors(machine, 0x180, rgb, 0x180);
198198   free(rgb);
199199
200   palette_normalize_range(machine, 0x000, 0x2ff, 0x00, 0xff);
200   palette_normalize_range(machine->palette, 0x000, 0x2ff, 0x00, 0xff);
201201
202202   /* we'll need this at run time */
203203   sprite_height_prom = color_prom + 0x900;
r936r937
220220   palette_set_colors(machine, 0x200, rgb, 0x020);
221221   free(rgb);
222222
223   palette_normalize_range(machine, 0x000, 0x21f, 0x00, 0xff);
223   palette_normalize_range(machine->palette, 0x000, 0x21f, 0x00, 0xff);
224224
225225   sprite_height_prom = color_prom + 0x620;   /* we'll need this at run time */
226226}
r936r937
238238   palette_set_colors(machine, 0x200, rgb, 0x100);
239239   free(rgb);
240240
241   palette_normalize_range(machine, 0x000, 0x2ff, 0x00, 0xff);
241   palette_normalize_range(machine->palette, 0x000, 0x2ff, 0x00, 0xff);
242242
243243   /* we'll need this at run time */
244244   sprite_height_prom = color_prom + 0x700;
src/mame/video/galaga.c
r936r937
1111
1212
1313#define MAX_STARS 252
14#define STARS_COLOR_BASE 32
14#define STARS_COLOR_BASE (64*4+64*4)
1515
1616UINT8 *galaga_videoram;
1717UINT8 *galaga_ram1,*galaga_ram2,*galaga_ram3;
1818UINT8 galaga_starcontrol[6];
1919static UINT32 stars_scrollx,stars_scrolly;
20static colortable *galaga_colortable;
2021
2122static INT32 galaga_gfxbank; // used by catsbee
2223
r936r937
337338{
338339   int i;
339340
341   galaga_colortable = colortable_alloc(machine, 32+64);
340342
343   /* core palette */
341344   for (i = 0;i < 32;i++)
342345   {
343346      int bit0,bit1,bit2,r,g,b;
344347
345
346348      bit0 = ((*color_prom) >> 0) & 0x01;
347349      bit1 = ((*color_prom) >> 1) & 0x01;
348350      bit2 = ((*color_prom) >> 2) & 0x01;
r936r937
356358      bit2 = ((*color_prom) >> 7) & 0x01;
357359      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
358360
359      palette_set_color(machine,i,MAKE_RGB(r,g,b));
361      colortable_palette_set_color(galaga_colortable,i,MAKE_RGB(r,g,b));
360362      color_prom++;
361363   }
362364
363   /* characters */
364   for (i = 0;i < 64*4;i++)
365      *(colortable++) = (*(color_prom++) & 0x0f) + 0x10;   /* chars */
366
367   /* sprites */
368   for (i = 0;i < 64*4;i++)
369      *(colortable++) = (*(color_prom++) & 0x0f);   /* sprites */
370
371
372   /* now the stars */
365   /* palette for the stars */
373366   for (i = 0;i < 64;i++)
374367   {
375368      int bits,r,g,b;
r936r937
382375      bits = (i >> 4) & 0x03;
383376      b = map[bits];
384377
385      palette_set_color(machine,i + 32,MAKE_RGB(r,g,b));
378      colortable_palette_set_color(galaga_colortable,32 + i,MAKE_RGB(r,g,b));
386379   }
380
381   /* characters */
382   for (i = 0;i < 64*4;i++)
383      colortable_entry_set_value(galaga_colortable, i, (*(color_prom++) & 0x0f) + 0x10);   /* chars */
384
385   /* sprites */
386   for (i = 0;i < 64*4;i++)
387      colortable_entry_set_value(galaga_colortable, 64*4+i, (*(color_prom++) & 0x0f));
388
389   /* now the stars */
390   for (i = 0;i < 64;i++)
391      colortable_entry_set_value(galaga_colortable, 64*4+64*4+i, 32 + i);
387392}
388393
389394
r936r937
417422       timing signals, while x flip is done by selecting the 2nd character set.
418423       We reproduce this here, but since the tilemap system automatically flips
419424       characters when screen is flipped, we have to flip them back. */
425    int color = galaga_videoram[tile_index + 0x400] & 0x3f;
420426   SET_TILE_INFO(
421427         0,
422428         (galaga_videoram[tile_index] & 0x7f) | (flip_screen ? 0x80 : 0) | (galaga_gfxbank << 8),
423         galaga_videoram[tile_index + 0x400] & 0x3f,
429         color,
424430         flip_screen ? TILE_FLIPX : 0);
431   tileinfo->group = color;
425432}
426433
427434
r936r937
434441
435442VIDEO_START( galaga )
436443{
437   tx_tilemap = tilemap_create(get_tile_info,tilemap_scan,TILEMAP_TYPE_COLORTABLE,8,8,36,28);
444   tx_tilemap = tilemap_create(get_tile_info,tilemap_scan,TILEMAP_TYPE_PEN,8,8,36,28);
445   colortable_configure_tilemap_groups(galaga_colortable, tx_tilemap, machine->gfx[0], 0x1f);
438446
439   tilemap_set_transparent_pen(tx_tilemap, 0x1f);
440
441447   galaga_gfxbank = 0;
442448
443449   spriteram   = galaga_ram1 + 0x380;
r936r937
529535               color,
530536               flipx,flipy,
531537               sx + 16*x, sy + 16*y,
532               cliprect,TRANSPARENCY_COLOR,0x0f);
538               cliprect,TRANSPARENCY_PENS,
539               colortable_get_transpen_mask(galaga_colortable, machine->gfx[1], color, 0x0f));
533540         }
534541      }
535542   }
r936r937
545552
546553   if ( galaga_starcontrol[5] == 1 )
547554   {
548        int bpen, star_cntr;
555        int star_cntr;
549556      int set_a, set_b;
550      bpen = machine->pens[0x1f];
551557
552558      /* two sets of stars controlled by these bits */
553559
r936r937
569575
570576
571577            if (y >= machine->screen[0].visarea.min_y && y <= machine->screen[0].visarea.max_y)
572            {
573               if (*BITMAP_ADDR16(bitmap, y, x) == bpen)
574                  *BITMAP_ADDR16(bitmap, y, x) = STARS_COLOR_BASE + star_seed_tab[ star_cntr ].col;
575            }
578               *BITMAP_ADDR16(bitmap, y, x) = STARS_COLOR_BASE + star_seed_tab[ star_cntr ].col;
576579         }
577580
578581      }
r936r937
581584
582585VIDEO_UPDATE( galaga )
583586{
584   fillbitmap(bitmap,machine->pens[0x1f],cliprect);
587   fillbitmap(bitmap,get_black_pen(machine),cliprect);
588   draw_stars(machine,bitmap,cliprect);
585589   draw_sprites(machine,bitmap,cliprect);
586590   tilemap_draw(bitmap,cliprect,tx_tilemap,0,0);
587
588   draw_stars(machine,bitmap,cliprect);
589591   return 0;
590592}
591593
src/mame/video/pacland.c
r936r937
3232static int palette_bank;
3333static const UINT8 *pacland_color_prom;
3434
35static colortable *pacland_colortable;
3536static tilemap *bg_tilemap, *fg_tilemap;
3637static mame_bitmap *sprite_bitmap,*fg_bitmap;
3738
r936r937
9293
9394      color_prom++;
9495
95      palette_set_color(machine,i,MAKE_RGB(r,g,b));
96      colortable_palette_set_color(pacland_colortable,i,MAKE_RGB(r,g,b));
9697   }
9798}
9899
99100PALETTE_INIT( pacland )
100101{
101102   int i;
102   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
103103
104   /* allocate the colortable */
105   pacland_colortable = colortable_alloc(machine, 256);
104106
105107   pacland_color_prom = color_prom;   /* we'll need this later */
106108   /* skip the palette data, it will be initialized later */
r936r937
109111
110112   /* Foreground */
111113   for (i = 0;i < 0x400;i++)
112      COLOR(0,i) = *(color_prom++);
114      colortable_entry_set_value(pacland_colortable, machine->gfx[0]->color_base + i, *color_prom++);
113115
114116   /* Background */
115117   for (i = 0;i < 0x400;i++)
116      COLOR(1,i) = *(color_prom++);
118      colortable_entry_set_value(pacland_colortable, machine->gfx[1]->color_base + i, *color_prom++);
117119
118120   /* Sprites */
119121   for (i = 0;i < 0x400;i++)
120122   {
121      COLOR(2,i) = *(color_prom++);
122      COLOR(2,i + 0x400) = (COLOR(2,i) < 0x80) ? 0x7f : 0xff;   // for high priority mask (round 19)
123      colortable_entry_set_value(pacland_colortable, machine->gfx[2]->color_base + i, *color_prom);
124      colortable_entry_set_value(pacland_colortable, machine->gfx[2]->color_base + i + 0x400, (*color_prom++ < 0x80) ? 0x7f : 0xff);   // for high priority mask (round 19)
123125   }
124126
125127   palette_bank = 0;
r936r937
154156   int flags = TILE_FLIPYX(attr >> 6);
155157
156158   tileinfo->category = (attr & 0x20) ? 1 : 0;
159   tileinfo->group = color;
157160
158161   SET_TILE_INFO(0, code, color, flags);
159162}
r936r937
171174   fg_bitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
172175   sprite_bitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
173176
174   bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,           8,8,64,32);
175   fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_COLORTABLE,8,8,64,32);
177   bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,64,32);
178   fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,64,32);
176179
177180   tilemap_set_scroll_rows(fg_tilemap, 32);
178   tilemap_set_transparent_pen(fg_tilemap, 0xff);
181   colortable_configure_tilemap_groups(pacland_colortable, fg_tilemap, machine->gfx[0], 0xff);
179182
180183   spriteram = pacland_spriteram + 0x780;
181184   spriteram_2 = spriteram + 0x800;
r936r937
280283               color,
281284               flipx,flipy,
282285               sx + 16*x,sy + 16*y,
283               cliprect,TRANSPARENCY_COLOR,0xff);
286               cliprect,TRANSPARENCY_PENS,
287               colortable_get_transpen_mask(pacland_colortable, machine->gfx[2], color, 0xff));
284288         }
285289      }
286290   }
src/mame/video/tatsumi.c
r936r937
265265   }
266266
267267   {
268      if( gfx && gfx->colortable )
268      if( gfx )
269269      {
270         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
270         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
271271         const UINT8 *shadow_pens = shadow_pen_array + (gfx->color_granularity * (color % gfx->total_colors));
272272         int source_base = (code % gfx->total_elements) * gfx->height;
273273
src/mame/video/konamiic.c
r936r937
19811981
19821982   /* set the color information */
19831983   if (machine->drv->color_table_len)
1984   {
1985      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
19861984      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
1987   }
19881985   else
1989   {
1990      machine->gfx[gfx_index]->colortable = machine->pens;
19911986      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
1992   }
19931987
19941988   K052109_memory_region = gfx_memory_region;
19951989   K052109_gfxnum = gfx_index;
r936r937
24522446
24532447   /* set the color information */
24542448   if (machine->drv->color_table_len)
2455   {
2456      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
24572449      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
2458   }
24592450   else
2460   {
2461      machine->gfx[gfx_index]->colortable = machine->pens;
24622451      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
2463   }
24642452
24652453#if VERBOSE
24662454   if (!(machine->drv->video_attributes & VIDEO_HAS_SHADOWS))
r936r937
29492937
29502938   /* set the color information */
29512939   if (machine->drv->color_table_len)
2952   {
2953      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
29542940      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
2955   }
29562941   else
2957   {
2958      machine->gfx[gfx_index]->colortable = machine->pens;
29592942      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
2960   }
29612943
29622944#if VERBOSE
29632945   if (!(machine->drv->video_attributes & VIDEO_HAS_SHADOWS))
r936r937
36953677
36963678   /* set the color information */
36973679   if (machine->drv->color_table_len)
3698   {
3699      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
37003680      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
3701   }
37023681   else
3703   {
3704      machine->gfx[gfx_index]->colortable = machine->pens;
37053682      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
3706   }
37073683
37083684#if VERBOSE
37093685   if (machine->screen[0].format == BITMAP_FORMAT_RGB32)
r936r937
38573833
38583834   /* set the color information */
38593835   if (machine->drv->color_table_len)
3860   {
3861      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
38623836      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
3863   }
38643837   else
3865   {
3866      machine->gfx[gfx_index]->colortable = machine->pens;
38673838      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
3868   }
38693839
38703840#if VERBOSE
38713841   if (!(machine->drv->video_attributes & VIDEO_HAS_SHADOWS))
r936r937
46204590
46214591   /* set the color information */
46224592   if (machine->drv->color_table_len)
4623   {
4624      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
46254593      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / (1 << bpp);
4626   }
46274594   else
4628   {
4629      machine->gfx[gfx_index]->colortable = machine->pens;
46304595      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / (1 << bpp);
4631   }
46324596
46334597   K051316_memory_region[chip] = gfx_memory_region;
46344598   K051316_gfxnum[chip] = gfx_index;
r936r937
56865650
56875651   /* set the color information */
56885652   if (machine->drv->color_table_len)
5689   {
5690      machine->gfx[gfx_index]->colortable = machine->remapped_colortable;
56915653      machine->gfx[gfx_index]->total_colors = machine->drv->color_table_len / 16;
5692   }
56935654   else
5694   {
5695      machine->gfx[gfx_index]->colortable = machine->pens;
56965655      machine->gfx[gfx_index]->total_colors = machine->drv->total_colors / 16;
5697   }
56985656   machine->gfx[gfx_index]->color_granularity = 16; /* override */
56995657
57005658   K056832_memory_region = gfx_memory_region;
r936r937
64156373   int all_dirty, line;
64166374   int offs, mask;
64176375
6418   pen_t *pal_ptr;
6376   const pen_t *pal_ptr;
64196377   const UINT8  *src_base, *src_ptr;
64206378   UINT8  *xpr_ptr;
64216379   UINT16 *dst_ptr;
r936r937
79367894#else
79377895
79387896// utility function to render a clipped scanline vertically or horizontally
7939INLINE void K053250_pdraw_scanline32(mame_bitmap *bitmap, pen_t *palette, UINT8 *source,
7897INLINE void K053250_pdraw_scanline32(mame_bitmap *bitmap, const pen_t *palette, UINT8 *source,
79407898      const rectangle *cliprect, int linepos, int scroll, int zoom,
79417899      UINT32 clipmask, UINT32 wrapmask, UINT32 orientation, int priority)
79427900{
r936r937
79517909   int src_x;
79527910   int src_fx, src_fdx;
79537911   int pix_data, dst_offset;
7954   pen_t  *pal_base;
7912   const pen_t  *pal_base;
79557913   UINT8  *pri_base;
79567914   UINT32 *dst_base;
79577915   int dst_adv;
r936r937
81088066   struct K053250_CHIPTAG *chip_ptr;
81098067   UINT16 *line_ram;
81108068   UINT8 *pix_base, *pix_ptr, *regs;
8111   pen_t *pal_base, *pal_ptr;
8069   const pen_t *pal_base, *pal_ptr;
81128070   UINT32 rommask, src_clipmask, src_wrapmask, dst_wrapmask;
81138071   int map_scrollx, map_scrolly, ctrl, orientation;
81148072   int dst_minx, dst_maxx, dst_miny, dst_maxy;
src/mame/video/tecmo16.c
r936r937
239239   if (sy > ey) return;
240240
241241   {
242      pen_t *paldata = machine->pens;
242      const pen_t *paldata = machine->pens;
243243      UINT32 *end;
244244
245245      UINT16 *sd1 = src1->base;                                    /* source data   */
src/mame/video/toypop.c
r936r937
1616UINT16 *toypop_bg_image;
1717static int bitmapflip,palettebank;
1818
19static UINT16 *transmask;
19static colortable *toypop_colortable;
2020
2121
2222/***************************************************************************
r936r937
3030
3131PALETTE_INIT( toypop )
3232{
33   rgb_t palette[256];
3433   int i;
3534
35   /* allocate the colortable */
36   toypop_colortable = colortable_alloc(machine, 256);
37
3638   for (i = 0;i < 256;i++)
3739   {
3840      int bit0,bit1,bit2,bit3,r,g,b;
r936r937
5658      bit3 = (color_prom[i+0x200] >> 3) & 0x01;
5759      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
5860
59      palette[i] = MAKE_RGB(r,g,b);
61      colortable_palette_set_color(toypop_colortable, i, MAKE_RGB(r,g,b));
6062   }
6163
62   /* allocate memory for mask of pens that are transparent in sprites */
63   transmask = auto_malloc(64 * sizeof(transmask[0]));
64   memset(transmask, 0, 64 * sizeof(transmask[0]));
65
6664   for (i = 0;i < 256;i++)
6765   {
6866      UINT8 entry;
67
6968      // characters
70      palette_set_color(machine, i + 0*256, palette[(color_prom[i + 0x300] & 0x0f) | 0x70]);
71      palette_set_color(machine, i + 1*256, palette[(color_prom[i + 0x300] & 0x0f) | 0xf0]);
69      colortable_entry_set_value(toypop_colortable, i + 0*256, (color_prom[i + 0x300] & 0x0f) | 0x70);
70      colortable_entry_set_value(toypop_colortable, i + 1*256, (color_prom[i + 0x300] & 0x0f) | 0xf0);
7271      // sprites
7372      entry = color_prom[i + 0x500];
74      palette_set_color(machine, i + 2*256, palette[entry]);
75      if (entry == 0xff)
76         transmask[i/4] |= 1 << (i % 4);
73      colortable_entry_set_value(toypop_colortable, i + 2*256, entry);
7774   }
7875   for (i = 0;i < 16;i++)
7976   {
8077      // background
81      palette_set_color(machine, i + 3*256 + 0*16, palette[0x60 + i]);
82      palette_set_color(machine, i + 3*256 + 1*16, palette[0xe0 + i]);
78      colortable_entry_set_value(toypop_colortable, i + 3*256 + 0*16, 0x60 + i);
79      colortable_entry_set_value(toypop_colortable, i + 3*256 + 1*16, 0xe0 + i);
8380   }
8481}
8582
r936r937
226223***************************************************************************/
227224
228225/* from mappy.c */
229void mappy_draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int xoffs, int yoffs, const UINT16 *transmask_table );
226void mappy_draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int xoffs, int yoffs, colortable *ctable, int transcolor);
230227
231228
232229VIDEO_UPDATE( toypop )
r936r937
234231   draw_background(bitmap);
235232   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
236233
237   mappy_draw_sprites(machine, bitmap, cliprect, -31, -8, transmask );
234   mappy_draw_sprites(machine, bitmap, cliprect, -31, -8, toypop_colortable, 0xff);
238235   return 0;
239236}
src/mame/video/digdug.c
r936r937
99
1010static INT32 bg_select, tx_color_mode, bg_disable, bg_color_bank;
1111
12static colortable *digdug_colortable;
1213
1314
1415/***************************************************************************
r936r937
3435{
3536   int i;
3637
38   digdug_colortable = colortable_alloc(machine, 32);
39
3740   for (i = 0;i < 32;i++)
3841   {
3942      int bit0,bit1,bit2,r,g,b;
r936r937
5053      bit1 = (*color_prom >> 6) & 0x01;
5154      bit2 = (*color_prom >> 7) & 0x01;
5255      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
53      palette_set_color(machine,i,MAKE_RGB(r,g,b));
56      colortable_palette_set_color(digdug_colortable,i,MAKE_RGB(r,g,b));
5457      color_prom++;
5558   }
5659
5760   /* characters - direct mapping */
5861   for (i = 0; i < 16; i++)
5962   {
60      colortable[0] = 0;
61      colortable[1] = i;
62      colortable += 2;
63      colortable_entry_set_value(digdug_colortable, i*2+0, 0);
64      colortable_entry_set_value(digdug_colortable, i*2+1, i);
6365   }
66
6467   /* sprites */
6568   for (i = 0;i < 0x100;i++)
66      *(colortable++) = (*(color_prom++) & 0x0f) + 0x10;
69      colortable_entry_set_value(digdug_colortable, 16*2+i, (*color_prom++ & 0x0f) + 0x10);
70
6771   /* bg_select */
6872   for (i = 0;i < 0x100;i++)
69      *(colortable++) = (*(color_prom++) & 0x0f);
73      colortable_entry_set_value(digdug_colortable, 16*2+256+i, *color_prom++ & 0x0f);
7074}
7175
7276
r936r937
288292      {
289293         for (x = 0;x <= size;x++)
290294         {
295            UINT32 transmask = colortable_get_transpen_mask(digdug_colortable, machine->gfx[1], color, 0x1f);
291296            drawgfx(bitmap,machine->gfx[1],
292297               sprite + gfx_offs[y ^ (size * flipy)][x ^ (size * flipx)],
293298               color,
294299               flipx,flipy,
295300               ((sx + 16*x) & 0xff), sy + 16*y,
296               &spritevisiblearea,TRANSPARENCY_COLOR,0x1f);
301               &spritevisiblearea,TRANSPARENCY_PENS,transmask);
297302            /* wraparound */
298303            drawgfx(bitmap,machine->gfx[1],
299304               sprite + gfx_offs[y ^ (size * flipy)][x ^ (size * flipx)],
300305               color,
301306               flipx,flipy,
302307               ((sx + 16*x) & 0xff) + 0x100, sy + 16*y,
303               &spritevisiblearea,TRANSPARENCY_COLOR,0x1f);
308               &spritevisiblearea,TRANSPARENCY_PENS,transmask);
304309         }
305310      }
306311   }
src/mame/video/ultratnk.c
r936r937
9797
9898VIDEO_EOF( ultratnk )
9999{
100   UINT16 BG = machine->gfx[0]->colortable[0];
100   UINT16 BG = machine->remapped_colortable[machine->gfx[0]->color_base];
101101
102102   int i;
103103
src/mame/video/mappy.c
r936r937
1010
1111static mame_bitmap *sprite_bitmap;
1212
13static UINT16 *transmask;
13static colortable *mappy_colortable;
1414
1515
1616/***************************************************************************
r936r937
4444{
4545   static const int resistances[3] = { 1000, 470, 220 };
4646   double rweights[3], gweights[3], bweights[2];
47   rgb_t palette[32];
4847   int i;
4948
5049   /* compute the color output resistor weights */
r936r937
5352         3, &resistances[0], gweights, 0, 0,
5453         2, &resistances[1], bweights, 0, 0);
5554
55   /* allocate the colortable */
56   mappy_colortable = colortable_alloc(machine, 32);
57
5658   /* create a lookup table for the palette */
5759   for (i = 0; i < 32; i++)
5860   {
r936r937
7678      bit1 = (color_prom[i] >> 7) & 0x01;
7779      b = combine_2_weights(bweights, bit0, bit1);
7880
79      palette[i] = MAKE_RGB(r, g, b);
81      colortable_palette_set_color(mappy_colortable, i, MAKE_RGB(r, g, b));
8082   }
8183
8284   /* color_prom now points to the beginning of the lookup table */
8385   color_prom += 32;
8486
85   /* allocate memory for mask of pens that are transparent in sprites */
86   transmask = auto_malloc(64 * sizeof(transmask[0]));
87   memset(transmask, 0, 64 * sizeof(transmask[0]));
88
8987   /* characters map to the upper 16 palette entries */
9088   for (i = 0; i < 64*4; i++)
9189   {
9290      UINT8 ctabentry = color_prom[i] & 0x0f;
93      palette_set_color(machine, i, palette[(ctabentry ^ 15) + 0x10]);
91      colortable_entry_set_value(mappy_colortable, i, (ctabentry ^ 15) + 0x10);
9492   }
9593
9694   /* sprites map to the lower 16 palette entries */
9795   for (i = 64*4; i < 128*4; i++)
9896   {
9997      UINT8 ctabentry = color_prom[i] & 0x0f;
100      palette_set_color(machine, i, palette[ctabentry]);
101
102      /* if the color table maps to palette entry 15, it is transparent */
103      if (ctabentry == 15)
104         transmask[(i - 64*4)/4] |= 1 << (i % 4);
98      colortable_entry_set_value(mappy_colortable, i, ctabentry);
10599   }
106100}
107101
r936r937
109103{
110104   static const int resistances[3] = { 1000, 470, 220 };
111105   double rweights[3], gweights[3], bweights[2];
112   rgb_t palette[32];
113106   int i;
114107
115108   /* compute the color output resistor weights */
r936r937
118111         3, &resistances[0], gweights, 0, 0,
119112         2, &resistances[1], bweights, 0, 0);
120113
114   /* allocate the colortable */
115   mappy_colortable = colortable_alloc(machine, 32);
116
121117   /* create a lookup table for the palette */
122118   for (i = 0; i < 32; i++)
123119   {
r936r937
141137      bit1 = (color_prom[i] >> 7) & 0x01;
142138      b = combine_2_weights(bweights, bit0, bit1);
143139
144      palette[i] = MAKE_RGB(r, g, b);
140      colortable_palette_set_color(mappy_colortable, i, MAKE_RGB(r, g, b));
145141   }
146142
147143   /* color_prom now points to the beginning of the lookup table */
148144   color_prom += 32;
149145
150   /* allocate memory for mask of pens that are transparent in sprites */
151   transmask = auto_malloc(64 * sizeof(transmask[0]));
152   memset(transmask, 0, 64 * sizeof(transmask[0]));
153
154146   /* characters map to the upper 16 palette entries */
155147   for (i = 0*4; i < 64*4; i++)
156148   {
157149      UINT8 ctabentry = color_prom[i] & 0x0f;
158      palette_set_color(machine, i, palette[ctabentry + 0x10]);
150      colortable_entry_set_value(mappy_colortable, i, ctabentry + 0x10);
159151   }
160152
161153   /* sprites map to the lower 16 palette entries */
162154   for (i = 64*4; i < machine->drv->total_colors; i++)
163155   {
164156      UINT8 ctabentry = color_prom[i] & 0x0f;
165      palette_set_color(machine, i, palette[ctabentry]);
166
167      /* if the color table maps to palette entry 15, it is transparent */
168      if (ctabentry == 15)
169         transmask[(i - 64*4)/16] |= 1 << (i % 16);
157      colortable_entry_set_value(mappy_colortable, i, ctabentry);
170158   }
171159}
172160
r936r937
186174{
187175   static const int resistances[4] = { 2200, 1000, 470, 220 };
188176   double rweights[4], gweights[4], bweights[4];
189   rgb_t palette[32];
190177   int i;
191178
192179   /* compute the color output resistor weights */
r936r937
195182         4, &resistances[0], gweights, 0, 0,
196183         4, &resistances[0], bweights, 0, 0);
197184
185   /* allocate the colortable */
186   mappy_colortable = colortable_alloc(machine, 32);
187
198188   /* create a lookup table for the palette */
199189   for (i = 0; i < 32; i++)
200190   {
r936r937
222212      bit3 = (color_prom[i + 0x200] >> 3) & 0x01;
223213      b = combine_4_weights(bweights, bit0, bit1, bit2, bit3);
224214
225      palette[i] = MAKE_RGB(r, g, b);
215      colortable_palette_set_color(mappy_colortable, i, MAKE_RGB(r, g, b));
226216   }
227217
228218   /* color_prom now points to the beginning of the lookup table */
229219   color_prom += 0x300;
230220
231   /* allocate memory for mask of pens that are transparent in sprites */
232   transmask = auto_malloc(64 * sizeof(transmask[0]));
233   memset(transmask, 0, 64 * sizeof(transmask[0]));
234
235221   /* characters map to the lower 16 palette entries */
236222   for (i = 0; i < 64*4; i++)
237223   {
238224      UINT8 ctabentry = color_prom[i] & 0x0f;
239      palette_set_color(machine, i, palette[ctabentry]);
225      colortable_entry_set_value(mappy_colortable, i, ctabentry);
240226   }
241227
242228   /* sprites map to the upper 16 palette entries */
243229   for (i = 64*4; i < 128*4; i++)
244230   {
245231      UINT8 ctabentry = color_prom[i] & 0x0f;
246      palette_set_color(machine, i, palette[ctabentry + 0x10]);
247
248      /* if the color table maps to palette entry 15, it is transparent */
249      if (ctabentry == 15)
250         transmask[(i - 64*4)/4] |= 1 << (i % 4);
232      colortable_entry_set_value(mappy_colortable, i, ctabentry + 0x10);
251233   }
252234}
253235
r936r937
300282{
301283   UINT8 attr = mappy_videoram[tile_index + 0x400];
302284   tileinfo->category = (attr & 0x40) >> 6;
285   tileinfo->group = attr & 0x3f;
303286   SET_TILE_INFO(
304287         0,
305288         mappy_videoram[tile_index],
r936r937
311294{
312295   UINT8 attr = mappy_videoram[tile_index + 0x400];
313296   tileinfo->category = (attr & 0x40) >> 6;
297   tileinfo->group = attr & 0x3f;
314298   SET_TILE_INFO(
315299         0,
316300         mappy_videoram[tile_index] + ((attr & 0x80) << 1),
r936r937
322306{
323307   UINT8 attr = mappy_videoram[tile_index + 0x800];
324308   tileinfo->category = (attr & 0x40) >> 6;
309   tileinfo->group = attr & 0x3f;
325310   SET_TILE_INFO(
326311         0,
327312         mappy_videoram[tile_index],
r936r937
339324
340325VIDEO_START( superpac )
341326{
342   bg_tilemap = tilemap_create(superpac_get_tile_info,superpac_tilemap_scan,TILEMAP_TYPE_COLORTABLE,8,8,36,28);
327   bg_tilemap = tilemap_create(superpac_get_tile_info,superpac_tilemap_scan,TILEMAP_TYPE_PEN,8,8,36,28);
343328   sprite_bitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
344329
345   tilemap_set_transparent_pen(bg_tilemap, 31);
330   colortable_configure_tilemap_groups(mappy_colortable, bg_tilemap, machine->gfx[0], 31);
346331
347332   spriteram = mappy_spriteram + 0x780;
348333   spriteram_2 = spriteram + 0x800;
r936r937
351336
352337VIDEO_START( phozon )
353338{
354   bg_tilemap = tilemap_create(phozon_get_tile_info,superpac_tilemap_scan,TILEMAP_TYPE_COLORTABLE,8,8,36,28);
339   bg_tilemap = tilemap_create(phozon_get_tile_info,superpac_tilemap_scan,TILEMAP_TYPE_PEN,8,8,36,28);
355340
356   tilemap_set_transparent_pen(bg_tilemap, 15);
341   colortable_configure_tilemap_groups(mappy_colortable, bg_tilemap, machine->gfx[0], 15);
357342
358343   spriteram = mappy_spriteram + 0x780;
359344   spriteram_2 = spriteram + 0x800;
r936r937
362347
363348VIDEO_START( mappy )
364349{
365   bg_tilemap = tilemap_create(mappy_get_tile_info,mappy_tilemap_scan,TILEMAP_TYPE_COLORTABLE,8,8,36,60);
350   bg_tilemap = tilemap_create(mappy_get_tile_info,mappy_tilemap_scan,TILEMAP_TYPE_PEN,8,8,36,60);
366351
367   tilemap_set_transparent_pen(bg_tilemap, 31);
352   colortable_configure_tilemap_groups(mappy_colortable, bg_tilemap, machine->gfx[0], 31);
368353   tilemap_set_scroll_cols(bg_tilemap, 36);
369354
370355   spriteram = mappy_spriteram + 0x780;
r936r937
417402***************************************************************************/
418403
419404/* also used by toypop.c */
420void mappy_draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int xoffs, int yoffs, const UINT16 *transmask_table )
405void mappy_draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int xoffs, int yoffs, colortable *ctable, int transcolor)
421406{
422407   int offs;
423408
r936r937
462447                  color,
463448                  flipx,flipy,
464449                  sx + 16*x,sy + 16*y,
465                  cliprect,TRANSPARENCY_PENS,transmask_table[color & 0x3f]);
450                  cliprect,TRANSPARENCY_PENS,
451                  colortable_get_transpen_mask(ctable, machine->gfx[1], color, transcolor));
466452            }
467453         }
468454      }
r936r937
536522                  color,
537523                  flipx,flipy,
538524                  sx + 8*x,sy + 8*y,
539                  cliprect,TRANSPARENCY_PENS,transmask[color & 0x3f]);
525                  cliprect,TRANSPARENCY_PENS,
526                  colortable_get_transpen_mask(mappy_colortable, machine->gfx[1], color, 31));
540527            }
541528         }
542529      }
r936r937
552539   tilemap_draw(bitmap,cliprect,bg_tilemap,1|TILEMAP_DRAW_OPAQUE,0);
553540
554541   fillbitmap(sprite_bitmap,15,cliprect);
555   mappy_draw_sprites(machine,sprite_bitmap,cliprect,0,0,transmask);
542   mappy_draw_sprites(machine,sprite_bitmap,cliprect,0,0,mappy_colortable,15);
556543   copybitmap(bitmap,sprite_bitmap,0,0,0,0,cliprect,TRANSPARENCY_PEN,15);
557544
558545   /* Redraw the high priority characters */
r936r937
595582   tilemap_draw(bitmap,cliprect,bg_tilemap,0|TILEMAP_DRAW_OPAQUE,0);
596583   tilemap_draw(bitmap,cliprect,bg_tilemap,1|TILEMAP_DRAW_OPAQUE,0);
597584
598   mappy_draw_sprites(machine,bitmap,cliprect,0,0,transmask);
585   mappy_draw_sprites(machine,bitmap,cliprect,0,0,mappy_colortable,15);
599586
600587   /* Redraw the high priority characters */
601588   tilemap_draw(bitmap,cliprect,bg_tilemap,1,0);
src/mame/video/psikyosh.c
r936r937
436436      else      { ystart = 0;      yend = high; yinc = +1; }
437437
438438      /* Start drawing */
439      if( gfx && gfx->colortable )
439      if( gfx )
440440      {
441441         for (ytile = ystart; ytile != yend; ytile += yinc )
442442         {
443443            for (xtile = xstart; xtile != xend; xtile += xinc )
444444            {
445               const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
445               const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
446446               int source_base = ((code + code_offset++) % gfx->total_elements) * gfx->height;
447447
448448               int x_index_base, y_index, sx, sy, ex, ey;
r936r937
704704      }
705705
706706      /* Start drawing */
707      if( gfx && gfx->colortable )
707      if( gfx )
708708      {
709         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
709         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
710710
711711         int sprite_screen_height = ((high*gfx->height*(0x400*0x400))/zoomy + 0x200)>>10; /* Round up to nearest pixel */
712712         int sprite_screen_width = ((wide*gfx->width*(0x400*0x400))/zoomx + 0x200)>>10;
src/mame/video/mpatrol.c
r936r937
323323      rect.max_y = ypos + 2 * BGHEIGHT - 1;
324324   }
325325
326   fillbitmap(bitmap, machine->gfx[image]->colortable[3], &rect);
326   fillbitmap(bitmap, machine->remapped_colortable[machine->gfx[image]->color_base + 3], &rect);
327327}
328328
329329
src/mame/video/equites.c
r936r937
3434static int bgcolor[4];
3535static rectangle halfclip;
3636static struct PRESTEP_TYPE { unsigned sy, fdx; } *prestep;
37static colortable *equites_colortable;
3738
3839/******************************************************************************/
3940// Exports
r936r937
4546
4647static void video_init_common(running_machine *machine)
4748{
48   pen_t *colortable;
4949   int i;
5050
51   colortable = machine->remapped_colortable;
52
5351   // set defaults
5452   maskwidth = 8;
5553   maskheight = machine->screen[0].visarea.max_y - machine->screen[0].visarea.min_y + 1;
r936r937
8078   UINT8 *clut_ptr;
8179   int i;
8280
81   equites_colortable = colortable_alloc(machine, 256);
82
8383   for (i=0; i<256; i++)
84   {
85      palette_set_color_rgb(machine, i, pal4bit(color_prom[i]), pal4bit(color_prom[i+0x100]), pal4bit(color_prom[i+0x200]));
86      colortable[i] = i;
87   }
84      colortable_palette_set_color(equites_colortable, i, MAKE_RGB(pal4bit(color_prom[i]), pal4bit(color_prom[i+0x100]), pal4bit(color_prom[i+0x200])));
8885
86   for (i=0; i<256; i++)
87      colortable_entry_set_value(equites_colortable, i, i);
88
8989   clut_ptr = memory_region(REGION_USER1) + 0x80;
9090   for (i=0; i<128; i++)
91      colortable[i+0x100] = clut_ptr[i];
91      colortable_entry_set_value(equites_colortable, i+0x100, clut_ptr[i]);
9292}
9393
9494static TILE_GET_INFO( equites_charinfo )
r936r937
120120   UINT8 *prom_ptr;
121121   int i;
122122
123   equites_colortable = colortable_alloc(machine, 256);
124
123125   for (i=0; i<0x100; i++)
124   {
125      palette_set_color_rgb(machine, i, pal4bit(color_prom[i]), pal4bit(color_prom[i+0x100]), pal4bit(color_prom[i+0x200]));
126      colortable[i] = (i & 3 || (i > 0x3f && i < 0x80) || i > 0xbf) ? i : 0;
126      colortable_palette_set_color(equites_colortable, i, MAKE_RGB(pal4bit(color_prom[i]), pal4bit(color_prom[i+0x100]), pal4bit(color_prom[i+0x200])));
127127
128   }
128   for (i = 0; i < 0x100; i++)
129      colortable_entry_set_value(equites_colortable, i, i);
130
129131   prom_ptr = memory_region(REGION_USER1);
130   colortable += 0x100;
131   for (i=0; i<0x80; i++) { colortable[i] = prom_ptr[i]+0x10; colortable[i+0x80] = prom_ptr[i]; }
132   for (i=0; i<0x80; i++)
133   {
134      colortable_entry_set_value(equites_colortable, i + 0x100, prom_ptr[i] + 0x10);
135      colortable_entry_set_value(equites_colortable, i + 0x180, prom_ptr[i]);
136   }
132137
133138   prom_ptr += 0x100;
134   colortable += 0x100;
135   for (i=0; i<0x400; i++) colortable[i] = prom_ptr[i];
139   for (i=0; i<0x400; i++)
140      colortable_entry_set_value(equites_colortable, i + 0x200, prom_ptr[i]);
136141}
137142
138143static TILE_GET_INFO( splndrbt_char0info )
r936r937
146151   color &= 0x3f;
147152
148153   SET_TILE_INFO(0, tile, color, 0);
154   if (color & 0x10)
155      tileinfo->flags |= TILE_FORCE_LAYER0;
149156}
150157
151158static TILE_GET_INFO( splndrbt_char1info )
r936r937
160167   tile += 0x100;
161168
162169   SET_TILE_INFO(0, tile, color, 0);
170   if (color & 0x10)
171      tileinfo->flags |= TILE_FORCE_LAYER0;
163172}
164173
165174static void splndrbt_video_reset(void)
r936r937
224233
225234   tmpbitmap = auto_bitmap_alloc(BMW, BMW, machine->screen[0].format);
226235
227   charmap0 = tilemap_create(splndrbt_char0info, tilemap_scan_cols, TILEMAP_TYPE_COLORTABLE, 8, 8, 32, 32);
236   charmap0 = tilemap_create(splndrbt_char0info, tilemap_scan_cols, TILEMAP_TYPE_PEN, 8, 8, 32, 32);
228237   tilemap_set_transparent_pen(charmap0, 0);
229238   tilemap_set_scrolldx(charmap0, 8, 8);
230239   tilemap_set_scrolldy(charmap0, 32, 32);
231240
232   charmap1 = tilemap_create(splndrbt_char1info, tilemap_scan_cols, TILEMAP_TYPE_COLORTABLE, 8, 8, 32, 32);
241   charmap1 = tilemap_create(splndrbt_char1info, tilemap_scan_cols, TILEMAP_TYPE_PEN, 8, 8, 32, 32);
233242   tilemap_set_transparent_pen(charmap1, 0);
234243   tilemap_set_scrolldx(charmap1, 8, 8);
235244   tilemap_set_scrolldy(charmap1, 32, 32);
r936r937
261270// Equites Hardware
262271static void equites_update_clut(running_machine *machine)
263272{
264   pen_t *colortable;
265273   int i, c;
266274
267   colortable = machine->remapped_colortable;
275   /* palette hacks! */
268276   c = *bgcolor;
269277
270   for (i=0x80; i<0x100; i+=0x08) colortable[i] = c;
278   for (i=0x80; i<0x100; i+=0x08)
279      colortable_entry_set_value(equites_colortable, i, c);
271280}
272281
273282static void equites_draw_scroll(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect)
r936r937
381390// Splendor Blast Hardware
382391static void splndrbt_update_clut(running_machine *machine)
383392{
384   pen_t *colortable;
385393   int c;
386394
387   colortable = machine->remapped_colortable;
395   /* palette hacks! */
388396   c = *bgcolor;
389397
390398   switch(equites_id)
391399   {
392400      case 0x8511:
393         colortable[0x114] = c;
401         colortable_entry_set_value(equites_colortable, 0x114, c);
394402      break;
395403   }
396404}
r936r937
437445   unsigned dst_startw, unsigned dst_endw,
438446   struct PRESTEP_TYPE *ps)
439447{
440#define WARP ((1<<BMW_l2)-1)
448#define WRAP ((1<<BMW_l2)-1)
441449
442   UINT16 *src_base, *src_ptr, *dst_ptr;
443   int src_pitch, dst_pitch, dst_wdiff, dst_visw, dst_vish;
444   int dst_curline, dst_xend, src_fsx, src_fdx, eax, ebx, ecx, edx;
450   int src_center_x = ((src_x + (src_w>>1)) & WRAP) << FP_PRECISION;
451   int dst_pitch, dst_wdiff, dst_visw, dst_vish;
452   int dst_curline;
445453
446   src_base = (UINT16*)src_bitmap->base;
447   src_pitch = src_bitmap->rowpixels;
448   ebx = ((src_x + (src_w>>1)) & WARP) << FP_PRECISION;
449
450   eax = dst_clip->min_x;
451   edx = dst_clip->min_y;
452   dst_visw = dst_clip->max_x - eax + 1;
453   dst_vish = dst_clip->max_y - edx;
454   dst_visw = dst_clip->max_x - dst_clip->min_x + 1;
455   dst_vish = dst_clip->max_y - dst_clip->min_y;
454456   dst_pitch = dst_bitmap->rowpixels;
455   dst_ptr = (UINT16*)dst_bitmap->base + edx * dst_pitch + eax + (dst_visw >> 1);
456457
457458   dst_wdiff = dst_endw - dst_startw;
458   dst_curline = 0;
459459
460   do
460   for (dst_curline = dst_clip->min_y; dst_curline <= dst_clip->max_y; dst_curline++)
461461   {
462      dst_xend = dst_startw + (dst_wdiff * dst_curline) / dst_vish;
463      eax = (src_y + ps[dst_curline].sy) & WARP;
464      src_fdx = ps[dst_curline].fdx;
465      src_ptr = src_base + src_pitch * eax;
462      const UINT16 *src_ptr = BITMAP_ADDR16(src_bitmap, (src_y + ps[dst_curline - dst_clip->min_y].sy) & WRAP, 0);
463      UINT16 *dst_ptr = BITMAP_ADDR16(dst_bitmap, dst_curline, dst_clip->min_x + dst_visw / 2);
464      int dst_xend = dst_startw + (dst_wdiff * (dst_curline - dst_clip->min_y)) / dst_vish;
465      int src_fsx = FP_HALF;
466      int src_fdx = ps[dst_curline - dst_clip->min_y].fdx;
467      int dst_x;
468
466469      if (dst_xend > dst_visw) dst_xend = dst_visw;
467      src_fsx = FP_HALF;
468      dst_xend >>= 1;
469      ecx = 0;
470      dst_xend /= 2;
470471
471      do
472      for (dst_x = 0; dst_x < dst_xend; dst_x++)
472473      {
473         eax = ebx - src_fsx;
474         edx = ebx + src_fsx;
474         dst_ptr[-dst_x - 1] = src_ptr[((src_center_x - src_fsx) >> FP_PRECISION) & WRAP];
475         dst_ptr[dst_x] = src_ptr[((src_center_x + src_fsx) >> FP_PRECISION) & WRAP];
475476         src_fsx += src_fdx;
476         eax >>= FP_PRECISION;
477         edx >>= FP_PRECISION;
478         eax &= WARP;
479         edx &= WARP;
480         eax = *(src_ptr + eax);
481         edx = *(src_ptr + edx);
482         *(dst_ptr - ecx - 1) = eax;
483         *(dst_ptr + ecx) = edx;
484477      }
485      while(++ecx < dst_xend);
486
487      dst_ptr += dst_pitch;
488478   }
489   while(++dst_curline <= dst_vish);
490479
491#undef WARP
480#undef WRAP
492481}
493482
494483static void splndrbt_draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *clip)
src/mame/video/djmain.c
r936r937
1717   int offs, pri_code;
1818   int sortedlist[NUM_SPRITES];
1919
20   machine->gfx[0]->colortable = &machine->remapped_colortable[K055555_read_register(K55_PALBASE_SUB2) * 0x400];
20   machine->gfx[0]->color_base = K055555_read_register(K55_PALBASE_SUB2) * 0x400;
2121
2222   for (offs = 0; offs < NUM_SPRITES; offs++)
2323      sortedlist[offs] = -1;
src/mame/video/n64.c
r936r937
4747
4848/*****************************************************************************/
4949
50#ifdef LSB_FIRST
51   #define BYTE_ADDR_XOR      3
52   #define WORD_ADDR_XOR      1
53#else
54   #define BYTE_ADDR_XOR      0
55   #define WORD_ADDR_XOR      0
56#endif
50#define BYTE_ADDR_XOR      BYTE4_XOR_BE(0)
51#define WORD_ADDR_XOR      (WORD_XOR_BE(0) >> 1)
5752
5853typedef struct
5954{
r936r937
815810      {
816811         switch (tsize)
817812         {
818            case 0: break;
819            case 1: break;   // FIXME?: Extreme-G 2 does this
813            case 0:
814               color->r = color->g = color->b = color->a = 0xff;
815               break;
816            case 1:
817               // FIXME?: Extreme-G 2 does this
818               color->r = color->g = color->b = color->a = 0xff;
819               break;
820820            case PIXEL_SIZE_16BIT:
821821            {
822822               UINT16 *tc = (UINT16*)texture_cache;
r936r937
841841               color->a = ((c >>  0) & 0xff);
842842               break;
843843            }
844            default:      fatalerror("FETCH_TEXEL: unknown RGBA texture size %d\n", tsize); break;
844            default:
845               color->r = color->g = color->b = color->a = 0xff;
846               fatalerror("FETCH_TEXEL: unknown RGBA texture size %d\n", tsize);
847               break;
845848         }
846849         break;
847850      }
r936r937
891894               }
892895               break;
893896            }
894            case 2: break;      // FIXME?: Clay Fighter Sculptor's Cut does this..
895            default:      fatalerror("FETCH_TEXEL: unknown CI texture size %d\n", tsize); break;
897            case 2:
898                // FIXME?: Clay Fighter Sculptor's Cut does this..
899               color->r = color->g = color->b = color->a = 0xff;
900               break;
901            default:
902               color->r = color->g = color->b = color->a = 0xff;
903               fatalerror("FETCH_TEXEL: unknown CI texture size %d\n", tsize);
904               break;
896905         }
897906         break;
898907      }
r936r937
939948               color->a = c & 0xff;
940949               break;
941950            }
942            default:      fatalerror("FETCH_TEXEL: unknown IA texture size %d\n", tsize); break;
951            default:
952               color->r = color->g = color->b = color->a = 0xff;
953               fatalerror("FETCH_TEXEL: unknown IA texture size %d\n", tsize);
954               break;
943955         }
944956         break;
945957      }
r936r937
972984               color->a = c;
973985               break;
974986            }
975            default:      fatalerror("FETCH_TEXEL: unknown I texture size %d\n", tsize); break;
987            default:
988               color->r = color->g = color->b = color->a = 0xff;
989               fatalerror("FETCH_TEXEL: unknown I texture size %d\n", tsize);
990               break;
976991         }
977992         break;
978993      }
979994      default:
980995      {
996         color->r = color->g = color->b = color->a = 0xff;
981997         fatalerror("FETCH_TEXEL: unknown texture format %d\n", tformat);
982998         break;
983999      }
src/mame/video/taito_f2.c
r936r937
368368      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
369369      const rectangle *clip,int scalex, int scaley)
370370{
371   const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
371   const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
372372   UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
373373
374374   int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
src/mame/video/tubep.c
r936r937
664664
665665   /* draw background ram */
666666   {
667      pen_t *pens = &machine->pens[ 32 ]; //change it later
667      const pen_t *pens = &machine->pens[ 32 ]; //change it later
668668
669669      UINT32 h,v;
670670      UINT8 * romBxx = memory_region(REGION_USER1) + 0x2000*background_romsel;
r936r937
778778
779779   /* draw background ram */
780780   {
781      pen_t *pens = &machine->pens[ 0x00 ];
781      const pen_t *pens = &machine->pens[ 0x00 ];
782782
783783      UINT32 h,v;
784784      UINT8 * rom13D  = memory_region(REGION_USER1);
src/mame/video/suprloco.c
r936r937
187187{
188188   int sx,sy,col,row,height,src,adjy,dy;
189189   UINT8 *spr_reg;
190   pen_t *spr_palette;
190   const pen_t *spr_palette;
191191   short skip;   /* bytes to skip before drawing each row (can be negative) */
192192
193193
src/mame/video/vulgus.c
r936r937
1313
1414static int vulgus_palette_bank;
1515static tilemap *fg_tilemap, *bg_tilemap;
16static colortable *vulgus_colortable;
1617
1718
1819/***************************************************************************
r936r937
2425PALETTE_INIT( vulgus )
2526{
2627   int i;
27   #define TOTAL_COLORS(gfxn) (machine->gfx[gfxn]->total_colors * machine->gfx[gfxn]->color_granularity)
28   #define COLOR(gfxn,offs) (colortable[machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
2928
29   vulgus_colortable = colortable_alloc(machine, 256);
3030
31   for (i = 0;i < machine->drv->total_colors;i++)
31   for (i = 0;i < 256;i++)
3232   {
3333      int bit0,bit1,bit2,bit3,r,g,b;
3434
35
3635      bit0 = (color_prom[0] >> 0) & 0x01;
3736      bit1 = (color_prom[0] >> 1) & 0x01;
3837      bit2 = (color_prom[0] >> 2) & 0x01;
3938      bit3 = (color_prom[0] >> 3) & 0x01;
4039      r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
41      bit0 = (color_prom[machine->drv->total_colors] >> 0) & 0x01;
42      bit1 = (color_prom[machine->drv->total_colors] >> 1) & 0x01;
43      bit2 = (color_prom[machine->drv->total_colors] >> 2) & 0x01;
44      bit3 = (color_prom[machine->drv->total_colors] >> 3) & 0x01;
40      bit0 = (color_prom[256] >> 0) & 0x01;
41      bit1 = (color_prom[256] >> 1) & 0x01;
42      bit2 = (color_prom[256] >> 2) & 0x01;
43      bit3 = (color_prom[256] >> 3) & 0x01;
4544      g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
46      bit0 = (color_prom[2*machine->drv->total_colors] >> 0) & 0x01;
47      bit1 = (color_prom[2*machine->drv->total_colors] >> 1) & 0x01;
48      bit2 = (color_prom[2*machine->drv->total_colors] >> 2) & 0x01;
49      bit3 = (color_prom[2*machine->drv->total_colors] >> 3) & 0x01;
45      bit0 = (color_prom[2*256] >> 0) & 0x01;
46      bit1 = (color_prom[2*256] >> 1) & 0x01;
47      bit2 = (color_prom[2*256] >> 2) & 0x01;
48      bit3 = (color_prom[2*256] >> 3) & 0x01;
5049      b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
5150
52      palette_set_color(machine,i,MAKE_RGB(r,g,b));
51      colortable_palette_set_color(vulgus_colortable,i,MAKE_RGB(r,g,b));
5352      color_prom++;
5453   }
5554
56   color_prom += 2*machine->drv->total_colors;
55   color_prom += 2*256;
5756   /* color_prom now points to the beginning of the lookup table */
5857
5958
6059   /* characters use colors 32-47 (?) */
61   for (i = 0;i < TOTAL_COLORS(0);i++)
62      COLOR(0,i) = *(color_prom++) + 32;
60   for (i = 0;i < machine->gfx[0]->total_colors * machine->gfx[0]->color_granularity;i++)
61      colortable_entry_set_value(vulgus_colortable, machine->gfx[0]->color_base + i, 32 + *color_prom++);
6362
6463   /* sprites use colors 16-31 */
65   for (i = 0;i < TOTAL_COLORS(2);i++)
66   {
67      COLOR(2,i) = *(color_prom++) + 16;
68   }
64   for (i = 0;i < machine->gfx[2]->total_colors * machine->gfx[2]->color_granularity;i++)
65      colortable_entry_set_value(vulgus_colortable, machine->gfx[2]->color_base + i, 16 + *color_prom++);
6966
7067   /* background tiles use colors 0-15, 64-79, 128-143, 192-207 in four banks */
71   for (i = 0;i < TOTAL_COLORS(1)/4;i++)
68   for (i = 0;i < machine->gfx[1]->total_colors * machine->gfx[1]->color_granularity / 4;i++)
7269   {
73      COLOR(1,i) = *color_prom;
74      COLOR(1,i+32*8) = *color_prom + 64;
75      COLOR(1,i+2*32*8) = *color_prom + 128;
76      COLOR(1,i+3*32*8) = *color_prom + 192;
70      colortable_entry_set_value(vulgus_colortable, machine->gfx[1]->color_base + 0*32*8 + i, *color_prom);
71      colortable_entry_set_value(vulgus_colortable, machine->gfx[1]->color_base + 1*32*8 + i, *color_prom + 64);
72      colortable_entry_set_value(vulgus_colortable, machine->gfx[1]->color_base + 2*32*8 + i, *color_prom + 128);
73      colortable_entry_set_value(vulgus_colortable, machine->gfx[1]->color_base + 3*32*8 + i, *color_prom + 192);
7774      color_prom++;
7875   }
7976}
r936r937
9693         code + ((color & 0x80) << 1),
9794         color & 0x3f,
9895         0);
96   tileinfo->group = color & 0x3f;
9997}
10098
10199static TILE_GET_INFO( get_bg_tile_info )
r936r937
120118
121119VIDEO_START( vulgus )
122120{
123   fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_COLORTABLE, 8, 8,32,32);
124   bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_TYPE_PEN           ,16,16,32,32);
121   fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN, 8, 8,32,32);
122   bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_TYPE_PEN,16,16,32,32);
125123
126   tilemap_set_transparent_pen(fg_tilemap,47);
124   colortable_configure_tilemap_groups(vulgus_colortable, fg_tilemap, machine->gfx[0], 47);
127125}
128126
129127
src/mame/video/circus.c
r936r937
202202static void ripcord_draw_skydiver(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect)
203203{
204204   const gfx_element *gfx;
205   pen_t *pal_ptr;
205   const pen_t *pal_ptr;
206206   UINT8  *src_lineptr, *src_pixptr;
207207   UINT16 *dst_lineptr, *dst_lineend;
208208   UINT32 code, color;
r936r937
222222   edx = 1;
223223
224224   gfx = machine->gfx[1];
225   pal_ptr = gfx->colortable + color * gfx->color_granularity;
225   pal_ptr = &machine->remapped_colortable[gfx->color_base + color * gfx->color_granularity];
226226   src_lineptr = gfx->gfxdata + code * gfx->char_modulo;
227227   src_pitch = gfx->line_modulo;
228228   dst_pitch = bitmap->rowpixels;
src/mame/video/taito_f3.c
r936r937
13621362      UINT32 orient,
13631363      int skip_layer_num)
13641364{
1365   pen_t *clut = &machine->remapped_colortable[0];
1365   const pen_t *clut = &machine->remapped_colortable[0];
13661366   UINT32 bgcolor=clut[0];
13671367   int length;
13681368
r936r937
26642664   }
26652665
26662666
2667   if( gfx && gfx->colortable )
2667   if( gfx )
26682668   {
2669      const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2669      const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
26702670      int source_base = (code % gfx->total_elements) * 16;
26712671
26722672      {
r936r937
28282828   }
28292829
28302830
2831   if( gfx && gfx->colortable )
2831   if( gfx )
28322832   {
2833      const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2833      const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
28342834      int source_base = (code % gfx->total_elements) * 16;
28352835
28362836      {
src/mame/video/twin16.c
r936r937
357357            */
358358         const UINT16 *gfx_data = gfx_base + (code&0x7ff)*16 + bank_table[(code>>11)&0x3]*0x8000;
359359         int color = (code>>13);
360         pen_t *pal_data = Machine->pens + 16*(0x20+color+8*palette);
360         const pen_t *pal_data = Machine->pens + 16*(0x20+color+8*palette);
361361
362362         {
363363            int y;
src/mame/video/pacman.c
r936r937
2020#include "includes/pacman.h"
2121#include "video/resnet.h"
2222
23static colortable *pacman_colortable;
2324static tilemap *bg_tilemap;
24static UINT8 *transmask;
2525static UINT8 charbank;
2626static UINT8 spritebank;
2727static UINT8 palettebank;
r936r937
8484{
8585   static const int resistances[3] = { 1000, 470, 220 };
8686   double rweights[3], gweights[3], bweights[2];
87   rgb_t palette[32];
8887   int i;
8988
9089   /* compute the color output resistor weights */
r936r937
9392         3, &resistances[0], gweights, 0, 0,
9493         2, &resistances[1], bweights, 0, 0);
9594
95   /* allocate the colortable */
96   pacman_colortable = colortable_alloc(machine, 32);
97
9698   /* create a lookup table for the palette */
9799   for (i = 0; i < 32; i++)
98100   {
r936r937
116118      bit1 = (color_prom[i] >> 7) & 0x01;
117119      b = combine_2_weights(bweights, bit0, bit1);
118120
119      palette[i] = MAKE_RGB(r, g, b);
121      colortable_palette_set_color(pacman_colortable, i, MAKE_RGB(r, g, b));
120122   }
121123
122124   /* color_prom now points to the beginning of the lookup table */
123125   color_prom += 32;
124126
125   /* allocate memory for mask of pens that are transparent in sprites */
126   transmask = auto_malloc(64);
127   memset(transmask, 0, 64);
128
129   /* color table; 64 entries total of 4 colors each */
127   /* allocate the colortable */
130128   for (i = 0; i < 64*4; i++)
131129   {
132130      UINT8 ctabentry = color_prom[i] & 0x0f;
133131
134      /* if this color table entry maps to pen 0, mark the appropriate pens in the transmask */
135      if (ctabentry == 0)
136         transmask[i/4] |= 1 << (i % 4);
137
138132      /* first palette bank */
139      palette_set_color(machine, i, palette[0x00 + ctabentry]);
133      colortable_entry_set_value(pacman_colortable, i, ctabentry);
140134
141135      /* second palette bank */
142      palette_set_color(machine, i + 64*4, palette[0x10 + ctabentry]);
136      colortable_entry_set_value(pacman_colortable, i + 64*4, 0x10 + ctabentry);
143137   }
144138}
145139
r936r937
252246               color,
253247               spriteram[offs] & 1,spriteram[offs] & 2,
254248               sx,sy,
255               &spriteclip,TRANSPARENCY_PENS,transmask[color & 0x3f]);
249               &spriteclip,TRANSPARENCY_PENS,
250               colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color, 0));
256251
257252         /* also plot the sprite with wraparound (tunnel in Crush Roller) */
258253         drawgfx(bitmap,machine->gfx[1],
r936r937
260255               color,
261256               spriteram[offs] & 1,spriteram[offs] & 2,
262257               sx - 256,sy,
263               &spriteclip,TRANSPARENCY_PENS,transmask[color & 0x3f]);
258               &spriteclip,TRANSPARENCY_PENS,
259               colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color, 0));
264260      }
265261      /* In the Pac Man based games (NOT Pengo) the first two sprites must be offset */
266262      /* one pixel to the left to get a more correct placement */
r936r937
278274               color,
279275               spriteram[offs] & 1,spriteram[offs] & 2,
280276               sx,sy + xoffsethack,
281               &spriteclip,TRANSPARENCY_PENS,transmask[color & 0x3f]);
277               &spriteclip,TRANSPARENCY_PENS,
278               colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color, 0));
282279
283280         /* also plot the sprite with wraparound (tunnel in Crush Roller) */
284281         drawgfx(bitmap,machine->gfx[1],
r936r937
286283               color,
287284               spriteram[offs] & 2,spriteram[offs] & 1,
288285               sx - 256,sy + xoffsethack,
289               &spriteclip,TRANSPARENCY_PENS,transmask[color & 0x3f]);
286               &spriteclip,TRANSPARENCY_PENS,
287               colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color, 0));
290288      }
291289   }
292290
r936r937
418416            color,
419417            spriteram[offs] & 1,spriteram[offs] & 2,
420418            sx,sy,
421            cliprect,TRANSPARENCY_PENS,transmask[color & 0x3f]);
419            cliprect,TRANSPARENCY_PENS,
420            colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color & 0x3f, 0));
422421   }
423422   /* In the Pac Man based games (NOT Pengo) the first two sprites must be offset */
424423   /* one pixel to the left to get a more correct placement */
r936r937
438437            color,
439438            spriteram[offs] & 1,spriteram[offs] & 2,
440439            sx,sy + xoffsethack,
441            cliprect,TRANSPARENCY_PENS,transmask[color & 0x3f]);
440            cliprect,TRANSPARENCY_PENS,
441            colortable_get_transpen_mask(pacman_colortable, machine->gfx[1], color & 0x3f, 0));
442442   }
443443   return 0;
444444}
src/mame/video/bwing.c
r936r937
165165
166166#define BW_SET_TILE_INFO(GFX, CODE, COLOR) { \
167167   tileinfo->pen_data = GFX->gfxdata + (CODE) * GFX->char_modulo; \
168   tileinfo->palette_base = (GFX->colortable - Machine->remapped_colortable) + ((COLOR) << 3); \
168   tileinfo->palette_base = GFX->color_base + ((COLOR) << 3); \
169169   }
170170
171171static TILE_GET_INFO( get_fgtileinfo )
src/mame/video/atarigt.c
r936r937
6565static UINT16 *cram, *tram;
6666static UINT32 *mram;
6767
68static pen_t *substitute_pens;
69
6870static UINT32 *expanded_mram;
6971
7072static UINT8 rshift, gshift, bshift;
r936r937
154156   expanded_mram = auto_malloc(sizeof(*expanded_mram) * MRAM_ENTRIES * 3);
155157
156158   /* map pens 1:1 */
159   substitute_pens = auto_malloc(65536 * sizeof(*substitute_pens));
157160   for (i = 0; i < machine->drv->total_colors; i++)
158      machine->pens[i] = i;
161      substitute_pens[i] = i;
162   machine->pens = substitute_pens;
159163
160164   /* compute shift values */
161165   rshift = 16;
src/mame/video/genesis.c
r936r937
426426      case 0x09:
427427      case 0x0a:
428428      case 0x0b:
429         if (ACCESSING_LSB && sndti_to_sndnum(SOUND_SN76496, 0) != -1)
429         if (ACCESSING_LSB && sndti_exists(SOUND_SN76496, 0))
430430            SN76496_0_w(0, data & 0xff);
431431         break;
432432   }
src/mame/video/thepit.c
r936r937
1616size_t thepit_spriteram_size;
1717
1818static UINT8 graphics_bank;
19static UINT8 color_count;
20static int color_granularity;
2119static UINT8 thepit_flip_screen_x;
2220static UINT8 thepit_flip_screen_y;
21static tilemap *thepit_solid_tilemap;
2322static tilemap *thepit_tilemap;
23static UINT8 *dummy_tile;
2424
2525
2626static rectangle spritevisiblearea =
r936r937
5757{
5858   int i;
5959
60   /* allocate primary colors for the background and foreground
61       this is wrong, but I don't know where to pick the colors from */
62   for (i = 0; i < 8; i++)
60   for (i = 0; i < 32; i++)
6361   {
64      palette_set_color_rgb(machine, i, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
65   }
66
67   for (i = 0; i < machine->drv->total_colors - 8; i++)
68   {
6962      int bit0, bit1, bit2, r, g, b;
7063
7164      bit0 = (color_prom[i] >> 0) & 0x01;
r936r937
8376      bit2 = (color_prom[i] >> 7) & 0x01;
8477      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
8578
86      palette_set_color(machine, i + 8, MAKE_RGB(r, g, b));
79      palette_set_color(machine, i, MAKE_RGB(r, g, b));
8780   }
8881
89   /* background priority colors */
90   for (i = 0; i < machine->drv->color_table_len - 32; i++)
91   {
92      colortable[i] = i + 8;
93   }
94
95   /* foreground priority colors - creates solid square */
96   for (i = 0; i < 32; i++)
97   {
98      colortable[machine->drv->color_table_len - 32 + i] = i >> 2;
99   }
82   /* allocate primary colors for the background and foreground
83       this is wrong, but I don't know where to pick the colors from */
84   for (i = 0; i < 8; i++)
85      palette_set_color_rgb(machine, i + 32, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
10086}
10187
10288
r936r937
11197{
11298   int i;
11399
114   /* allocate primary colors for the background and foreground
115       this is wrong, but I don't know where to pick the colors from */
116   for (i = 0; i < 8; i++)
100   for (i = 0; i < 32; i++)
117101   {
118      palette_set_color_rgb(machine, i, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
119   }
120
121   for (i = 0; i < machine->drv->total_colors - 8; i++)
122   {
123102      UINT8 r = ((color_prom[i + 0x20] >> 6) | (color_prom[i + 0x00] << 2)) & 0x1f;
124
125103      UINT8 g = BITSWAP8(color_prom[i + 0x20], 7, 6, 0, 1, 2, 3, 4, 5) & 0x1f;
126
127104      UINT8 b = BITSWAP8(color_prom[i + 0x00], 0, 1, 2, 3, 4, 5, 6, 7) & 0x1f;
128105
129106      palette_set_color_rgb(machine, i + 8, pal5bit(r), pal5bit(g), pal5bit(b));
130107   }
131108
132   for (i = 0;i < machine->drv->color_table_len;i++)
133   {
134      colortable[i] = i + 8;
135   }
136
137   /* background priority colors */
138   for (i = 0; i < machine->drv->color_table_len - 64; i++)
139   {
140      colortable[i] = i + 8;
141   }
142
143   /* foreground priority colors - creates solid square */
144   for (i = 0; i < 64; i++)
145   {
146      colortable[machine->drv->color_table_len - 64 + i] = i >> 3;
147   }
109   /* allocate primary colors for the background and foreground
110       this is wrong, but I don't know where to pick the colors from */
111   for (i = 0; i < 8; i++)
112      palette_set_color_rgb(machine, i + 32, pal1bit(i >> 2), pal1bit(i >> 1), pal1bit(i >> 0));
148113}
149114
150115
r936r937
155120
156121***************************************************************************/
157122
158static TILE_GET_INFO( get_tile_info )
123static TILE_GET_INFO( solid_get_tile_info )
159124{
160   UINT8 fore_color;
161
162   UINT8 code = thepit_videoram[tile_index];
163125   UINT8 back_color = (thepit_colorram[tile_index] & 0x70) >> 4;
164126   int priority = (back_color != 0) && ((thepit_colorram[tile_index] & 0x80) == 0);
127   tileinfo->pen_data = dummy_tile;
128   tileinfo->palette_base = back_color + 32;
129   tileinfo->category = priority;
130}
165131
166   if (priority)
167   {
168      /* foreground - solid square */
169      fore_color = color_count + back_color;
170   }
171   else
172   {
173      /* background */
174      fore_color = thepit_colorram[tile_index] & (color_count - 1);
175132
176      /* set up pen #0 color */
177      machine->gfx[graphics_bank]->colortable[fore_color * color_granularity] = machine->pens[back_color];
178   }
179
133static TILE_GET_INFO( get_tile_info )
134{
135   UINT8 fore_color = thepit_colorram[tile_index] % machine->gfx[0]->total_colors;
136   UINT8 code = thepit_videoram[tile_index];
180137   SET_TILE_INFO(2 * graphics_bank, code, fore_color, 0);
181   tileinfo->category = priority;
182138}
183139
184140
r936r937
189145 *
190146 *************************************/
191147
192static void video_start_common(UINT8 _color_count, int _color_granularity)
148VIDEO_START( thepit )
193149{
150   thepit_solid_tilemap = tilemap_create(solid_get_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,32,32);
151
194152   thepit_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_TYPE_PEN,8,8,32,32);
153   tilemap_set_transparent_pen(thepit_tilemap, 0);
195154
155   tilemap_set_scroll_cols(thepit_solid_tilemap, 32);
196156   tilemap_set_scroll_cols(thepit_tilemap, 32);
197157
198   color_count = _color_count;
199   color_granularity = _color_granularity;
200}
158   dummy_tile = auto_malloc(8*8);
159   memset(dummy_tile, 0, 8*8);
201160
202
203VIDEO_START( thepit )
204{
205   video_start_common(8, 4);
206
207   graphics_bank = 0;   /* not used in this game */
161   graphics_bank = 0;   /* only used in intrepid */
208162}
209163
210164
211VIDEO_START( intrepid )
212{
213   video_start_common(8, 4);
214}
215165
216
217VIDEO_START( suprmous )
218{
219   video_start_common(4, 8);
220
221   graphics_bank = 0;   /* not used in this game */
222}
223
224
225
226166/*************************************
227167 *
228168 *  Memory handlers
r936r937
240180{
241181   thepit_colorram[offset] = data;
242182   tilemap_mark_tile_dirty(thepit_tilemap, offset);
183   tilemap_mark_tile_dirty(thepit_solid_tilemap, offset);
243184}
244185
245186
r936r937
248189   thepit_flip_screen_x = data & 0x01;
249190
250191   tilemap_set_flip(thepit_tilemap, thepit_flip_screen_x ? TILEMAP_FLIPX : 0);
192   tilemap_set_flip(thepit_solid_tilemap, thepit_flip_screen_x ? TILEMAP_FLIPX : 0);
251193}
252194
253195
r936r937
256198   thepit_flip_screen_y = data & 0x01;
257199
258200   tilemap_set_flip(thepit_tilemap, thepit_flip_screen_y ? TILEMAP_FLIPY : 0);
201   tilemap_set_flip(thepit_solid_tilemap, thepit_flip_screen_y ? TILEMAP_FLIPY : 0);
259202}
260203
261204
r936r937
333276
334277         drawgfx(bitmap, machine->gfx[2 * graphics_bank + 1],
335278               thepit_spriteram[offs + 1] & 0x3f,
336               thepit_spriteram[offs + 2] & (color_count - 1),
279               thepit_spriteram[offs + 2],
337280               flipx, flipy, x, y,
338281               thepit_flip_screen_x ? &spritevisibleareaflipx : &spritevisiblearea,
339282               TRANSPARENCY_PEN, 0);
r936r937
349292   for (offs = 0; offs < 32; offs++)
350293   {
351294      tilemap_set_scrolly(thepit_tilemap, offs, thepit_attributesram[offs << 1]);
295      tilemap_set_scrolly(thepit_solid_tilemap, offs, thepit_attributesram[offs << 1]);
352296   }
353297
354298   /* low priority tiles */
299   tilemap_draw(bitmap, cliprect, thepit_solid_tilemap, 0, 0);
355300   tilemap_draw(bitmap, cliprect, thepit_tilemap, 0, 0);
356301
357302   /* low priority sprites */
358303   draw_sprites(machine, bitmap, cliprect, 0);
359304
360305   /* high priority tiles */
361   tilemap_draw(bitmap, cliprect, thepit_tilemap, 1, 1);
306   tilemap_draw(bitmap, cliprect, thepit_solid_tilemap, 1, 1);
362307
363308   /* high priority sprites */
364309   draw_sprites(machine, bitmap, cliprect, 1);
src/mame/video/exerion.c
r936r937
248248      int stop3 = background_latches[11] >> 4;
249249      UINT8 *mixer = &background_mixer[(background_latches[12] << 4) & 0xf0];
250250      UINT8 scanline[VISIBLE_X_MAX];
251      pen_t *pens;
251      const pen_t *pens;
252252
253253      /* the cocktail flip flag controls whether we count up or down in X */
254254      if (!exerion_cocktail_flip)
src/mame/drivers/docastle.c
r936r937
591591   RGN_FRAC(1,1),
592592   4,
593593   { 0, 1, 2, 3 },
594   { 0, 4, 8, 12, 16, 20, 24, 28 },
595   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
594   { STEP8(0,4) },
595   { STEP8(0,32) },
596596   32*8
597597};
598598
r936r937
602602   RGN_FRAC(1,1),
603603   4,
604604   { 0, 1, 2, 3 },
605   { 0, 4, 8, 12, 16, 20, 24, 28,
606         32, 36, 40, 44, 48, 52, 56, 60 },
607   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
608         8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
605   { STEP16(0,4) },
606   { STEP16(0,64) },
609607   128*8
610608};
611609
r936r937
614612static const gfx_decode gfxdecodeinfo[] =
615613{
616614   { REGION_GFX1, 0, &charlayout,       0, 64 },
617   { REGION_GFX2, 0, &spritelayout, 64*16, 32*2 },
615   { REGION_GFX2, 0, &spritelayout,     0, 32*2 },
618616   { -1 }
619617};
620618
r936r937
653651   MDRV_SCREEN_SIZE(32*8, 32*8)
654652   MDRV_SCREEN_VISIBLE_AREA(1*8, 31*8-1, 4*8, 28*8-1)
655653   MDRV_GFXDECODE(gfxdecodeinfo)
656   MDRV_PALETTE_LENGTH(258)
657   MDRV_COLORTABLE_LENGTH(64*16+2*32*16)
654   MDRV_PALETTE_LENGTH(512)
658655
659656   MDRV_PALETTE_INIT(docastle)
660657   MDRV_VIDEO_START(docastle)
r936r937
687684   MDRV_CPU_PROGRAM_MAP(dorunrun_map2, 0)
688685
689686   // video hardware
690   MDRV_PALETTE_INIT(dorunrun)
687   MDRV_VIDEO_START(dorunrun)
691688MACHINE_DRIVER_END
692689
693690static MACHINE_DRIVER_START( idsoccer )
r936r937
701698   MDRV_CPU_PROGRAM_MAP(idsoccer_map2, 0)
702699
703700   // video hardware
704   MDRV_PALETTE_INIT(dorunrun)
701   MDRV_VIDEO_START(dorunrun)
705702
706703   // sound hardware
707704   MDRV_SOUND_ADD(MSM5205, 384000)
src/mame/drivers/hornet.c
r936r937
343343   decodegfx(machine->gfx[K037122_gfx_index[chip]], (UINT8*)K037122_char_ram[chip], 0, machine->gfx[K037122_gfx_index[chip]]->total_elements);
344344
345345   if (machine->drv->color_table_len)
346   {
347      machine->gfx[K037122_gfx_index[chip]]->colortable = machine->remapped_colortable;
348346      machine->gfx[K037122_gfx_index[chip]]->total_colors = machine->drv->color_table_len / 16;
349   }
350347   else
351   {
352      machine->gfx[K037122_gfx_index[chip]]->colortable = machine->pens;
353348      machine->gfx[K037122_gfx_index[chip]]->total_colors = machine->drv->total_colors / 16;
354   }
355349
356350   return 0;
357351}
src/mame/drivers/mediagx.c
r936r937
183183         UINT8 pen = dp[index++];
184184         if (pen)
185185         {
186            p[i] = gfx->colortable[att & 0xf];
186            p[i] = Machine->remapped_colortable[gfx->color_base + (att & 0xf)];
187187         }
188188         else
189189         {
190190            if (((att >> 4) & 7) > 0)
191191            {
192               p[i] = gfx->colortable[(att >> 4) & 0x7];
192               p[i] = Machine->remapped_colortable[gfx->color_base + ((att >> 4) & 0x7)];
193193            }
194194         }
195195      }
src/mame/drivers/seibuspi.c
r936r937
864864   }
865865
866866   // oki banking
867   if (sndti_to_sndnum(SOUND_OKIM6295, 1) >= 0)
867   if (sndti_exists(SOUND_OKIM6295, 1))
868868      OKIM6295_set_bank_base(1, (data & 0x4000000) ? 0x40000 : 0);
869869}
870870
src/mame/drivers/coolpool.c
r936r937
175175{
176176   /* keep track of the last few writes */
177177   memmove(&nvram_write_seq[0], &nvram_write_seq[1], (NVRAM_UNLOCK_SEQ_LEN - 1) * sizeof(nvram_write_seq[0]));
178   nvram_write_seq[NVRAM_UNLOCK_SEQ_LEN - 1] = offset;
178   nvram_write_seq[NVRAM_UNLOCK_SEQ_LEN - 1] = offset & 0x3ff;
179179
180180   /* if they match the unlock sequence, enable writes and set a timeout */
181181   if (!memcmp(nvram_unlock_seq, nvram_write_seq, sizeof(nvram_unlock_seq)))
src/mame/drivers/gaplus.c
r936r937
780780   MDRV_SCREEN_SIZE(36*8, 28*8)
781781   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 0*8, 28*8-1)
782782   MDRV_GFXDECODE(gfxdecodeinfo)
783   MDRV_PALETTE_LENGTH(256)
784   MDRV_COLORTABLE_LENGTH(64*4+64*8)
783   MDRV_PALETTE_LENGTH(64*4+64*8)
785784
786785   MDRV_PALETTE_INIT(gaplus)
787786   MDRV_VIDEO_START(gaplus)
src/mame/drivers/bfm_sc2.c
r936r937
1/***************************************************************************
1/****************************************************************************************
22
3  Bellfruit scorpion2/3 driver, (under heavy construction !!!)
3  bfm_sc2.c
44
5    Bellfruit scorpion2/3 driver, (under heavy construction !!!)
6
7*****************************************************************************************
8
59  30-12-2006: J Wallace: Fixed init routines.
610  07-03-2006: El Condor: Recoded to more accurately represent the hardware setup.
711  18-01-2006: Cleaned up for MAME inclusion
r936r937
7377-----------+---+-----------------+-----------------------------------------
74782336       |?/W| D D D D D D D D | dimcnt ?
7579-----------+---+-----------------+-----------------------------------------
762337       | W | D D D D D D D D | volume overide
802337       | W | D D D D D D D D | volume override
7781-----------+---+-----------------+-----------------------------------------
78822338       | W | D D D D D D D D | payout chip select
7983-----------+---+-----------------+-----------------------------------------
80842339       | W | D D D D D D D D | clkden ?
8185-----------+---+-----------------+-----------------------------------------
822400       |R/W| D D D D D D D D | uart1 (MC6850 compatible) control/status register
862400       |R/W| D D D D D D D D | uart1 (MC6850 compatible) control/status
8387-----------+---+-----------------+-----------------------------------------
842500       |R/W| D D D D D D D D | uart1 (MC6850 compatible) data register
882500       |R/W| D D D D D D D D | uart1 (MC6850 compatible) data
8589-----------+---+-----------------+-----------------------------------------
862600       |R/W| D D D D D D D D | uart2 (MC6850 compatible) control/status register
902600       |R/W| D D D D D D D D | uart2 (MC6850 compatible) control/status
8791-----------+---+-----------------+-----------------------------------------
882700       |R/W| D D D D D D D D | uart2 (MC6850 compatible) data register
922700       |R/W| D D D D D D D D | uart2 (MC6850 compatible) data
8993-----------+---+-----------------+-----------------------------------------
90942800       |R/W| D D D D D D D D | vfd1
9195-----------+---+-----------------+-----------------------------------------
r936r937
120124
121125Adder hardware:
122126    Games supported:
123        * Quintoon (2 sets Dutch, 1 set UK)
124        * Quintoon (UK) (1 set)
127        * Quintoon (2 sets Dutch, 2 sets UK)
125128        * Pokio (1 set)
126129        * Paradice (1 set)
127130        * Pyramid (1 set)
r936r937
130133
131134    Known issues:
132135        * Need to find the 'missing' game numbers
133
136        * Fix RS232 protocol
134137***************************************************************************/
135138
136139#include "driver.h"
r936r937
162165#ifdef MAME_DEBUG
163166#define LOG_SERIAL(x) logerror x   // log serial communication between mainboard (scorpion2) and videoboard (adder2)
164167#define UART_LOG(x) logerror x      //enable UART data logging
168#define LOG(x) logerror x
165169#else
166170#define LOG_SERIAL(x)
167171#define UART_LOG(x)
172#define LOG(x)
168173#endif
169174
170175// local prototypes ///////////////////////////////////////////////////////
r936r937
180185
181186// local vars /////////////////////////////////////////////////////////////
182187
183static UINT8 *nvram;     // pointer to NV ram
184static size_t        nvram_size; // size of NV ram
185static UINT8 key[16];   // security device on gamecard (video games only)
188static UINT8 *nvram;      // pointer to NVRAM
189static size_t nvram_size;   // size of NVRAM
190static UINT8 key[16];      // security device on gamecard (video games only)
186191
187static UINT8 e2ram[1024]; // x24C08 e2ram
192static UINT8 e2ram[1024];   // x24C08 e2ram
188193
189static int mmtr_latch;        // mechanical meter latch
190static int triac_latch;        // payslide triac latch
191static int vfd1_latch;        // vfd1 latch
192static int vfd2_latch;        // vfd2 latch
193static int irq_status;        // custom chip IRQ status
194static int optic_pattern;     // reel optics
195static int uart1_status;     // MC6850 status
196static int uart2_status;     // MC6850 status
197static int locked;           // hardware lock/unlock status (0=unlocked)
194static int mmtr_latch;      // mechanical meter latch
195static int triac_latch;      // payslide triac latch
196static int vfd1_latch;      // vfd1 latch
197static int vfd2_latch;      // vfd2 latch
198static int irq_status;      // custom chip IRQ status
199static int optic_pattern;   // reel optics
200static int uart1_data;
201static int uart2_data;
202static int data_to_uart1;
203static int data_to_uart2;
204static int locked;         // hardware lock/unlock status (0=unlocked)
198205static int timer_enabled;
199206static int reel_changed;
200207static int coin_inhibits;
201208static int irq_timer_stat;
202209static int expansion_latch;
203static int global_volume;     // 0-31
204static int volume_override;     // 0 / 1
210static int global_volume;   // 0-31
211static int volume_override;   // 0 / 1
205212
206static int sc2_show_door;         // flag <>0, show door state
207static int sc2_door_state;         // door switch strobe/data
213static int sc2_show_door;   // flag <>0, show door state
214static int sc2_door_state;   // door switch strobe/data
208215
209216static int reel12_latch;
210217static int reel34_latch;
r936r937
214221static int slide_states[6];
215222static int slide_pay_sensor[6];
216223
217static int has_hopper;        // flag <>0, scorpion2 board has hopper connected
224static int has_hopper;      // flag <>0, scorpion2 board has hopper connected
218225
219226static int triac_select;
220227
221static int hopper_running;      // flag <>0, hopper is running used in some scorpion2 videogames
222static int hopper_coin_sense;   // hopper coin sense state
223static int timercnt;         // timer counts up every IRQ (=1000 times a second)
228static int hopper_running;   // flag <>0, hopper is running used in some scorpion2 videogames
229static int hopper_coin_sense;
230static int timercnt;      // timer counts up every IRQ (=1000 times a second)
224231
225232static int watchdog_cnt;
226233static int watchdog_kicked;
227234
228235// user interface stuff ///////////////////////////////////////////////////
229236
230static UINT8 Lamps[256];      // 256 multiplexed lamps
231static UINT8 sc2_Inputs[64];   // ??  multiplexed inputs,
232                        // need to be hooked to buttons
237static UINT8 Lamps[256];
238static UINT8 sc2_Inputs[64];
233239
234240static UINT8 input_override[64];// bit pattern, bit set means this input is overriden and cannot be changed with switches
235241
r936r937
254260
255261static void send_to_adder(int data)
256262{
257   adder2_data_from_sc2 = 1;      // set flag, data from scorpion2 board available
258   adder2_sc2data       = data;   // store data
263   adder2_data_from_sc2 = 1;
264   adder2_sc2data       = data;
259265
260   adder2_acia_triggered = 1;      // set flag, acia IRQ triggered
261   cpunum_set_input_line(1, M6809_IRQ_LINE, HOLD_LINE );   // trigger IRQ
266   adder2_acia_triggered = 1;
267   cpunum_set_input_line(1, M6809_IRQ_LINE, HOLD_LINE );
262268
263269   LOG_SERIAL(("sadder  %02X  (%c)\n",data, data ));
264270}
r936r937
268274static int receive_from_adder(void)
269275{
270276   int data = adder2_data;
271   adder2_data_to_sc2 = 0;     // clr flag, data from adder available
277   adder2_data_to_sc2 = 0;
272278
273279   LOG_SERIAL(("radder:  %02X(%c)\n",data, data ));
274280
r936r937
281287{
282288   int status = 0;
283289
284   if ( adder2_data_to_sc2  ) status |= 0x01; // receive  buffer full
290   if ( adder2_data_to_sc2  ) status |= 0x01;   // receive  buffer full
285291   if ( !adder2_data_from_sc2) status |= 0x02; // transmit buffer empty
286292
287293   return status;
r936r937
351357
352358   }
353359
354   uart1_status  = 0x02; // MC6850 transmit buffer empty !!!
355   uart2_status  = 0x02; // MC6850 transmit buffer empty !!!
356   locked        = 0;   // hardware is NOT locked
360   locked        = 0;
357361
358362   // make sure no inputs are overidden ////////////////////////////////////
359363   memset(input_override, 0, sizeof(input_override));
r936r937
374378
375379static void Scorpion2_SetSwitchState(int strobe, int data, int state)
376380{
377   //logerror("setstate(%0x:%0x, %d) ", strobe, data, state);
378381   if ( strobe < 11 && data < 8 )
379382   {
380383      if ( strobe < 8 )
r936r937
382385         input_override[strobe] |= (1<<data);
383386
384387         if ( state ) sc2_Inputs[strobe] |=  (1<<data);
385         else         sc2_Inputs[strobe] &= ~(1<<data);
386
387          //logerror("override[%02x] = %02x %02x\n", strobe, input_override[strobe], sc2_Inputs[strobe]);
388         else       sc2_Inputs[strobe] &= ~(1<<data);
388389      }
389390      else
390391      {
r936r937
394395
395396            if ( state ) sc2_Inputs[strobe-8+4] |=  (1<<(data+2));
396397            else       sc2_Inputs[strobe-8+4] &= ~(1<<(data+2));
397
398            //logerror("override[%02x] = %02x %02x\n", strobe-8+4, input_override[strobe-8+4], sc2_Inputs[strobe-8+4]);
399398         }
400399         else
401400         {
r936r937
403402
404403            if ( state ) sc2_Inputs[strobe-8] |=  (1 << (data+5));
405404            else       sc2_Inputs[strobe-8] &= ~(1 << (data+5));
406
407            //logerror("override[%02x] = %02x %02x\n", strobe-8, input_override[strobe-8], sc2_Inputs[strobe-8]);
408405         }
409406      }
410407   }
r936r937
441438
442439static NVRAM_HANDLER( bfm_sc2 )
443440{
441   static const UINT8 init_e2ram[10] = { 1, 4, 10, 20, 0, 1, 1, 4, 10, 20 };
444442   if ( read_or_write )
445443   {   // writing
446444      mame_fwrite(file,nvram,nvram_size);
r936r937
457455      {
458456         memset(nvram,0x00,nvram_size);
459457         memset(e2ram,0x00,sizeof(e2ram));
460         e2ram[ 0] =  1;
461         e2ram[ 1] =  4;
462         e2ram[ 2] = 10;
463         e2ram[ 3] = 20;
464         e2ram[ 4] =  0;
465         e2ram[ 5] =  1;
466         e2ram[ 6] =  1;
467         e2ram[ 7] =  4;
468         e2ram[ 8] = 10;
469         e2ram[ 9] = 20;
470         e2ram[10] =  0;
458         memcpy(e2ram,init_e2ram,sizeof(init_e2ram));
471459      }
472460   }
473461}
r936r937
483471
484472static WRITE8_HANDLER( ram_w )
485473{
486   nvram[offset] = data;     // write to RAM
474   nvram[offset] = data;   // write to RAM
487475}
488476
489477///////////////////////////////////////////////////////////////////////////
r936r937
504492
505493static INTERRUPT_GEN( timer_irq )
506494{
495   timercnt++;
496
507497   if ( watchdog_kicked )
508498   {
509499      watchdog_cnt    = 0;
r936r937
625615      if ( Mechmtr_update(0, cycles, data & 0x01 ) )
626616      {
627617         sc2gui_update_mmtr |= 0x01;
628         logerror("meter %d = %ld\n", 1, MechMtr_Getcount(0) );
629618      }
630619   }
631620
r936r937
634623      if ( Mechmtr_update(1, cycles, data & 0x02 ) )
635624      {
636625         sc2gui_update_mmtr |= 0x02;
637         logerror("meter %d = %ld\n", 2, MechMtr_Getcount(1) );
638626      }
639627   }
640628
r936r937
643631      if ( Mechmtr_update(2, cycles, data & 0x04 ) )
644632      {
645633         sc2gui_update_mmtr |= 0x04;
646         logerror("meter %d = %ld\n", 3, MechMtr_Getcount(2) );
647634      }
648635   }
649636
r936r937
652639      if ( Mechmtr_update(3, cycles, data & 0x08 ) )
653640      {
654641         sc2gui_update_mmtr |= 0x08;
655         logerror("meter %d = %ld\n", 4, MechMtr_Getcount(3) );
656642      }
657643   }
658644
r936r937
662648      if ( Mechmtr_update(4, cycles, data & 0x10 ) )
663649      {
664650         sc2gui_update_mmtr |= 0x10;
665         logerror("meter %d = %ld\n", 5, MechMtr_Getcount(4) );
666651      }
667652   }
668653
r936r937
671656      if ( Mechmtr_update(5, cycles, data & 0x20 ) )
672657      {
673658         sc2gui_update_mmtr |= 0x20;
674         logerror("meter %d = %ld\n", 6, MechMtr_Getcount(5) );
675659      }
676660   }
677661
r936r937
680664      if ( Mechmtr_update(6, cycles, data & 0x40 ) )
681665      {
682666         sc2gui_update_mmtr |= 0x40;
683         logerror("meter %d = %ld\n", 7, MechMtr_Getcount(6) );
684667      }
685668   }
686669
r936r937
689672      if ( Mechmtr_update(7, cycles, data & 0x80 ) )
690673      {
691674         sc2gui_update_mmtr |= 0x80;
692         logerror("meter %d = %ld\n", 8, MechMtr_Getcount(7) );
693675      }
694676   }
695677
r936r937
703685   int i;
704686   int off = offset<<3;
705687
706   Lamps[ off   ] = (data & 0x01) != 0;
707   Lamps[ off+1 ] = (data & 0x02) != 0;
708   Lamps[ off+2 ] = (data & 0x04) != 0;
709   Lamps[ off+3 ] = (data & 0x08) != 0;
710   Lamps[ off+4 ] = (data & 0x10) != 0;
711   Lamps[ off+5 ] = (data & 0x20) != 0;
712   Lamps[ off+6 ] = (data & 0x40) != 0;
713   Lamps[ off+7 ] = (data & 0x80) != 0;
714
688   for (i=0; i<8; i++)
689   {
690      Lamps[ off+i ] = (data & (1 << i)) != 0;
691   }
715692   if (offset == 0) // update all lamps after strobe 0 has been updated (HACK)
716693   {
717694      for ( i = 0; i < 256; i++ )
r936r937
727704{
728705   int result = 0xFF,t1,t2;
729706
730   switch ( offset )
707   if (offset < 8)
731708   {
732      case 0:
733      case 1:
734      case 2:
735      case 3:
736         t1 = input_override[offset];   // strobe 0-3 data 0-4
737         t2 = input_override[offset+8];   // strobe 8-B data 0-2
709      int idx = (offset & 4) ? 4 : 8;
710      t1 = input_override[offset];   // strobe 0-7 data 0-4
711      t2 = input_override[offset+idx];   // strobe 8-B data 0-4
738712
739         t1 = (sc2_Inputs[offset]   & t1) | ( ( readinputport(offset+1)   & ~t1) & 0x1F);
713      t1 = (sc2_Inputs[offset]   & t1) | ( ( readinputport(offset+1)   & ~t1) & 0x1F);
714      if (idx == 8)
740715         t2 = (sc2_Inputs[offset+8] & t2) | ( ( readinputport(offset+1+8) & ~t2) << 5);
741
742         sc2_Inputs[offset]   = (sc2_Inputs[offset]   & ~0x1F) | t1;
743         sc2_Inputs[offset+8] = (sc2_Inputs[offset+8] & ~0x60) | t2;
744         result = t1 | t2;
745         break;
746
747      case 4:
748      case 5:
749      case 6:
750      case 7:
751         t1 = input_override[offset];   // strobe 4-7 data 0-4
752         t2 = input_override[offset+4];   // strobe 8-B data 3-4
753
754         t1 =  (sc2_Inputs[offset]   & t1) | ( ( readinputport(offset+1)     & ~t1) & 0x1F);
716      else
755717         t2 =  (sc2_Inputs[offset+4] & t2) | ( ( ( readinputport(offset+1+4) & ~t2) << 2) & 0x60);
756718
757         sc2_Inputs[offset]   = (sc2_Inputs[offset]   & ~0x1F) | t1;
758         sc2_Inputs[offset+4] = (sc2_Inputs[offset+4] & ~0x60) | t2;
759         result =  t1 | t2;
760         break;
761
762      default:
763         logerror("read strobe %d\n", offset);
719      sc2_Inputs[offset]   = (sc2_Inputs[offset]   & ~0x1F) | t1;
720      sc2_Inputs[offset+idx] = (sc2_Inputs[offset+idx] & ~0x60) | t2;
721      result = t1 | t2;
764722   }
765723
766724   return result;
r936r937
825783   if ( data & 0x80 )         bank |= 0x01;
826784   if ( expansion_latch & 2 ) bank |= 0x02;
827785
828   //logerror("start sound %d bank %d\n", data, bank);
829786   upd7759_set_bank_base(0, bank*0x20000);
830787
831788   upd7759_port_w(0, data&0x3F);   // setup sample
r936r937
978935      if ( changed & p )
979936      { // this inhibit line has changed
980937         coin_lockout_w(i, (~data & p) ); // update lockouts
981
982         //logerror("lockout %d, %s\n", i, data&p?"OFF":"ON");
983
984938         changed &= ~p;
985939      }
986940
r936r937
996950   return 0;
997951}
998952
999
1000953///////////////////////////////////////////////////////////////////////////
1001954
1002955static READ8_HANDLER( coin_input_r )
r936r937
11131066
11141067static READ8_HANDLER( uart1stat_r )
11151068{
1116   return uart1_status;
1117}
1069   int status = 0x06;
11181070
1071   if ( data_to_uart1  ) status |= 0x01;
1072   if ( !data_to_uart2 ) status |= 0x02;
1073
1074   return status;
1075}
11191076///////////////////////////////////////////////////////////////////////////
11201077
11211078static READ8_HANDLER( uart1data_r )
11221079{
1123   return 0x06; //for now
1080   return uart1_data;
11241081}
11251082
1126///////////////////////////////////////////////////////////////////////////
1083//////////////////////////////////////////////////////////////////////////
11271084
11281085static WRITE8_HANDLER( uart1ctrl_w )
11291086{
1087   UART_LOG(("uart1ctrl:%x\n", data));
11301088}
1131
11321089///////////////////////////////////////////////////////////////////////////
11331090
11341091static WRITE8_HANDLER( uart1data_w )
11351092{
1136   UART_LOG(("uart1:%c\n", data));
1093   data_to_uart2 = 1;
1094   uart1_data    = data;
1095   UART_LOG(("uart1:%x\n", data));
11371096}
1138
11391097///////////////////////////////////////////////////////////////////////////
11401098
11411099static READ8_HANDLER( uart2stat_r )
11421100{
1143   return uart2_status;
1144}
1101   int status = 0x06;
11451102
1103   if ( data_to_uart2  ) status |= 0x01;
1104   if ( !data_to_uart1 ) status |= 0x02;
1105
1106   return status;
1107}
11461108///////////////////////////////////////////////////////////////////////////
11471109
11481110static READ8_HANDLER( uart2data_r )
11491111{
1150   return 0x06;
1112   return uart2_data;
11511113}
11521114
11531115///////////////////////////////////////////////////////////////////////////
11541116
11551117static WRITE8_HANDLER( uart2ctrl_w )
11561118{
1119   UART_LOG(("uart2ctrl:%x\n", data));
11571120}
11581121
11591122///////////////////////////////////////////////////////////////////////////
11601123
11611124static WRITE8_HANDLER( uart2data_w )
11621125{
1163   UART_LOG(("uart2:%c\n", data));
1126   data_to_uart1 = 1;
1127   uart2_data    = data;
1128   UART_LOG(("uart2:%x\n", data));
11641129}
11651130
11661131///////////////////////////////////////////////////////////////////////////
r936r937
12611226
12621227         e2data_to_read <<= 1;
12631228
1264         logerror("  e2d pin= %d\n", e2data_pin);
1229         LOG(("e2d pin= %d\n", e2data_pin));
12651230
12661231         e2cnt++;
12671232         if ( e2cnt >= 8 )
r936r937
13041269
13051270   e2reg = data;
13061271
1307   // logerror("e2: D:%d C:%d [%d]:%d\n", data&SDA?1:0, data&SCL?1:0, e2state, e2cnt );
1308
13091272   if ( changed )
13101273   {
13111274      while ( 1 )
r936r937
13161279         {   // X24C08 Start condition (1->0 on SDA while SCL=1)
13171280            e2dummywrite = ( e2state == 5 );
13181281
1319            logerror("e2ram:   c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, e2dummywrite );
1282            LOG(("e2ram:   c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, e2dummywrite ));
13201283
13211284            e2state = 1; // ready for commands
13221285            e2cnt   = 0;
r936r937
13281291            ( !(changed & SCL) && (data & SCL) )     // SCL=1 and not changed
13291292            )
13301293         {   // X24C08 Stop condition (0->1 on SDA while SCL=1)
1331            logerror("e2ram:   c:%d d:%d Stop condition\n", (data & SCL)?1:0, (data&SDA)?1:0 );
1294            LOG(("e2ram:   c:%d d:%d Stop condition\n", (data & SCL)?1:0, (data&SDA)?1:0 ));
13321295            e2state = 0;
13331296            e2data  = 0;
13341297            break;
r936r937
13441307                  e2cnt   = 0;
13451308                  e2rw    = e2data & 1;
13461309
1347                  logerror("e2ram: Slave address received !!  device id=%01X device adr=%01d high order adr %0X RW=%d) %02X\n",
1348                     e2data>>4, (e2data & 0x08)?1:0, (e2data>>1) & 0x03, e2rw , e2data );
1310                  LOG(("e2ram: Slave address received !!  device id=%01X device adr=%01d high order adr %0X RW=%d) %02X\n",
1311                     e2data>>4, (e2data & 0x08)?1:0, (e2data>>1) & 0x03, e2rw , e2data ));
13491312
13501313                  e2state = 2;
13511314               }
r936r937
13601323
13611324                  if ( ack < 0 )
13621325                  {
1363                     logerror(" ACK = 0\n");
1326                     LOG(("ACK = 0\n"));
13641327                     e2state = 0;
13651328                  }
13661329                  else
13671330                  {
1368                     logerror(" ACK = 1\n");
1331                     LOG(("ACK = 1\n"));
13691332                     if ( e2dummywrite )
13701333                     {
13711334                        e2dummywrite = 0;
r936r937
13831346                     switch ( e2state )
13841347                     {
13851348                        case 7:
1386                           logerror(" read address %04X\n",e2address);
1349                           LOG(("read address %04X\n",e2address));
13871350                           e2data_to_read = e2ram[e2address];
13881351                           break;
13891352                        case 3:
1390                           logerror(" write, awaiting address\n");
1353                           LOG(("write, awaiting address\n"));
13911354                           break;
13921355                        default:
1393                           logerror(" ?unknow action %04X\n",e2address);
1356                           LOG(("?unknow action %04X\n",e2address));
13941357                           break;
13951358                     }
13961359                  }
r936r937
14051368                  e2data_pin = 0;
14061369                  e2address = (e2address & 0xFF00) | e2data;
14071370
1408                  logerror("  write address = %04X waiting for ACK\n", e2address);
1371                  LOG(("write address = %04X waiting for ACK\n", e2address));
14091372                  e2state = 4;
14101373                  e2cnt   = 0;
14111374                  e2data  = 0;
r936r937
14221385                  if ( ack < 0 )
14231386                  {
14241387                     e2state = 0;
1425                     logerror("  ACK = 0, cancel write\n" );
1388                     LOG(("ACK = 0, cancel write\n" ));
14261389                  }
14271390                  else
14281391                  {
14291392                     e2state = 5;
1430                     logerror("  ACK = 1, awaiting data to write\n" );
1393                     LOG(("ACK = 1, awaiting data to write\n" ));
14311394                  }
14321395               }
14331396               break;
r936r937
14351398            case 5: // receive data to write
14361399               if ( recdata(changed, data) )
14371400               {
1438                  logerror("  write data = %02X received, awaiting ACK\n", e2data);
1401                  LOG(("write data = %02X received, awaiting ACK\n", e2data));
14391402                  e2cnt   = 0;
14401403                  e2state = 6;  // wait ack
14411404               }
r936r937
14491412                  if ( ack < 0 )
14501413                  {
14511414                     e2state = 0;
1452                     logerror("  ACK=0, write canceled\n");
1415                     LOG(("ACK=0, write canceled\n"));
14531416                  }
14541417                  else
14551418                  {
1456                     logerror("  ACK=1, writeing %02X to %04X\n", e2data, e2address);
1419                     LOG(("ACK=1, writing %02X to %04X\n", e2data, e2address));
14571420
14581421                     e2ram[e2address] = e2data;
14591422
r936r937
14701433               {
14711434                  //e2data_pin = 0;
14721435
1473                  logerror("  address read, data = %02X waiting for ACK\n", e2data );
1436                  LOG(("address read, data = %02X waiting for ACK\n", e2data ));
14741437
14751438                  e2state = 8;
14761439               }
r936r937
14861449
14871450                  e2data_to_read = e2ram[e2address];
14881451
1489                  logerror("  ready for next address %04X\n", e2address);
1452                  LOG(("ready for next address %04X\n", e2address));
14901453
14911454                  e2cnt   = 0;
14921455                  e2data  = 0;
r936r937
14951458
14961459            case 0:
14971460
1498               logerror("e2ram: ? c:%d d:%d\n", (data & SCL)?1:0, (data&SDA)?1:0 );
1461               LOG(("e2ram: ? c:%d d:%d\n", (data & SCL)?1:0, (data&SDA)?1:0 ));
14991462               break;
15001463            }
15011464         break;
r936r937
15051468
15061469static int read_e2ram(void)
15071470{
1508   logerror("e2ram: r %d (%02X) \n", e2data_pin, e2data_to_read );
1471   LOG(("e2ram: r %d (%02X) \n", e2data_pin, e2data_to_read ));
15091472
15101473   return e2data_pin;
15111474}
r936r937
15931556   //BFM_dm01_reset(); No known video based game has a Matrix board
15941557}
15951558
1559static VIDEO_UPDATE( addersc2 )
1560{
1561   if ( sc2_show_door )
1562   {
1563      output_set_value("door",( Scorpion2_GetSwitchState(sc2_door_state>>4, sc2_door_state & 0x0F) ) );
1564   }
1565
1566   return video_update_adder2(machine,screen,bitmap,cliprect);
1567}
1568
15961569// memory map for scorpion2 board video addon /////////////////////////////
15971570
15981571static ADDRESS_MAP_START( memmap_vid, ADDRESS_SPACE_PROGRAM, 8 )
r936r937
22752248
22762249INPUT_PORTS_END
22772250
2251// input ports for UK quintoon (older)/////////////////////////////////////
2252
2253static INPUT_PORTS_START( quintono )
2254   PORT_INCLUDE(quintoon)
2255   PORT_MODIFY("STROBE10")
2256   PORT_DIPNAME( 0x10, 0x00, "Stake per Game / Jackpot" )PORT_DIPLOCATION("DIL:11")
2257   PORT_DIPSETTING(    0x00, "20p / 6 Pounds" )
2258   PORT_DIPSETTING(    0x10, "50p / 20 Pounds" )
2259INPUT_PORTS_END
2260
22782261// input ports for slotsnl  ///////////////////////////////////////////////
22792262
22802263static INPUT_PORTS_START( slotsnl )
r936r937
30533036///////////////////////////////////////////////////////////////////////////
30543037
30553038static MACHINE_DRIVER_START( scorpion2_vid )
3056   MDRV_MACHINE_RESET( init )            // main scorpion2 board initialisation
3039   MDRV_MACHINE_RESET( init )                     // main scorpion2 board initialisation
30573040   MDRV_INTERLEAVE(16)                           // needed for serial communication !!
3058
3059   MDRV_CPU_ADD_TAG("main", M6809, 2000000 )            // 6809 CPU at 2 Mhz
3041   MDRV_CPU_ADD_TAG("main", M6809, 2000000 )         // 6809 CPU at 2 Mhz
30603042   MDRV_CPU_PROGRAM_MAP(memmap_vid,0)               // setup scorpion2 board memorymap
30613043   MDRV_CPU_PERIODIC_INT(timer_irq, 1000)            // generate 1000 IRQ's per second
3044
30623045   MDRV_NVRAM_HANDLER(bfm_sc2)
30633046   MDRV_DEFAULT_LAYOUT(layout_bfm_sc2)
30643047
r936r937
30683051   MDRV_SCREEN_SIZE( 400, 280)
30693052   MDRV_SCREEN_VISIBLE_AREA(  0, 400-1, 0, 280-1)
30703053   MDRV_SCREEN_REFRESH_RATE(50)
3054
30713055   MDRV_VIDEO_START( adder2)
30723056   MDRV_VIDEO_RESET( adder2)
3073   MDRV_VIDEO_UPDATE(adder2)
3057   MDRV_VIDEO_UPDATE(addersc2)
30743058
30753059   MDRV_PALETTE_LENGTH(16)
30763060   MDRV_COLORTABLE_LENGTH(16)
r936r937
31183102
31193103// UK quintoon initialisation ////////////////////////////////////////////////
31203104
3121static DRIVER_INIT( quintoon )
3105static DRIVER_INIT (quintoon)
31223106{
31233107   sc2_common_init();
31243108   adder2_decode_char_roms();
3125   Mechmtr_init(8);   // setup mech meters
3109   Mechmtr_init(8);               // setup mech meters
31263110
31273111   has_hopper = 0;
31283112
3129   Scorpion2_SetSwitchState(3,0,1);     // tube1 level switch
3130   Scorpion2_SetSwitchState(3,1,1);     // tube2 level switch
3131   Scorpion2_SetSwitchState(3,2,1);     // tube3 level switch
3113   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
3114   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
3115   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
31323116
31333117   Scorpion2_SetSwitchState(5,2,1);
31343118   Scorpion2_SetSwitchState(6,4,1);
r936r937
31423126static DRIVER_INIT( pyramid )
31433127{
31443128   sc2_common_init();
3145   adder2_decode_char_roms();        // decode GFX roms
3129   adder2_decode_char_roms();         // decode GFX roms
31463130   adder2_common_init();
31473131
31483132   has_hopper = 1;
31493133
3150   Scorpion2_SetSwitchState(3,0,1);     // tube1 level switch
3151   Scorpion2_SetSwitchState(3,1,1);     // tube2 level switch
3152   Scorpion2_SetSwitchState(3,2,1);     // tube3 level switch
3134   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
3135   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
3136   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
31533137
31543138   sc2_show_door   = 1;
31553139   sc2_door_state  = 0x41;
r936r937
31593143static DRIVER_INIT( sltsbelg )
31603144{
31613145   sc2_common_init();
3162   adder2_decode_char_roms();        // decode GFX roms
3146   adder2_decode_char_roms();         // decode GFX roms
31633147   adder2_common_init();
31643148
31653149   has_hopper = 1;
r936r937
31733157static DRIVER_INIT( adder_dutch )
31743158{
31753159   sc2_common_init();
3176   adder2_decode_char_roms();        // decode GFX roms
3160   adder2_decode_char_roms();         // decode GFX roms
31773161   adder2_common_init();
31783162
31793163   has_hopper = 0;
31803164
3181   Scorpion2_SetSwitchState(3,0,1);     // tube1 level switch
3182   Scorpion2_SetSwitchState(3,1,1);     // tube2 level switch
3183   Scorpion2_SetSwitchState(3,2,1);     // tube3 level switch
3165   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
3166   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
3167   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
31843168
31853169   sc2_show_door   = 1;
31863170   sc2_door_state  = 0x41;
r936r937
31913175static DRIVER_INIT( gldncrwn )
31923176{
31933177   sc2_common_init();
3194   adder2_decode_char_roms();        // decode GFX roms
3178   adder2_decode_char_roms();         // decode GFX roms
31953179   adder2_common_init();
31963180
31973181   has_hopper = 0;
31983182
3199   Scorpion2_SetSwitchState(3,0,1);     // tube1 level switch
3200   Scorpion2_SetSwitchState(3,1,1);     // tube2 level switch
3201   Scorpion2_SetSwitchState(3,2,1);     // tube3 level switch
3183   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
3184   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
3185   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
32023186
32033187   sc2_show_door   = 0;
32043188   sc2_door_state  = 0x41;
32053189}
32063190
3207// ROM definition UK Quintoon /////////////////////////////////////////////
3191// ROM definition UK Quintoon ////////////////////////////////////////////
32083192
32093193ROM_START( quintoon )
3210   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3211   ROM_LOAD( "95750203.bin",   0x0000, 0x10000,  CRC(037ef2d0) SHA1(6958624e29629a7639a80e8929b833a8b0201833))
3194   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3195   ROM_LOAD("95750206.p1",   0x00000, 0x10000,  CRC(05f4bfad) SHA1(22751573f3a51a9fd2d2a75a7d1b20d78112e0bb))
32123196
32133197   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3214   ROM_LOAD( "quinp132", 0x0000, 0x20000,  CRC(63896a7f) SHA1(81aa56874a15faa3aabdfc0fc524b2e25b751f22))
3198   ROM_LOAD("quinp132",      0x00000, 0x20000,  CRC(63896a7f) SHA1(81aa56874a15faa3aabdfc0fc524b2e25b751f22))
32153199
3216   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples - using Dutch version, need to check a UK Quintoon PCB
3217   ROM_LOAD( "95001016.snd", 0x00000, 0x20000, BAD_DUMP CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
3200   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // using Dutch samples, need to check a UK Quintoon PCB
3201   ROM_LOAD("95001016.snd",   0x00000, 0x20000, BAD_DUMP CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
32183202
32193203   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3220   ROM_LOAD( "quinp233",0x00000, 0x20000, CRC(3d4ebecf) SHA1(b339cf16797ccf7a1ec20fcebf52b6edad9a1047))
3204   ROM_LOAD("quinp233",      0x00000, 0x20000, CRC(3d4ebecf) SHA1(b339cf16797ccf7a1ec20fcebf52b6edad9a1047))
3205ROM_END
32213206
3207// ROM definition UK Quintoon (older) ////////////////////////////////////
3208
3209ROM_START( quintono )
3210   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3211   ROM_LOAD("95750203.bin",   0x00000, 0x10000,  CRC(037ef2d0) SHA1(6958624e29629a7639a80e8929b833a8b0201833))
3212
3213   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3214   ROM_LOAD("quinp132",      0x00000, 0x20000,  CRC(63896a7f) SHA1(81aa56874a15faa3aabdfc0fc524b2e25b751f22))
3215
3216   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // using Dutch samples, need to check a UK Quintoon PCB
3217   ROM_LOAD("95001016.snd",   0x00000, 0x20000, BAD_DUMP CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
3218
3219   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3220   ROM_LOAD("quinp233",      0x00000, 0x20000, CRC(3d4ebecf) SHA1(b339cf16797ccf7a1ec20fcebf52b6edad9a1047))
32223221ROM_END
32233222
32243223// ROM definition Dutch Quintoon ///////////////////////////////////////////
32253224
32263225ROM_START( qntoond )
3227   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3228   ROM_LOAD( "95750243.bin", 0x0000, 0x10000, CRC(36a8dcd1) SHA1(ab21301312fbb6609f850e1cf6bcda5a2b7f66f5))
3226   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3227   ROM_LOAD("95750243.bin", 0x00000, 0x10000, CRC(36a8dcd1) SHA1(ab21301312fbb6609f850e1cf6bcda5a2b7f66f5))
32293228
32303229   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3231   ROM_LOAD( "95770024.vid", 0x0000, 0x20000, CRC(5bc7ac55) SHA1(b54e9684f750b73c357d41b88ca8c527258e2a10))
3230   ROM_LOAD("95770024.vid", 0x00000, 0x20000, CRC(5bc7ac55) SHA1(b54e9684f750b73c357d41b88ca8c527258e2a10))
32323231
3233   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3234   ROM_LOAD( "95001016.snd", 0x00000, 0x20000, CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
3232   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3233   ROM_LOAD("95001016.snd", 0x00000, 0x20000, CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
32353234
32363235   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3237   ROM_LOAD( "95770025.chr", 0x00000, 0x20000, CRC(f59748ea) SHA1(f0f7f914fdf72db8eb60717b95e7d027c0081339))
3238
3236   ROM_LOAD("95770025.chr", 0x00000, 0x20000, CRC(f59748ea) SHA1(f0f7f914fdf72db8eb60717b95e7d027c0081339))
32393237ROM_END
32403238
32413239// ROM definition Dutch Quintoon alternate set /////////////////////////////
32423240
32433241ROM_START( qntoondo )
3244   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3245   ROM_LOAD( "95750136.bin", 0x0000, 0x10000, CRC(839ea01d) SHA1(d7f77dbaea4e87c3d782408eb50d10f44b6df5e2))
3242   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3243   ROM_LOAD("95750136.bin", 0x00000, 0x10000, CRC(839ea01d) SHA1(d7f77dbaea4e87c3d782408eb50d10f44b6df5e2))
32463244
32473245   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3248   ROM_LOAD( "95770024.vid", 0x0000, 0x20000, CRC(5bc7ac55) SHA1(b54e9684f750b73c357d41b88ca8c527258e2a10))
3246   ROM_LOAD("95770024.vid", 0x00000, 0x20000, CRC(5bc7ac55) SHA1(b54e9684f750b73c357d41b88ca8c527258e2a10))
32493247
3250   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3251   ROM_LOAD( "95001016.snd", 0x00000, 0x20000, CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
3248   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3249   ROM_LOAD("95001016.snd", 0x00000, 0x20000, CRC(cf097d41) SHA1(6712f93896483360256d8baffc05977c8e532ef1))
32523250
32533251   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3254   ROM_LOAD( "95770025.chr", 0x00000, 0x20000, CRC(f59748ea) SHA1(f0f7f914fdf72db8eb60717b95e7d027c0081339))
3255
3252   ROM_LOAD("95770025.chr", 0x00000, 0x20000, CRC(f59748ea) SHA1(f0f7f914fdf72db8eb60717b95e7d027c0081339))
32563253ROM_END
32573254
32583255// ROM definition dutch golden crown //////////////////////////////////////
32593256
32603257ROM_START( gldncrwn )
3261   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3262   ROM_LOAD( "95752011.bin", 0x0000, 0x10000, CRC(54f7cca0) SHA1(835727d88113700a38060f880b4dfba2ded41487))
3258   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3259   ROM_LOAD("95752011.bin", 0x00000, 0x10000, CRC(54f7cca0) SHA1(835727d88113700a38060f880b4dfba2ded41487))
32633260
32643261   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3265   ROM_LOAD( "95770117.vid", 0x0000, 0x20000,  CRC(598ba7cb) SHA1(ab518d7df24b0b453ec3fcddfc4db63e0391fde7))
3262   ROM_LOAD("95770117.vid", 0x00000, 0x20000, CRC(598ba7cb) SHA1(ab518d7df24b0b453ec3fcddfc4db63e0391fde7))
32663263
3267   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3268   ROM_LOAD( "95001039.snd", 0x00000, 0x20000, CRC(6af26157) SHA1(9b3a85f5dd760c4430e38e2844928b74aadc7e75))
3264   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3265   ROM_LOAD("95001039.snd", 0x00000, 0x20000, CRC(6af26157) SHA1(9b3a85f5dd760c4430e38e2844928b74aadc7e75))
32693266
32703267   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3271   ROM_LOAD( "95770118.ch1", 0x00000, 0x20000, CRC(9c9ac946) SHA1(9a571e7d00f6654242aface032c2fb186ef44aba))
3272   ROM_LOAD( "95770119.ch2", 0x20000, 0x20000, CRC(9e0fdb2e) SHA1(05e8257285b0009df4fcc73e93490876358a8be8))
3268   ROM_LOAD("95770118.ch1", 0x00000, 0x20000, CRC(9c9ac946) SHA1(9a571e7d00f6654242aface032c2fb186ef44aba))
3269   ROM_LOAD("95770119.ch2", 0x20000, 0x20000, CRC(9e0fdb2e) SHA1(05e8257285b0009df4fcc73e93490876358a8be8))
32733270
32743271   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3275   ROM_LOAD( "gcrpal.bin", 0, 8 , CRC(4edd5a1d) SHA1(d6fe38377d5f2291d33ee8ed808548871e63c4d7))
3272   ROM_LOAD("gcrpal.bin", 0, 8 , CRC(4edd5a1d) SHA1(d6fe38377d5f2291d33ee8ed808548871e63c4d7))
32763273ROM_END
32773274
32783275// ROM definition Dutch Paradice //////////////////////////////////////////
32793276
32803277ROM_START( paradice )
3281   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3282   ROM_LOAD( "95750615.bin", 0x0000, 0x10000, CRC(f51192e5) SHA1(a1290e32bba698006e83fd8d6075202586232929))
3278   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3279   ROM_LOAD("95750615.bin", 0x00000, 0x10000, CRC(f51192e5) SHA1(a1290e32bba698006e83fd8d6075202586232929))
32833280
32843281   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3285   ROM_LOAD( "95770084.vid", 0x0000, 0x20000, CRC(8f27bd34) SHA1(fccf7283b5c952b74258ee6e5138c1ca89384e24))
3282   ROM_LOAD("95770084.vid", 0x00000, 0x20000, CRC(8f27bd34) SHA1(fccf7283b5c952b74258ee6e5138c1ca89384e24))
32863283
3287   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3288   ROM_LOAD( "95001037.snd", 0x00000, 0x20000, CRC(82f74276) SHA1(c51c3caeb7bf514ec7a1b452c8effc4c79186062))
3284   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3285   ROM_LOAD("95001037.snd", 0x00000, 0x20000, CRC(82f74276) SHA1(c51c3caeb7bf514ec7a1b452c8effc4c79186062))
32893286
32903287   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3291   ROM_LOAD( "95770085.ch1", 0x00000, 0x20000, CRC(4d1fb82f) SHA1(054f683d1d7c884911bd2d0f85aab4c59ddf9930))
3292   ROM_LOAD( "95770086.ch2", 0x20000, 0x20000, CRC(7b566e11) SHA1(f34c82ad75a0f88204ac4ae83a00801215c46ca9))
3288   ROM_LOAD("95770085.ch1", 0x00000, 0x20000, CRC(4d1fb82f) SHA1(054f683d1d7c884911bd2d0f85aab4c59ddf9930))
3289   ROM_LOAD("95770086.ch2", 0x20000, 0x20000, CRC(7b566e11) SHA1(f34c82ad75a0f88204ac4ae83a00801215c46ca9))
32933290
32943291   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
32953292   ROM_LOAD( "pdcepal.bin", 0, 8 , CRC(64020c97) SHA1(9371841e2df950c1f2e5b5a4b52621beb6f60945))
r936r937
32983295// ROM definition Dutch Pokio /////////////////////////////////////////////
32993296
33003297ROM_START( pokio )
3301   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3302   ROM_LOAD( "95750278.bin", 0x0000, 0x10000, CRC(5124b24d) SHA1(9bc63891a8e9283c2baa64c264a5d6d1625d44b2))
3298   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3299   ROM_LOAD("95750278.bin", 0x00000, 0x10000, CRC(5124b24d) SHA1(9bc63891a8e9283c2baa64c264a5d6d1625d44b2))
33033300
33043301   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3305   ROM_LOAD( "95770044.vid", 0x0000, 0x20000,  CRC(46d7a6d8) SHA1(01f58e735621661b57c61491b3769ae99e92476a))
3302   ROM_LOAD("95770044.vid", 0x00000, 0x20000, CRC(46d7a6d8) SHA1(01f58e735621661b57c61491b3769ae99e92476a))
33063303
3307   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3308   ROM_LOAD( "95001016.snd", 0x00000, 0x20000, CRC(98aaff76) SHA1(4a59cf83daf018d93f1ff7805e06309d2f3d7252))
3304   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3305   ROM_LOAD("95001016.snd", 0x00000, 0x20000, CRC(98aaff76) SHA1(4a59cf83daf018d93f1ff7805e06309d2f3d7252))
33093306
33103307   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3311   ROM_LOAD( "95770045.chr", 0x00000, 0x20000, CRC(dd30da90) SHA1(b4f5a229d88613c0c7d43adf3f325c619abe38a3))
3308   ROM_LOAD("95770045.chr", 0x00000, 0x20000, CRC(dd30da90) SHA1(b4f5a229d88613c0c7d43adf3f325c619abe38a3))
33123309
33133310   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3314   ROM_LOAD( "pokiopal.bin", 0, 8 , CRC(53535184) SHA1(c5c98085e39ca3671dca72c21a8466d7d70cd341))
3311   ROM_LOAD("pokiopal.bin", 0, 8 , CRC(53535184) SHA1(c5c98085e39ca3671dca72c21a8466d7d70cd341))
33153312ROM_END
33163313
33173314// ROM definition pyramid prototype  //////////////////////////////////////
33183315
33193316ROM_START( pyramid )
3320   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3321   ROM_LOAD( "95750898.bin", 0x0000, 0x10000,  CRC(3b0df16c) SHA1(9af599fe604f86c72986aa1610d74837852e023f))
3317   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3318   ROM_LOAD("95750898.bin", 0x00000, 0x10000,  CRC(3b0df16c) SHA1(9af599fe604f86c72986aa1610d74837852e023f))
33223319
33233320   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3324   ROM_LOAD( "95770108.vid", 0x0000, 0x20000,  CRC(216ff683) SHA1(227764771600ce88c5f36bed9878e6bb9988ae8f))
3321   ROM_LOAD("95770108.vid", 0x00000, 0x20000,  CRC(216ff683) SHA1(227764771600ce88c5f36bed9878e6bb9988ae8f))
33253322
3326   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3327   ROM_LOAD( "95001038.snd", 0x00000, 0x20000, CRC(f885c42e) SHA1(4d79fc5ae4c58247740d78d81302bfbb43331c43))
3323   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3324   ROM_LOAD("95001038.snd", 0x00000, 0x20000, CRC(f885c42e) SHA1(4d79fc5ae4c58247740d78d81302bfbb43331c43))
33283325
33293326   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3330   ROM_LOAD( "95770106.ch1", 0x00000, 0x20000, CRC(a83c27ae) SHA1(f61ca3cdf19a933bae18c1b32a5fb0a2204dde78))
3331   ROM_LOAD( "95770107.ch2", 0x20000, 0x20000, CRC(52e59f64) SHA1(ea4828c2cfb72cd77c92c60560b4d5ee424f7dca))
3327   ROM_LOAD("95770106.ch1", 0x00000, 0x20000, CRC(a83c27ae) SHA1(f61ca3cdf19a933bae18c1b32a5fb0a2204dde78))
3328   ROM_LOAD("95770107.ch2", 0x20000, 0x20000, CRC(52e59f64) SHA1(ea4828c2cfb72cd77c92c60560b4d5ee424f7dca))
33323329
33333330   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3334   ROM_LOAD( "pyrmdpal.bin", 0, 8 , CRC(1c7c37bb) SHA1(fe0276603fee8f58e4318f91645260368212b78b))
3331   ROM_LOAD("pyrmdpal.bin", 0, 8 , CRC(1c7c37bb) SHA1(fe0276603fee8f58e4318f91645260368212b78b))
33353332ROM_END
33363333
33373334// ROM definition Dutch slots /////////////////////////////////////////////
33383335
33393336ROM_START( slotsnl )
3340   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3341   ROM_LOAD( "95750368.bin", 0x0000, 0x10000,  CRC(3a43048c) SHA1(13728e05b334cba90ea9cc51ea00c4384baa8614))
3337   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3338   ROM_LOAD("95750368.bin", 0x00000, 0x10000, CRC(3a43048c) SHA1(13728e05b334cba90ea9cc51ea00c4384baa8614))
33423339
33433340   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3344   ROM_LOAD( "video.vid", 0x0000, 0x20000, CRC(cc760208) SHA1(cc01b1e31335b26f2d0f3470d8624476b153655f))
3341   ROM_LOAD("video.vid",    0x00000, 0x20000, CRC(cc760208) SHA1(cc01b1e31335b26f2d0f3470d8624476b153655f))
33453342
3346   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3347   ROM_LOAD( "95001029.snd", 0x00000, 0x20000, CRC(7749c724) SHA1(a87cce0c99e392f501bba44b3936a7059d682c9c))
3343   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3344   ROM_LOAD("95001029.snd", 0x00000, 0x20000, CRC(7749c724) SHA1(a87cce0c99e392f501bba44b3936a7059d682c9c))
33483345
33493346   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3350   ROM_LOAD( "charset.chr",   0x00000, 0x20000,  CRC(ef4300b6) SHA1(a1f765f38c2f146651fc685ea6195af72465f559))
3347   ROM_LOAD("charset.chr",    0x00000, 0x20000,  CRC(ef4300b6) SHA1(a1f765f38c2f146651fc685ea6195af72465f559))
33513348
33523349   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
33533350   ROM_LOAD( "slotspal.bin", 0, 8 , CRC(ee5421f0) SHA1(21bdcbf11dda8b1a93c49ae1c706954bba53c917))
r936r937
33563353// ROM definition Belgian Slots (Token pay per round) Payslide ////////////
33573354
33583355ROM_START( sltblgtk )
3359   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3360   ROM_LOAD( "95750943.bin", 0x0000, 0x10000,  CRC(c9fb8153) SHA1(7c1d0660c15f05b1e0784d8322c62981fe8dc4c9))
3356   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3357   ROM_LOAD("95750943.bin", 0x00000, 0x10000, CRC(c9fb8153) SHA1(7c1d0660c15f05b1e0784d8322c62981fe8dc4c9))
33613358
33623359   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3363   ROM_LOAD( "adder121.bin", 0x0000, 0x20000, CRC(cedbbf28) SHA1(559ae341b55462feea771127394a54fc65266818))
3360   ROM_LOAD("adder121.bin", 0x00000, 0x20000, CRC(cedbbf28) SHA1(559ae341b55462feea771127394a54fc65266818))
33643361
3365   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3366   ROM_LOAD( "sound029.bin", 0x00000, 0x20000, CRC(7749c724) SHA1(a87cce0c99e392f501bba44b3936a7059d682c9c))
3362   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3363   ROM_LOAD("sound029.bin", 0x00000, 0x20000, CRC(7749c724) SHA1(a87cce0c99e392f501bba44b3936a7059d682c9c))
33673364
33683365   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3369   ROM_LOAD( "chr122.bin",   0x00000, 0x20000, CRC(a1e3bdf4) SHA1(f0cabe08dee028e2014cbf0fc3fe0806cdfa60c6))
3366   ROM_LOAD("chr122.bin",    0x00000, 0x20000, CRC(a1e3bdf4) SHA1(f0cabe08dee028e2014cbf0fc3fe0806cdfa60c6))
33703367
33713368   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3372   ROM_LOAD( "stsbtpal.bin", 0, 8 , CRC(20e13635) SHA1(5aa7e7cac8c00ebc193d63d0c6795904f42c70fa))
3369   ROM_LOAD("stsbtpal.bin", 0, 8 , CRC(20e13635) SHA1(5aa7e7cac8c00ebc193d63d0c6795904f42c70fa))
33733370ROM_END
33743371
33753372// ROM definition Belgian Slots (Cash Payout) /////////////////////////////
33763373
33773374ROM_START( sltblgp1 )
3378   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3379   ROM_LOAD( "95752008.bin", 0x0000, 0x10000,  CRC(3167d3b9) SHA1(a28563f65d55c4d47f3e7fdb41e050d8a733b9bd))
3375   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3376   ROM_LOAD("95752008.bin", 0x00000, 0x10000, CRC(3167d3b9) SHA1(a28563f65d55c4d47f3e7fdb41e050d8a733b9bd))
33803377
33813378   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3382   ROM_LOAD( "adder142.bin", 0x0000, 0x20000, CRC(a6f6356b) SHA1(b3d3063155ee3ea888273081f844279b6e33f7d9))
3379   ROM_LOAD("adder142.bin", 0x00000, 0x20000, CRC(a6f6356b) SHA1(b3d3063155ee3ea888273081f844279b6e33f7d9))
33833380
3384   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3385   ROM_LOAD( "sound033.bin", 0x00000, 0x20000, CRC(bb1dfa55) SHA1(442454fccfe03e6f4c3353551cb7459e184a099d))
3381   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3382   ROM_LOAD("sound033.bin", 0x00000, 0x20000, CRC(bb1dfa55) SHA1(442454fccfe03e6f4c3353551cb7459e184a099d))
33863383
33873384   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3388   ROM_LOAD( "chr143.bin",   0x00000, 0x20000, CRC(a40e91e2) SHA1(87dc76963ea961fcfbe4f3e25df9162348d39d79))
3385   ROM_LOAD("chr143.bin",    0x00000, 0x20000, CRC(a40e91e2) SHA1(87dc76963ea961fcfbe4f3e25df9162348d39d79))
33893386
33903387   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3391   ROM_LOAD( "stsbcpal.bin", 0, 8 , CRC(c63bcab6) SHA1(238841165d5b3241b0bcc5c1792e9c0be1fc0177))
3388   ROM_LOAD("stsbcpal.bin", 0, 8 , CRC(c63bcab6) SHA1(238841165d5b3241b0bcc5c1792e9c0be1fc0177))
33923389ROM_END
33933390
33943391// ROM definition Belgian Slots (Cash Payout) /////////////////////////////
33953392
33963393ROM_START( sltblgpo )
3397   ROM_REGION( 0x12000, REGION_CPU1, 0 )   /* 64 + 8k for code */
3398   ROM_LOAD( "95770938.bin", 0x0000, 0x10000,  CRC(7e802634) SHA1(fecf86e632546649d5e647c42a248b39fc2cf982))
3394   ROM_REGION( 0x12000, REGION_CPU1, 0 )
3395   ROM_LOAD("95770938.bin", 0x00000, 0x10000, CRC(7e802634) SHA1(fecf86e632546649d5e647c42a248b39fc2cf982))
33993396
34003397   ROM_REGION( 0x20000, REGION_CPU2, 0 )
3401   ROM_LOAD( "95770120.chr", 0x00000, 0x20000, CRC(ad505138) SHA1(67ccd8dc30e76283247ab5a62b22337ebaff74cd))
3398   ROM_LOAD("95770120.chr", 0x00000, 0x20000, CRC(ad505138) SHA1(67ccd8dc30e76283247ab5a62b22337ebaff74cd))
34023399
3403   ROM_REGION( 0x20000, REGION_SOUND1, 0 ) // samples
3404   ROM_LOAD( "sound033.bin", 0x00000, 0x20000, CRC(bb1dfa55) SHA1(442454fccfe03e6f4c3353551cb7459e184a099d))
3400   ROM_REGION( 0x20000, REGION_SOUND1, 0 )
3401   ROM_LOAD("sound033.bin", 0x00000, 0x20000, CRC(bb1dfa55) SHA1(442454fccfe03e6f4c3353551cb7459e184a099d))
34053402
34063403   ROM_REGION( 0x40000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_ERASEFF )
3407   ROM_LOAD( "95770110.add", 0x0000, 0x20000, CRC(64b03284) SHA1(4b1c17b75e449c9762bb949d7cde0694a3aaabeb))
3404   ROM_LOAD("95770110.add", 0x00000, 0x20000, CRC(64b03284) SHA1(4b1c17b75e449c9762bb949d7cde0694a3aaabeb))
34083405
34093406   ROM_REGION( 0x10, REGION_PROMS, ROMREGION_DISPOSE )
3410   ROM_LOAD( "stsbcpal.bin", 0, 8 , CRC(c63bcab6) SHA1(238841165d5b3241b0bcc5c1792e9c0be1fc0177))
3407   ROM_LOAD("stsbcpal.bin", 0, 8 , CRC(c63bcab6) SHA1(238841165d5b3241b0bcc5c1792e9c0be1fc0177))
34113408ROM_END
34123409
34133410//     year, name,     parent,    machine,       input,     init,       monitor, company,    fullname
34143411GAMEL( 1993, qntoondo, qntoond,     scorpion2_vid, qntoond,   adder_dutch,0,       "BFM/ELAM", "Quintoon (Dutch, Game Card 95-750-136)",      GAME_SUPPORTS_SAVE,layout_quintoon )
3415GAMEL( 1993, quintoon, 0,        scorpion2_vid, quintoon,  quintoon,   0,       "BFM",      "Quintoon (UK, Game Card 95-750-203)",         GAME_SUPPORTS_SAVE|GAME_IMPERFECT_SOUND,layout_quintoon ) //Current samples need verification
3412GAMEL( 1993, quintoon, 0,        scorpion2_vid, quintoon,  quintoon,   0,       "BFM",      "Quintoon (UK, Game Card 95-750-206)",         GAME_SUPPORTS_SAVE|GAME_IMPERFECT_SOUND,layout_quintoon ) //Current samples need verification
3413GAMEL( 1993, quintono, quintoon,  scorpion2_vid, quintono,  quintoon,   0,       "BFM",      "Quintoon (UK, Game Card 95-750-203)",         GAME_SUPPORTS_SAVE|GAME_IMPERFECT_SOUND,layout_quintoon ) //Current samples need verification
34163414GAMEL( 1993, qntoond,  0,        scorpion2_vid, qntoond,   adder_dutch,0,       "BFM/ELAM", "Quintoon (Dutch, Game Card 95-750-243)",      GAME_SUPPORTS_SAVE,layout_quintoon )
34173415GAMEL( 1994, pokio,    0,        scorpion2_vid, pokio,     adder_dutch,0,       "BFM/ELAM", "Pokio (Dutch, Game Card 95-750-278)",         GAME_SUPPORTS_SAVE,layout_pokio )
34183416GAMEL( 1995, slotsnl,  0,        scorpion2_vid, slotsnl,   adder_dutch,0,       "BFM/ELAM", "Slots (Dutch, Game Card 95-750-368)",         GAME_SUPPORTS_SAVE,layout_slots )
src/mame/drivers/dynax.c
r936r937
1010Custom: TC17G032AP-0246 (blitter)
1111
1212---------------------------------------------------------------------------------------------------------------------
13Year + Game                 Board(s)                    Sound                       Palette  Notes
13Year + Game                     Board(s)                    Sound                       Clock  Palette  Notes
1414---------------------------------------------------------------------------------------------------------------------
1588 Hana no Mai              D1610088L1                  AY8912 YM2203        M5205  PROM
1688 Hana Kochou              D201901L2 + D201901L1-0     AY8912 YM2203        M5205  PROM
1789 Hana Oriduru             D2304268L                   AY8912        YM2413 M5205  RAM
1889 Dragon Punch             D24?                               YM2203               PROM
1989 Mahjong Friday           D2607198L1                                YM2413        PROM
2089 Sports Match             D31?                               YM2203               PROM
2190 Jong Tou Ki (1)          D1505178-A + D2711078L-B    AY8912 YM2203        M5205  PROM
2290 Mahjong Campus Hunting   D3312108L1-1 + D23SUB1      AY8912        YM2413 M5205  RAM
2390 7jigen no Youseitachi    D3707198L1 + D23SUB1        AY8912        YM2413 M5205  RAM
2490 Mahjong Electron Base                                AY8912        YM2413        RAM
2590 Mahjong X-Tal/Diamond 7  D4005208L1-1 + D23SUB       AY8912        YM2413 M5205  RAM
2690 Neruton Haikujiradan     D4005208L1-1 + D4508308L-2  AY8912        YM2413 M5205  RAM
2791 Mahjong Yarunara         D5512068L1-1 + D4508308L-2  AY8912        YM2413 M5205  RAM
2891 Mahjong Angels           D5512068L1-1 + D6107068L-1  AY8912        YM2413 M5205  RAM
2991 Mahjong Dial Q2          D5212298L-1                               YM2413        PROM
3091 Mahjong Tenkaigen                                    AY8910        YM2413 M6242  RAM      TMP91P640, protecttion
3192 Quiz TV Gassyuukoku Q&Q  D5512068L1-2 + D6410288L-1  AY8912        YM2413 M5205  RAM
3294 Mahjong Reach (bootleg)  bootleg                     AY8910        YM2413 M6242  PROM     TMP91P640
3394 Maya                                                        YM2203               PROM
3496 Mahjong Raijinhai DX     D10010318L1 + D10502168     AY8910               M6242  PROM     undumped TMP91P640 code
359? Inca                                                        YM2203               PROM
1588 Hana no Mai                  D1610088L1                  AY8912 YM2203        M5205         PROM
1688 Hana Kochou                  D201901L2 + D201901L1-0     AY8912 YM2203        M5205         PROM
1789 Hana Oriduru                 D2304268L                   AY8912        YM2413 M5205         RAM
1889 Dragon Punch                 D24?                               YM2203                      PROM
1989 Mahjong Friday               D2607198L1                                YM2413               PROM
2089 Sports Match                 D31?                               YM2203                      PROM
2190 Jong Tou Ki                  D1505178-A + D2711078L-B    AY8912 YM2203        M5205         PROM     2 x Z80, 2 x blitter
2290 Mahjong Campus Hunting       D3312108L1-1 + D23SUB1      AY8912        YM2413 M5205         RAM
2390 7jigen no Youseitachi        D3707198L1 + D23SUB1        AY8912        YM2413 M5205         RAM
2490 Mahjong Electron Base                                    AY8912        YM2413               RAM
2590 Mahjong X-Tal/Diamond 7      D4005208L1-1 + D23SUB       AY8912        YM2413 M5205         RAM
2690 Neruton Haikujiradan         D4005208L1-1 + D4508308L-2  AY8912        YM2413 M5205         RAM
2791 Mahjong Yarunara             D5512068L1-1 + D4508308L-2  AY8912        YM2413 M5205  M6242  RAM      NL-001
2891 Mahjong Angels               D5512068L1-1 + D6107068L-1  AY8912        YM2413 M5205         RAM
2991 Mahjong Comic Gekijou Vol.1  D5512068L1-1 + D6107068L-1  AY8912        YM2413 M5205  M6242  RAM      NL-001, Battery
3091 Mahjong Dial Q2              D5212298L-1                               YM2413               PROM
3191 Mahjong Tenkaigen                                        AY8910        YM2413        M6242  RAM      TMP91P640, protecttion, Battery
3292 Quiz TV Gassyuukoku Q&Q      D5512068L1-2 + D6410288L-1  AY8912        YM2413 M5205         RAM
3394 Mahjong Reach (bootleg)      bootleg                     AY8910        YM2413        M6242  PROM     TMP91P640, Battery
3494 Maya                                                            YM2203                      PROM
3596 Mahjong Raijinhai DX         D10010318L1 + D10502168     AY8910                      M6242  PROM     undumped TMP91P640 code, Battery
369? Inca                                                            YM2203                      PROM
3637---------------------------------------------------------------------------------------------------------------------
37(1) quite different from the others: it has a slave Z80 and *two* blitters
3838
3939Notes:
4040
r936r937
666666      case 0x01:   dynax_blit_romregion_w(0,1);   return;
667667      case 0x80:   dynax_blit_romregion_w(0,2);   return;
668668      case 0x81:   dynax_blit_romregion_w(0,3);   return;
669      case 0x82:   dynax_blit_romregion_w(0,4);   return;   // mjcomv1
669670   }
670671   logerror("%04x: unmapped romregion=%02X\n",activecpu_get_pc(),data);
671672}
r936r937
10141015static int rombank;
10151016static UINT8 *romptr;
10161017int tenkai_dswsel, tenkai_ipsel, tenkai_ip;
1018static UINT8 tenkai_p5_val;
10171019
10181020static WRITE8_HANDLER( tenkai_ipsel_w )
10191021{
r936r937
11481150   rombank = (rombank & 0x08) | ((data & 0x0e) >> 1);
11491151   tenkai_update_rombank();
11501152}
1153// Added by Whistler - START
1154static READ8_HANDLER( tenkai_p5_r )
1155{
1156   return tenkai_p5_val;
1157}
1158static WRITE8_HANDLER( tenkai_p6_w )
1159{
1160   tenkai_p5_val &= 0x0f;
1161   if (data & 0x0f)
1162   {
1163      tenkai_p5_val |= (1 << 4);
1164   }
1165}
1166static WRITE8_HANDLER( tenkai_p7_w )
1167{
1168   tenkai_p5_val &= 0xf0;
1169   if (data & 0x03)
1170   {
1171      tenkai_p5_val |= (1 << 3);
1172   }
1173}
1174// Added by Whistler - END
11511175static WRITE8_HANDLER( tenkai_p8_w )
11521176{
1153   rombank = ((data & 0x08) << 1) | (rombank & 0x0f);
1177   rombank = ((data & 0x08) <<    1) | (rombank & 0x0f);
11541178   tenkai_update_rombank();
11551179}
11561180static READ8_HANDLER( tenkai_p8_r )
r936r937
12621286static ADDRESS_MAP_START( tenkai_io_map, ADDRESS_SPACE_IO, 8 )
12631287   AM_RANGE( T90_P3, T90_P3 ) AM_READWRITE( tenkai_p3_r , tenkai_p3_w )
12641288   AM_RANGE( T90_P4, T90_P4 ) AM_WRITE( tenkai_p4_w )
1289   AM_RANGE( T90_P5, T90_P5 ) AM_READ( tenkai_p5_r )
1290   AM_RANGE( T90_P6, T90_P6 ) AM_WRITE( tenkai_p6_w )
1291   AM_RANGE( T90_P7, T90_P7 ) AM_WRITE( tenkai_p7_w )
12651292   AM_RANGE( T90_P8, T90_P8 ) AM_READWRITE( tenkai_p8_r, tenkai_p8_w )
12661293ADDRESS_MAP_END
12671294
r936r937
49184945   ROM_RELOAD(                   0x10000, 0x40000 )
49194946   ROM_LOAD( "tmp91p640n-10.5b", 0x00000, 0x04000, CRC(509f1c97) SHA1(08557bea2e924053fd5bc9de5e306f3ecf8e98e6) )
49204947
4948   // Note by Whistler:
4949   // It appears that the first half of lzc-01.u6 in tenkaibb (as well as the same data in other bootleg versions)
4950   // does not exist _anywhere_ in this rom dump, and in this way some girls won't show correctly (such as the 3rd one)
49214951   ROM_REGION( 0x80000, REGION_GFX1, 0 )   // blitter data
49224952   ROM_LOAD( "taicom01.15b", 0x000000, 0x80000, CRC(39e4e6f3) SHA1(5b543a5933446091d7cfd519d5a6f23047d8a9f2) )
49234953
4924   ROM_REGION( 0x80000, REGION_GFX2, 0 )   // blitter data
4954   ROM_REGION( 0x100000, REGION_GFX2, 0 )   // blitter data
49254955   ROM_LOAD( "taicom02.11b", 0x000000, 0x80000, CRC(aae8cfb7) SHA1(736c6148aa6e7b22ca19615a27e9a10d41778aa7) )
4926
4927   ROM_REGION( 0x80000, REGION_GFX3, 0 )   // blitter data
4928   ROM_LOAD( "taicom03.13b", 0x000000, 0x80000, CRC(68cb730a) SHA1(7ce90e34fa51d50a7668ac1c5ccbc18bebe8ad84) )
4956   ROM_LOAD( "taicom03.13b", 0x080000, 0x80000, CRC(68cb730a) SHA1(7ce90e34fa51d50a7668ac1c5ccbc18bebe8ad84) )
49294957ROM_END
49304958
49314959/***************************************************************************
r936r937
52265254
52275255/***************************************************************************
52285256
5257Mahjong Comic Gekijou Vol.1
5258(c)1991 Dynax / Tenho Iwatani
5259D5512068L1-1 (main PCB)
5260D6107068L-1  (sub PCB)
52295261
5262CPU: Z80B
5263Sound: AY-3-8912, YM2413, M5205
5264OSC: 20.0000MHz (near Z80B)
5265     14.31818MHz (near sound section)
5266     ?MHz (near RTC)
5267Custom: DYNAX NL-001
5268        DYNAX TC17G032AP-0246
5269Others: 3.6V Ni-Cd Battery, M6242B RTC
5270
5271ROMs:
52726101.2D      [60552776] \
52736102.4D      [4b4f3966] -- Programs?
5274
52756103.5D      [6d56e5c1] -- Samples?
5276
52776104.1A      [04eb1ce0] \
52786105.2A      [54115f33] |
52796106.3A      [093faddb] |
52806107.4A      [0b0997f5] |
52816108.5A      [bd31ae6f] |
52826109.1B      [cf718f69] |- Graphics
52836110.2B      [2865eae4] |
52846111.3B      [581edcc0] |
52856112.4B      [3083c0cf] |
52866113.5B      [e34e9541] |
52876114.1C      [1aa9a1d7] /
5288
5289d61a.4e \
5290d61b.7b -- PAL16CEV8 (not dumped)
5291
52926104-6114 and D61B is on sub PCB, others are on main PCB
5293
5294***************************************************************************/
5295
5296ROM_START( mjcomv1 )
5297   ROM_REGION( 0x10000 + 0x28*0x8000, REGION_CPU1, 0 )   // Z80 Code
5298   ROM_LOAD( "6101.2d", 0x000000, 0x20000, CRC(60552776) SHA1(9876f1aece8f25b7e495c6fac24ebb5028916f73) )
5299   // 00-03
5300   ROM_RELOAD(          0x010000, 0x20000 )
5301   // 0c-0f
5302   ROM_RELOAD(          0x070000, 0x20000 )
5303   // 24-27
5304   ROM_RELOAD(          0x130000, 0x20000 )
5305   // 04-07
5306   ROM_LOAD( "6102.4d", 0x030000, 0x20000, CRC(4b4f3966) SHA1(150cf8fe6342ea9a956073b3ebba6553c13e9cf8) )
5307   // 08-0b
5308   ROM_LOAD( "6103.5d", 0x050000, 0x20000, CRC(6d56e5c1) SHA1(2c02a400d21e442cdd68bf6210b397b770cde3b5) )   // 1ST AND 2ND HALF IDENTICAL
5309
5310//  ROM_REGION( 0x00000, REGION_GFX1, 0 )   // blitter data
5311//  unused
5312
5313//  ROM_REGION( 0x00000, REGION_GFX2, 0 )   // blitter data
5314//  unused
5315
5316   ROM_REGION( 0x100000, REGION_GFX3, 0 )   // blitter data
5317   //                   0x00000, 0x20000
5318   ROM_LOAD( "6105.2a", 0x20000, 0x20000, CRC(54115f33) SHA1(ed7d00c9b5c8aad066cf92c627b36c3a5e982d9f) )
5319   ROM_LOAD( "6106.3a", 0x40000, 0x20000, CRC(093faddb) SHA1(ac8ee5abcd8a7b28f28407f5488c21a4bbff305a) )
5320   ROM_LOAD( "6107.4a", 0x60000, 0x20000, CRC(0b0997f5) SHA1(ef31ca2818b8aef7fac01293e34fd7b37c8326f4) )
5321   ROM_LOAD( "6108.5a", 0x80000, 0x20000, CRC(bd31ae6f) SHA1(cc322dd07acab85874e5f033c65d2c99838d7474) )
5322   ROM_LOAD( "6109.1b", 0xa0000, 0x20000, CRC(cf718f69) SHA1(0e8f9e6c9ef35f71a4b7fcaf62e4c22b486dcb9d) )
5323   ROM_LOAD( "6110.2b", 0xc0000, 0x20000, CRC(2865eae4) SHA1(dd945a2a531a08e654f13c135bb9cb799589d513) )
5324   ROM_LOAD( "6111.3b", 0xe0000, 0x20000, CRC(581edcc0) SHA1(d52de6ca199f03e0d88c8e4275fe2b37b3ef6016) )
5325
5326   ROM_REGION( 0x60000, REGION_GFX4, 0 )   // blitter data
5327   ROM_LOAD( "6112.4b", 0x00000, 0x20000, CRC(3083c0cf) SHA1(24465e2d01cb0f0646644a3a5d57d9c0f456cf96) )
5328   ROM_LOAD( "6113.5b", 0x20000, 0x20000, CRC(e34e9541) SHA1(fbe457b4107730f3d633536e82b9271dcbc71559) )
5329   ROM_LOAD( "6114.1c", 0x40000, 0x20000, CRC(1aa9a1d7) SHA1(67991ff4968443e596fd2fadb097e32d2e6802c3) )
5330
5331   ROM_REGION( 0x80000, REGION_GFX5, 0 )   // blitter data
5332   ROM_LOAD( "6104.1a", 0x00000, 0x80000, CRC(04eb1ce0) SHA1(670b213db190bb845c0a99e0a8b166ebff8a7ea1) )
5333ROM_END
5334
5335/***************************************************************************
5336
5337
52305338                                Game Drivers
52315339
52325340
r936r937
52525360GAME( 1990, mjelct3a, mjelctrn, mjelctrn, mjelct3,  mjelct3a, ROT180, "Dynax",                    "Mahjong Electron Base (parts 2 & 3, alt., Japan)",             0 )
52535361GAME( 1990, majxtal7, 0,        majxtal7, majxtal7, mjelct3,  ROT180, "Dynax",                    "Mahjong X-Tal 7 - Crystal Mahjong / Mahjong Diamond 7 (Japan)",GAME_IMPERFECT_GRAPHICS )
52545362GAME( 1990, neruton,  0,        neruton,  neruton,  mjelct3,  ROT180, "Dynax / Yukiyoshi Tokoro", "Mahjong Neruton Haikujirada (Japan)",                          GAME_IMPERFECT_GRAPHICS )
5363GAME( 1991, mjcomv1,  0,        yarunara, yarunara, 0,        ROT180, "Dynax",                    "Mahjong Comic Gekijou Vol.1 (Japan)",                          0 )
52555364GAME( 1991, tenkai,   0,        tenkai,   tenkai,   0,        ROT0,   "Dynax",                    "Mahjong Tenkaigen",                                            GAME_NOT_WORKING )
52565365GAME( 1991, tenkai2b, tenkai,   tenkai,   tenkai,   0,        ROT0,   "Dynax",                    "Mahjong Tenkaigen Part 2 (bootleg)",                           GAME_NOT_WORKING )
52575366GAME( 1991, tenkaibb, tenkai,   tenkai,   tenkai,   0,        ROT0,   "Dynax",                    "Mahjong Tenkaigen (bootleg b)",                                0 )
src/mame/drivers/paradise.c
r936r937
5757{
5858   if (data & ~0x02)   logerror("CPU #0 - PC %04X: unknown oki bank bits %02X\n",activecpu_get_pc(),data);
5959
60   if (sndti_to_sndnum(SOUND_OKIM6295, 1) >= 0)
60   if (sndti_exists(SOUND_OKIM6295, 1))
6161      OKIM6295_set_bank_base(1, (data & 0x02) ? 0x40000 : 0);
6262}
6363
src/mame/drivers/namcona1.c
r936r937
196196 */
197197    0x30,0x32,0x4f,0x63,0x74,0x39,0x32,0x52,0x45,0x56,0x49,0x53,0x49,0x4f,0x4e,0x35,
198198   0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x01,
199   0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
200   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
201   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
202   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
203   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
204   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
205   0x51,0x01,0x38,0x38,0xa7,0xbf,0xf1,0x04,0x0d,0x15,0x9b,0x80,0x1f,0x83,0xd5,0xa4,
206   0x69,0x88,0x7c,0x9f,0xb6,0x01,0xda,0x93,0x17,0x45,0x8b,0x12,0xb2,0x02,0x33,0x5c,
207   0x50,0xd6,0xe1,0x56,0xa4,0xad,0x42,0x4a,0x5c,0xdd,0x86,0x61,0xe9,0x03,0x12,0xe1,
208   0x0f,0x9b,0xea,0x26,0x2c,0x61,0xdc,0x62,0x48,0x6b,0x6d,0x14,0xe0,0x03,0x85,0x4a,
209   0x72,0x46,0xda,0x96,0xc8,0x7d,0x1c,0xd1,0x05,0x3e,0xe5,0x92,0x70,0x43,0x5f,0x6c,
210   0x03,0x05,0xb3,0xeb,0xb3,0x20,0x35,0x4d,0x7e,0x66,0x50,0x01,0x36,0xc0,0x33,0xe1,
211   0x0f,0xc9,0x38,0x2e,0xe9,0x29,0x19,0x4f,0x5e,0xb1,0xd1,0x49,0x8b,0x3b,0x53,0xfd,
212   0x9f,0x3f,0xee,0x25,0x25,0x35,0x7b,0x0d,0x11,0xaf,0x4c,0x11,0x8c,0x32,0xd4,0xda,
213   0x7f,0xd8,0x16,0x57,0xe1,0xa6,0xce,0x7d,0xc1,0xae,0x62,0xbf,0x13,0xe4,0x87,0x4c,
214   0x3a,0xc1,0xb3,0x0c,0x59,0x99,0x47,0x58,0x5a,0xbd,0x78,0x7c,0xba,0x50,0x01,0xed,
215   0x1b,0xea,0x8a,0x49,0x88,0xee,0xd6,0x14,0x85,0xab,0xb0,0x2c,0xde,0x35,0x93,0x11,
216   0x2d,0x01,0x1c,0xd7,0x28,0x43,0x30,0xe7,0xb0,0x08,0xed,0x79
199   0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02
217200}; /* ExvaniaDefaultNvMem */
218201
219202static const UINT8 QuiztouDefaultNvMem[] =
r936r937
224207 */
225208   0x30,0x32,0x4F,0x63,0x74,0x39,0x32,0x52,0x45,0x56,0x49,0x53,0x49,0x4F,0x4E,0x35,
226209   0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x01,
227   0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,
228   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
229   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
230   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
231   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
232   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
233   0xC1,0x9B,0xE1,0xC0,0x7E,0xE9,0xA8,0x9A,0xA7,0x86,0xC2,0xB5,0x54,0xBF,0x9A,0xE7,
234   0xD9,0x23,0xD1,0x55,0x90,0x38,0x28,0xD1,0xD9,0x6C,0xA1,0x66,0x5E,0x4E,0xE1,0x30,
235   0x9C,0xFE,0xD9,0x71,0x9F,0xE2,0xA5,0xE2,0x0C,0x9B,0xB4,0x47,0x65,0x38,0x2A,0x46,
236   0x89,0xA9,0x82,0x79,0x7A,0x76,0x78,0xC2,0x63,0xB1,0x26,0xDF,0xDA,0x29,0x6D,0x3E,
237   0x62,0xE0,0x96,0x12,0x34,0xBF,0x39,0xA6,0x3F,0x89,0x5E,0xF1,0x6D,0x0E,0xE3,0x6C,
238   0x28,0xA1,0x1E,0x20,0x1D,0xCB,0xC2,0x03,0x3F,0x41,0x07,0x84,0x0F,0x14,0x05,0x65,
239   0x1B,0x28,0x61,0xC9,0xC5,0xE7,0x2C,0x8E,0x46,0x36,0x08,0xDC,0xF3,0xA8,0x8D,0xFE,
240   0xBE,0xF2,0xEB,0x71,0xFF,0xA0,0xD0,0x3B,0x75,0x06,0x8C,0x7E,0x87,0x78,0x73,0x4D,
241   0xD0,0xBE,0x82,0xBE,0xDB,0xC2,0x46,0x41,0x2B,0x8C,0xFA,0x30,0x7F,0x70,0xF0,0xA7,
242   0x54,0x86,0x32,0x95,0xAA,0x5B,0x68,0x13,0x0B,0xE6,0xFC,0xF5,0xCA,0xBE,0x7D,0x9F,
243   0x89,0x8A,0x41,0x1B,0xFD,0xB8,0x4F,0x68,0xF6,0x72,0x7B,0x14,0x99,0xCD,0xD3,0x0D,
244   0xF0,0x44,0x3A,0xB4,0xA6,0x66,0x53,0x33,0x0B,0xCB,0xA1,0x10,0x5E,0x4C,0xEC,0x03,
245   0x4C,0x73,0xE6,0x05,0xB4,0x31,0x0E,0xAA,0xAD,0xCF,0xD5,0xB0,0xCA,0x27,0xFF,0xD8,
246   0x9D,0x14,0x4D,0xF4,0x79,0x27,0x59,0x42,0x7C,0x9C,0xC1,0xF8,0xCD,0x8C,0x87,0x20,
247   0x23,0x64,0xB8,0xA6
210   0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
248211}; /* QuiztouDefaultNvMem */
249212
213static const UINT8 CgangpzlDefaultNvMem[] =
214{
215/* This data oughtn't be necessary; when Cgangpzl's EPROM area is uninitialized,
216 * the game software automatically writes these values there, but then hangs.
217 */
218   0x30,0x32,0x4F,0x63,0x74,0x39,0x32,0x52,0x45,0x56,0x49,0x53,0x49,0x4F,0x4E,0x35,
219   0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x01,
220   0x00,0x02,0x00,0x00,0x00,0x01
221}; /* CgangpzlDefaultNvMem */
222
250223static UINT8 namcona1_nvmem[NA1_NVRAM_SIZE];
251224
252225static NVRAM_HANDLER( namcosna1 )
r936r937
274247         case NAMCO_QUIZTOU:
275248            memcpy( namcona1_nvmem, QuiztouDefaultNvMem, sizeof(QuiztouDefaultNvMem) );
276249            break;
250
251         case NAMCO_CGANGPZL:
252            memcpy( namcona1_nvmem, CgangpzlDefaultNvMem, sizeof(CgangpzlDefaultNvMem) );
253            break;
277254         }
278255      }
279256   }
src/mame/drivers/mpu4.c
r936r937
17541754   machine->gfx[mpu4_gfx_index+3] = allocgfx(&mpu4_vid_char_16x16_layout);
17551755
17561756   /* set the color information */
1757   machine->gfx[mpu4_gfx_index+0]->colortable = machine->pens;
17581757   machine->gfx[mpu4_gfx_index+0]->total_colors = machine->drv->total_colors / 16;
1759   machine->gfx[mpu4_gfx_index+1]->colortable = machine->pens;
17601758   machine->gfx[mpu4_gfx_index+1]->total_colors = machine->drv->total_colors / 16;
1761   machine->gfx[mpu4_gfx_index+2]->colortable = machine->pens;
17621759   machine->gfx[mpu4_gfx_index+2]->total_colors = machine->drv->total_colors / 16;
1763   machine->gfx[mpu4_gfx_index+3]->colortable = machine->pens;
17641760   machine->gfx[mpu4_gfx_index+3]->total_colors = machine->drv->total_colors / 16;
17651761
17661762   scn2675_IR_pointer = 0;
src/mame/drivers/deniam.c
r936r937
309309static void irqhandler(int linestate)
310310{
311311   /* system 16c doesn't have the sound CPU */
312   if (Machine->drv->cpu[1].cpu_type)
312   if (Machine->drv->cpu[1].cpu_type != CPU_DUMMY)
313313      cpunum_set_input_line(1,0,linestate);
314314}
315315
src/mame/drivers/limenko.c
r936r937
225225      gfx.width = width;
226226      gfx.height = height;
227227      gfx.total_elements = 1;
228      gfx.color_depth = 256;
228229      gfx.color_granularity = 256;
229      gfx.colortable = machine->remapped_colortable;
230      gfx.color_base = 0;
230231      gfx.total_colors = 0x10;
231232      gfx.pen_usage = NULL;
232233      gfx.gfxdata = gfxdata;
src/mame/drivers/polepos.c
r936r937
912912   MDRV_SCREEN_SIZE(32*8, 32*8)
913913   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
914914   MDRV_GFXDECODE(gfxdecodeinfo)
915   MDRV_PALETTE_LENGTH(128)
916   MDRV_COLORTABLE_LENGTH(0x0f00)
915   MDRV_PALETTE_LENGTH(0x0f00)
917916
918917   MDRV_PALETTE_INIT(polepos)
919918   MDRV_VIDEO_START(polepos)
src/mame/drivers/cps2.c
r936r937
66386638
66396639ROM_START( xmcotaj )
66406640   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
6641   ROM_LOAD16_WORD_SWAP( "xmnj.03d", 0x000000, 0x80000, CRC(79086d62) SHA1(d99a48bd40593aa9c1ff1fcbfc40cfe3bc882fc5) )
6642   ROM_LOAD16_WORD_SWAP( "xmnj.04d", 0x080000, 0x80000, CRC(38eed613) SHA1(86ecb58bf03adda705a39a9779862fe2c85cadad) )
6643   ROM_LOAD16_WORD_SWAP( "xmn.05",   0x100000, 0x80000, CRC(c3ed62a2) SHA1(4e3317d7ca981e33318822103a16e59f4ce20deb) )
6644   ROM_LOAD16_WORD_SWAP( "xmn.06",   0x180000, 0x80000, CRC(f03c52e1) SHA1(904b2312ee594f5ece0484cad0eed25cc758185e) )
6645   ROM_LOAD16_WORD_SWAP( "xmn.07",   0x200000, 0x80000, CRC(325626b1) SHA1(3f3a0aabbe5ffad8136ac91e0de785103b16059b) )
6646   ROM_LOAD16_WORD_SWAP( "xmn.08",   0x280000, 0x80000, CRC(7194ea10) SHA1(40a5892d816f24cbfd4c310792eeabf689c6fa7e) )
6647   ROM_LOAD16_WORD_SWAP( "xmn.09",   0x300000, 0x80000, CRC(ae946df3) SHA1(733671f76d766bda7110df9d338791cc5202b050) )
6648   ROM_LOAD16_WORD_SWAP( "xmn.10",   0x380000, 0x80000, CRC(32a6be1d) SHA1(8f5fcb33b528abed670b4fc3fa62431a6e033c56) )
6649
6650   ROM_REGION( 0x2000000, REGION_GFX1, 0 )
6651   ROMX_LOAD( "xmn.13m",   0x0000000, 0x400000, CRC(bf4df073) SHA1(4d2740c3a827f0ec2cf75ad99c65e393c6a11c23) , ROM_GROUPWORD | ROM_SKIP(6) )
6652   ROMX_LOAD( "xmn.15m",   0x0000002, 0x400000, CRC(4d7e4cef) SHA1(50b8797b8099a8d76ad063ba1201a13dbb88ae3a) , ROM_GROUPWORD | ROM_SKIP(6) )
6653   ROMX_LOAD( "xmn.17m",   0x0000004, 0x400000, CRC(513eea17) SHA1(a497477ad9ac13180911d8745ef6ee1955c0b877) , ROM_GROUPWORD | ROM_SKIP(6) )
6654   ROMX_LOAD( "xmn.19m",   0x0000006, 0x400000, CRC(d23897fc) SHA1(1e31627999736652252164d32662779a1ac6ca29) , ROM_GROUPWORD | ROM_SKIP(6) )
6655   ROMX_LOAD( "xmn.14m",   0x1000000, 0x400000, CRC(778237b7) SHA1(89a759ec383518ec52f5059d10ec342f2247aa20) , ROM_GROUPWORD | ROM_SKIP(6) )
6656   ROMX_LOAD( "xmn.16m",   0x1000002, 0x400000, CRC(67b36948) SHA1(692fb6e4096b880aa22996d554b160f664bbd907) , ROM_GROUPWORD | ROM_SKIP(6) )
6657   ROMX_LOAD( "xmn.18m",   0x1000004, 0x400000, CRC(015a7c4c) SHA1(cccc95dafd076a1a9fa004710006149c42d058ba) , ROM_GROUPWORD | ROM_SKIP(6) )
6658   ROMX_LOAD( "xmn.20m",   0x1000006, 0x400000, CRC(9dde2758) SHA1(17ba259cad03c7b5d56c0a5eda9ab53521665729) , ROM_GROUPWORD | ROM_SKIP(6) )
6659
6660   ROM_REGION( QSOUND_SIZE, REGION_CPU2, 0 ) /* 64k for the audio CPU (+banks) */
6661   ROM_LOAD( "xmn.01a",  0x00000, 0x08000, CRC(40f479ea) SHA1(f29e15f537675305264ae2138a0a537fb9e2008b) )
6662   ROM_CONTINUE(         0x10000, 0x18000 )
6663   ROM_LOAD( "xmn.02a",  0x28000, 0x20000, CRC(39d9b5ad) SHA1(af502debfd36100d4fc971ed25fdf9d7121d6f18) )
6664
6665   ROM_REGION( 0x400000, REGION_SOUND1, 0 ) /* QSound samples */
6666   ROM_LOAD16_WORD_SWAP( "xmn.11m",   0x000000, 0x200000, CRC(c848a6bc) SHA1(ac8ac564d3c43225822f8bc330eba9f35b24b0a4) )
6667   ROM_LOAD16_WORD_SWAP( "xmn.12m",   0x200000, 0x200000, CRC(729c188f) SHA1(3279774ad8aebbcf0fc779cdfcbe21044dd192ad) )
6668ROM_END
6669
6670ROM_START( xmcotaj1 )
6671   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
66416672   ROM_LOAD16_WORD_SWAP( "xmnj.03b", 0x000000, 0x80000, CRC(c8175fb3) SHA1(ea25bd165f8794324a1e07719312798cf9742924) )
66426673   ROM_LOAD16_WORD_SWAP( "xmnj.04b", 0x080000, 0x80000, CRC(54b3fba3) SHA1(47eaff5d36a45e4196f87ed3d02e54d5407e7962) )
66436674   ROM_LOAD16_WORD_SWAP( "xmn.05",   0x100000, 0x80000, CRC(c3ed62a2) SHA1(4e3317d7ca981e33318822103a16e59f4ce20deb) )
r936r937
66676698   ROM_LOAD16_WORD_SWAP( "xmn.12m",   0x200000, 0x200000, CRC(729c188f) SHA1(3279774ad8aebbcf0fc779cdfcbe21044dd192ad) )
66686699ROM_END
66696700
6670ROM_START( xmcotaj1 )
6701ROM_START( xmcotaj2 )
66716702   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
66726703   ROM_LOAD16_WORD_SWAP( "xmnj.03a", 0x000000, 0x80000, CRC(00761611) SHA1(e780dbe1d21a0d5b6981f0395942c9fa59688113) )
66736704   ROM_LOAD16_WORD_SWAP( "xmnj.04a", 0x080000, 0x80000, CRC(614d3f60) SHA1(2272ae243557562a0bc85d2cd2b37dd876f6902c) )
r936r937
71487179GAME( 1994, xmcota,   0,       cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Euro 950105)", 0 )
71497180GAME( 1994, xmcotau,  xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (USA 950105)", 0 )
71507181GAME( 1994, xmcotah,  xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Hispanic 950331)", 0 )
7151GAME( 1994, xmcotaj,  xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941219)", 0 )
7152GAME( 1994, xmcotaj1, xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941217)", 0 )
7182GAME( 1994, xmcotaj,  xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941222)", 0 )
7183GAME( 1994, xmcotaj1, xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941219)", 0 )
7184GAME( 1994, xmcotaj2, xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941217)", 0 )
71537185GAME( 1994, xmcotajr, xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Japan 941208 rent version)", 0 )
71547186GAME( 1994, xmcotaa,  xmcota,  cps2, ssf2,    cps2, ROT0,   "Capcom", "X-Men: Children of the Atom (Asia 941217)", 0 )
71557187GAME( 1994, armwar,   0,       cps2, avsp,    cps2, ROT0,   "Capcom", "Armored Warriors (Euro 941024)", 0 )
src/mame/drivers/darius.c
r936r937
366366   int left, right;
367367   left  = (        darius_pan[0]  * darius_vol[6])>>8;
368368   right = ((0xff - darius_pan[0]) * darius_vol[6])>>8;
369   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 6) >= 0)
369   if (sndti_exists(SOUND_FILTER_VOLUME, 6))
370370      flt_volume_set_volume(6, left / 100.0);
371   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 7) >= 0)
371   if (sndti_exists(SOUND_FILTER_VOLUME, 7))
372372      flt_volume_set_volume(7, right / 100.0); /* FM #0 */
373373}
374374
r936r937
377377   int left, right;
378378   left  = (        darius_pan[1]  * darius_vol[7])>>8;
379379   right = ((0xff - darius_pan[1]) * darius_vol[7])>>8;
380   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 14) >= 0)
380   if (sndti_exists(SOUND_FILTER_VOLUME, 14))
381381      flt_volume_set_volume(14, left / 100.0);
382   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 15) >= 0)
382   if (sndti_exists(SOUND_FILTER_VOLUME, 15))
383383      flt_volume_set_volume(15, right / 100.0); /* FM #1 */
384384}
385385
r936r937
388388   int left, right;
389389   left  = (        darius_pan[2]  * darius_vol[port])>>8;
390390   right = ((0xff - darius_pan[2]) * darius_vol[port])>>8;
391   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, port*2+0) >= 0)
391   if (sndti_exists(SOUND_FILTER_VOLUME, port*2+0))
392392      flt_volume_set_volume(port*2+0, left / 100.0);
393   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, port*2+1) >= 0)
393   if (sndti_exists(SOUND_FILTER_VOLUME, port*2+1))
394394      flt_volume_set_volume(port*2+1, right / 100.0);
395395}
396396
r936r937
399399   int left, right;
400400   left  = (        darius_pan[3]  * darius_vol[port + 3])>>8;
401401   right = ((0xff - darius_pan[3]) * darius_vol[port + 3])>>8;
402   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, port*2+0+8) >= 0)
402   if (sndti_exists(SOUND_FILTER_VOLUME, port*2+0+8))
403403      flt_volume_set_volume(port*2+0+8, left / 100.0);
404   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, port*2+1+8) >= 0)
404   if (sndti_exists(SOUND_FILTER_VOLUME, port*2+1+8))
405405      flt_volume_set_volume(port*2+1+8, right / 100.0);
406406}
407407
r936r937
410410   int left, right;
411411   left  = darius_def_vol[(darius_pan[4]>>4)&0x0f];
412412   right = darius_def_vol[(darius_pan[4]>>0)&0x0f];
413   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 16) >= 0)
413   if (sndti_exists(SOUND_FILTER_VOLUME, 16))
414414      flt_volume_set_volume(16, left / 100.0);
415   if (sndti_to_sndnum(SOUND_FILTER_VOLUME, 17) >= 0)
415   if (sndti_exists(SOUND_FILTER_VOLUME, 17))
416416      flt_volume_set_volume(17, right / 100.0); /* FM #1 */
417417}
418418
src/mame/drivers/st0016.c
r936r937
33    driver by Tomasz Slanina
44********************************************
55
6
76Todo:
87- find NMI source, and NMI enable/disable (timer ? video hw ?)
98
109Not working games :
1110- Super Real Mahjong P5
12- Super Eagle Shot
13   RAM 0x0a000000 - 0x0a003fff (8bit) is shared with ST-0016 ($f000-$ffff)
14   after boot, r3000 writes there "KCUFUOY" , and  ST-0016 "YOU!" ;)
1511*/
1612
1713#include "driver.h"
r936r937
130126   AM_RANGE(0x1fc00000, 0x1fdfffff) AM_READ(MRA32_ROM) AM_WRITE(MWA32_ROM) AM_REGION(REGION_USER1, 0)
131127ADDRESS_MAP_END
132128
133static ADDRESS_MAP_START( speglsht_mem, ADDRESS_SPACE_PROGRAM, 32 )
134   AM_RANGE(0x00000000, 0x000fffff) AM_RAM
135   AM_RANGE(0x01800200, 0x01800203) AM_WRITE(MWA32_RAM)
136   AM_RANGE(0x01a00000, 0x01afffff) AM_RAM
137   AM_RANGE(0x01c00000, 0x01c00003) AM_READ(MRA32_RAM)
138   AM_RANGE(0x01ca5000, 0x01ca6fff) AM_RAM /* i/o ?? */
139   AM_RANGE(0x0a000000, 0x0a003fff) AM_RAM /* shared with st-0016 ! */
140   AM_RANGE(0x1eff0000, 0x1eff001f) AM_WRITE(MWA32_RAM)
141   AM_RANGE(0x1fc00000, 0x1fdfffff) AM_READ(MRA32_ROM) AM_WRITE(MWA32_ROM) AM_REGION(REGION_USER1, 0)
142ADDRESS_MAP_END
143
144129/*************************************
145130 *
146131 *  Machine's structure ST0016 + V810
r936r937
162147      latches[2]|=1;
163148   COMBINE_DATA(&latches[offset]);
164149   timer_call_after_resynch(0, NULL);
165
166150}
167151
168152static READ8_HANDLER(latch8_r)
r936r937
445429   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
446430INPUT_PORTS_END
447431
448INPUT_PORTS_START( speglsht )
449   PORT_INCLUDE( st0016 )
450
451   PORT_MODIFY("DSW1")   /* Dip switch A  */
452   PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) )
453   PORT_DIPSETTING(    0x03, DEF_STR( 3C_1C ) )
454   PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
455   PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
456   PORT_DIPSETTING(    0x01, "1C/1C or 2C/3C" ) /* 1 coin/1 credit or 2 coins/3 credits */
457   PORT_DIPSETTING(    0x02, DEF_STR( 2C_3C ) )
458   PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
459   PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
460   PORT_DIPSETTING(    0x00, "2C Start/1C Continue" )
461   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Coin_B ) )
462   PORT_DIPSETTING(    0x18, DEF_STR( 3C_1C ) )
463   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) )
464   PORT_DIPSETTING(    0x38, DEF_STR( 1C_1C ) )
465   PORT_DIPSETTING(    0x08, "1C/1C or 2C/3C" ) /* 1 coin/1 credit or 2 coins/3 credits */
466   PORT_DIPSETTING(    0x10, DEF_STR( 2C_3C ) )
467   PORT_DIPSETTING(    0x30, DEF_STR( 1C_2C ) )
468   PORT_DIPSETTING(    0x28, DEF_STR( 1C_3C ) )
469   PORT_DIPSETTING(    0x00, "2C Start/1C Continue" )
470   PORT_DIPNAME( 0x40, 0x40, "Unkown / Unused" )
471   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
472   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
473   PORT_DIPNAME( 0x80, 0x80, "Bonus for PAR Play" )
474   PORT_DIPSETTING(    0x80, DEF_STR( None ) )
475   PORT_DIPSETTING(    0x00, "Extra Hole" )
476
477   PORT_MODIFY("DSW2")   /* Dip switch B */
478   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ) )
479   PORT_DIPSETTING(    0x03, DEF_STR( Normal ) )
480   PORT_DIPSETTING(    0x02, DEF_STR( Easy ) )
481   PORT_DIPSETTING(    0x01, DEF_STR( Hard ) )
482   PORT_DIPSETTING(    0x00, DEF_STR( Very_Hard ) )
483   PORT_DIPNAME( 0x0c, 0x0c, "Number of Players" )
484   PORT_DIPSETTING(    0x0c, "3" )
485   PORT_DIPSETTING(    0x08, "4" )
486   PORT_DIPSETTING(    0x04, "2" )
487   PORT_DIPSETTING(    0x00, "1" )
488   PORT_DIPNAME( 0x10, 0x00, DEF_STR( Demo_Sounds ) )
489   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
490   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
491   PORT_DIPNAME( 0x20, 0x20, "Control Panel" )
492   PORT_DIPSETTING(    0x00, "2P Pair" )
493   PORT_DIPSETTING(    0x40, DEF_STR( Single ) )
494   PORT_DIPNAME( 0x40, 0x40, "Country" )
495   PORT_DIPSETTING(    0x40, DEF_STR( Japan ) )
496   PORT_DIPSETTING(    0x00, "North America" )
497   PORT_DIPNAME( 0x80, 0x80, "Test Mode" )
498   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
499   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
500INPUT_PORTS_END
501
502432INPUT_PORTS_START( srmp5 )
503433   PORT_START_TAG("IN0")
504434   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )
r936r937
590520
591521static MACHINE_DRIVER_START( srmp5 )
592522   MDRV_IMPORT_FROM(st0016)
593   MDRV_CPU_ADD(R3000BE, 16000000)
523   MDRV_CPU_ADD(R3000LE, 16000000)
594524   MDRV_CPU_CONFIG(config)
595525   MDRV_CPU_PROGRAM_MAP(srmp5_mem,0)
596526MACHINE_DRIVER_END
597527
598static MACHINE_DRIVER_START( speglsht )
599   MDRV_IMPORT_FROM(st0016)
600   MDRV_CPU_ADD(R3000BE, 16000000)
601   MDRV_CPU_CONFIG(config)
602   MDRV_CPU_PROGRAM_MAP(speglsht_mem,0)
603MACHINE_DRIVER_END
604
605528/*************************************
606529 *
607530 *  ROM definition(s)
r936r937
736659ROM_END
737660
738661/*
739Super Eagle Shot
740(c)1993 Seta (distributed by Visco)
741E30-001A
742
743CPU  : Integrated Device IDT79R3051-25J 9407C (R3000A)
744Sound: ST-0016
745OSC  : 50.0000MHz (X1) 42.9545MHz (X3)
746
747ROMs:
748SX004-01.PR0 - Main programs (MX27C4000)
749SX004-02.PR1 |
750SX004-03.PR2 |
751SX004-04.PR3 /
752
753SX004-05.RD0 - Graphics? (D23C8000SCZ)
754SX004-06.RD1 /
755
756SX004-07.ZPR - Program? (16M mask, read as 27c160)
757
758GALs (not dumped):
759SX004-08.27 (16V8B)
760SX004-09.46 (16V8B)
761SX004-10.59 (16V8B)
762SX004-11.61 (22V10B)
763SX004-12.62 (22V10B)
764SX004-13.63 (22V10B)
765
766Custom chips:
767SETA ST-0015 60EN502F12 JAPAN 9415YAI (U18, 208pin PQFP, system controller)
768SETA ST-0016 TC6187AF JAPAN 9348YAA (U68, 208pin PQFP, sound & object)
769
770   ?      ST-0015              SX004-01   49.9545MHz    ST-0016       5588-25
771                               SX004-02      52B256-70  514256 514256
772 50MHz                         SX004-03      52B256-70  SX004-07
773 528257-70 514256-70 514256-70 SX004-04
774 528257-70 514256-70 514256-70 SX004-05
775 528257-70 514256-70 514256-70 SX004-06
776           514256-70 514256-70
777                                                NEC D6376
778
779*/
780
781ROM_START( speglsht )
782   ROM_REGION( 0x210000, REGION_CPU1, 0 )
783   ROM_LOAD( "sx004-07",   0x10000, 0x200000,   CRC(2d759cc4) SHA1(9fedd829190b2aab850b2f1088caaec91e8715dd) )
784   ROM_COPY( REGION_CPU1,  0x10000, 0x00000, 0x08000 )
785
786   ROM_REGION32_BE( 0x200000, REGION_USER1, 0 )
787   ROM_LOAD32_BYTE( "sx004-04.u33",   0x00000, 0x80000,   CRC(e46d2e57) SHA1(b1fb836ab2ce547dc2e8d1046d7ef835b87bb04e) )
788   ROM_LOAD32_BYTE( "sx004-03.u32",   0x00001, 0x80000,   CRC(c6ffb00e) SHA1(f57ef45bb5c690c3e63101a36835d2687abfcdbd) )
789   ROM_LOAD32_BYTE( "sx004-02.u31",   0x00002, 0x80000,   CRC(21eb46e4) SHA1(0ab21ed012c9a76e01c83b60c6f4670836dfa718) )
790   ROM_LOAD32_BYTE( "sx004-01.u30",   0x00003, 0x80000,   CRC(65646949) SHA1(74931c230f4e4b1008fbc5fba169292e216aa23b) )
791
792   ROM_REGION( 0x200000, REGION_USER2,0)
793   ROM_LOAD( "sx004-05",   0x000000, 0x100000,   CRC(4b8ae72b) SHA1(261495edf41d7797d2ea8d442ac6a8362bafadf2) )
794   ROM_LOAD( "sx004-06",   0x100000, 0x100000,   CRC(5af78e44) SHA1(0131d50348fef80c2b100d74b7c967c6a710d548) )
795ROM_END
796
797ROM_START( speglsha )
798   ROM_REGION( 0x210000, REGION_CPU1, 0 )
799   ROM_LOAD( "sx004-07",   0x10000, 0x200000,   CRC(2d759cc4) SHA1(9fedd829190b2aab850b2f1088caaec91e8715dd) )
800   ROM_COPY( REGION_CPU1,  0x10000, 0x00000, 0x08000 )
801
802   ROM_REGION32_BE( 0x200000, REGION_USER1, 0 )
803   ROM_LOAD32_BYTE( "sx004-04.u33",   0x00000, 0x80000,   CRC(e46d2e57) SHA1(b1fb836ab2ce547dc2e8d1046d7ef835b87bb04e) )
804   ROM_LOAD32_BYTE( "sx004-03.u32",   0x00001, 0x80000,   CRC(c6ffb00e) SHA1(f57ef45bb5c690c3e63101a36835d2687abfcdbd) )
805   ROM_LOAD32_BYTE( "sx004-02.u31",   0x00002, 0x80000,   CRC(21eb46e4) SHA1(0ab21ed012c9a76e01c83b60c6f4670836dfa718) )
806   ROM_LOAD32_BYTE( "sx004-01.u30",   0x00003, 0x80000,   CRC(65646949) SHA1(74931c230f4e4b1008fbc5fba169292e216aa23b) )
807
808   ROM_REGION( 0x200000, REGION_USER2,0)
809   ROM_LOAD( "sx004-05.rd0",   0x000000, 0x100000,   CRC(f3c69468) SHA1(81daef6d0596cb67bb6f87b39874aae1b1ffe6a6) )
810   ROM_LOAD( "sx004-06",       0x100000, 0x100000,   CRC(5af78e44) SHA1(0131d50348fef80c2b100d74b7c967c6a710d548) )
811ROM_END
812
813/*
814662Mayjinsen (JPN Ver.)
815663(c)1994 Seta
816664
r936r937
910758   st0016_game=2;
911759}
912760
913static DRIVER_INIT(speglsht)
914{
915   st0016_game=3;
916}
917
918761static DRIVER_INIT(mayjinsn)
919762{
920763   st0016_game=4|0x80;
r936r937
939782GAME(  1995, koikois,    0,     st0016, koikois, renju, ROT0, "Visco",  "Koi Koi Shimasho", GAME_IMPERFECT_GRAPHICS)
940783/* Not working */
941784GAME( 199?, srmp5,   0,     srmp5,    srmp5,    srmp5,    ROT0, "Seta",  "Super Real Mahjong P5",GAME_NOT_WORKING)
942GAME( 1994, speglsht,   0,     speglsht, speglsht, speglsht, ROT0, "Seta",  "Super Eagle Shot (set 1)",GAME_NOT_WORKING)
943GAME( 1994, speglsha,   speglsht, speglsht, speglsht, speglsht, ROT0, "Seta",  "Super Eagle Shot (set 2)",GAME_NOT_WORKING)
944785GAME( 1994, mayjinsn,   0,     mayjinsn, st0016,   mayjinsn, ROT0, "Seta",  "Mayjinsen",GAME_IMPERFECT_GRAPHICS|GAME_NOT_WORKING)
src/mame/drivers/ironhors.c
r936r937
4747
4848static WRITE8_HANDLER( ironhors_filter_w )
4949{
50   if (sndti_to_sndnum(SOUND_FILTER_RC, 2) >= 0)
50   if (sndti_exists(SOUND_FILTER_RC, 2))
5151   {
5252      filter_rc_set_RC(0,FLT_RC_LOWPASS, 1000,2200,1000,data & 0x04 ? CAP_N(220) : 0); /* YM2203-SSG-A */
5353      filter_rc_set_RC(1,FLT_RC_LOWPASS, 1000,2200,1000,data & 0x02 ? CAP_N(220) : 0); /* YM2203-SSG-B */
src/mame/drivers/cps3.c
r936r937
432432
433433   /* 32-bit ONLY */
434434   {
435      if( gfx && gfx->colortable )
435      if( gfx )
436436      {
437//          const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
437//          const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
438438         UINT32 palbase = (gfx->color_granularity * color) & 0x1ffff;
439439         const pen_t *pal = &cps3_mame_colours[palbase];
440440         UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
r936r937
907907
908908   /* create the char set (gfx will then be updated dynamically from RAM) */
909909   machine->gfx[0] = allocgfx(&cps3_tiles8x8_layout);
910   machine->gfx[0]->colortable   = machine->pens;
911910   machine->gfx[0]->total_colors = machine->drv->total_colors / 16;
912911
913912   //decode_ssram();
914913
915914   /* create the char set (gfx will then be updated dynamically from RAM) */
916915   machine->gfx[1] = allocgfx(&cps3_tiles16x16_layout);
917   machine->gfx[1]->colortable   = machine->pens;
918916   machine->gfx[1]->total_colors = machine->drv->total_colors / 64;
919917   machine->gfx[1]->color_granularity=64;
920918
src/mame/drivers/bankp.c
r936r937
246246   1024,   /* 1024 characters */
247247   2,   /* 2 bits per pixel */
248248   { 0, 4 },   /* the bitplanes are packed in one byte */
249   { 8*8+3, 8*8+2, 8*8+1, 8*8+0, 3, 2, 1, 0 },
250   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
249   { STEP4(8*8+3,-1), STEP4(0*8+3,-1) },
250   { STEP8(0*8,8) },
251251   16*8   /* every char takes 8 consecutive bytes */
252252};
253253static const gfx_layout charlayout2 =
r936r937
256256   2048,   /* 2048 characters */
257257   3,   /* 3 bits per pixel */
258258   { 0, 2048*8*8, 2*2048*8*8 },   /* the bitplanes are separated */
259   { 7, 6, 5, 4, 3, 2, 1, 0 },
260   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
259   { STEP8(7,-1) },
260   { STEP8(0*8,8) },
261261   8*8   /* every char takes 8 consecutive bytes */
262262};
263263
r936r937
288288   MDRV_SCREEN_SIZE(32*8, 32*8)
289289   MDRV_SCREEN_VISIBLE_AREA(3*8, 31*8-1, 2*8, 30*8-1)
290290   MDRV_GFXDECODE(gfxdecodeinfo)
291   MDRV_PALETTE_LENGTH(32)
292   MDRV_COLORTABLE_LENGTH(32*4+16*8)
291   MDRV_PALETTE_LENGTH(32*4+16*8)
293292
294293   MDRV_PALETTE_INIT(bankp)
295294   MDRV_VIDEO_START(bankp)
src/mame/drivers/speglsht.c
r0r937
1/*
2Super Eagle Shot
3(c)1993 Seta (distributed by Visco)
4-----------------------------------
5driver by Tomasz Slanina
6
7
8GOLF
9E30-001A
10
11CPU           : Integrated Device IDT79R3051-25J 9407C (R3000A)
12Sound+Objects : ST-0016
13OSC           : 50.0000MHz (X1) 42.9545MHz (X3)
14
15ROMs:
16SX004-01.PR0 - R3051 Main programs (MX27C4000)
17SX004-02.PR1 |
18SX004-03.PR2 |
19SX004-04.PR3 /
20
21SX004-05.RD0 - Data and Graphics (D23C8000SCZ)
22SX004-06.RD1 /
23
24SX004-07.ZPR - ST-0016 Program and Data (16M mask, read as 27c160)
25
26GALs (not dumped):
27SX004-08.27 (16V8B)
28SX004-09.46 (16V8B)
29SX004-10.59 (16V8B)
30SX004-11.61 (22V10B)
31SX004-12.62 (22V10B)
32SX004-13.63 (22V10B)
33
34Custom chips:
35SETA ST-0015 60EN502F12 JAPAN 9415YAI (U18, 208pin PQFP, system controller)
36SETA ST-0016 TC6187AF JAPAN 9348YAA (U68, 208pin PQFP, sound & object)
37
38 R3051    ST-0015              SX004-01   49.9545MHz    ST-0016       5588-25
39                               SX004-02      52B256-70  514256 514256
40 50MHz                         SX004-03      52B256-70  SX004-07
41 528257-70 514256-70 514256-70 SX004-04
42 528257-70 514256-70 514256-70 SX004-05
43 528257-70 514256-70 514256-70 SX004-06
44           514256-70 514256-70
45                                                NEC D6376
46
47
48*/
49
50#include "driver.h"
51#include "cpu/z80/z80.h"
52#include "cpu/mips/r3000.h"
53#include "sound/st0016.h"
54#include "st0016.h"
55
56READ8_HANDLER(st0016_dma_r);
57static UINT8 *shared;
58
59UINT32 *speglsht_framebuffer;
60UINT32  speglsht_videoreg;
61
62extern UINT8 *st0016_charram;
63
64static ADDRESS_MAP_START( st0016_mem, ADDRESS_SPACE_PROGRAM, 8 )
65   AM_RANGE(0x0000, 0x7fff) AM_ROM
66   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK(1)
67   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
68   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
69   AM_RANGE(0xe000, 0xe7ff) AM_RAM
70   AM_RANGE(0xe800, 0xe87f) AM_RAM
71   AM_RANGE(0xe900, 0xe9ff) AM_RAM AM_WRITE(st0016_snd_w) AM_BASE(&st0016_sound_regs)
72   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
73   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
74   AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE(&shared)
75ADDRESS_MAP_END
76
77static ADDRESS_MAP_START( st0016_io, ADDRESS_SPACE_IO, 8 )
78   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
79   AM_RANGE(0x00, 0xbf) AM_READ(st0016_vregs_r) AM_WRITE(st0016_vregs_w)
80   AM_RANGE(0xe1, 0xe1) AM_WRITE(st0016_rom_bank_w)
81   AM_RANGE(0xe2, 0xe2) AM_WRITE(st0016_sprite_bank_w)
82   AM_RANGE(0xe3, 0xe4) AM_WRITE(st0016_character_bank_w)
83   AM_RANGE(0xe5, 0xe5) AM_WRITE(st0016_palette_bank_w)
84   AM_RANGE(0xe6, 0xe6) AM_WRITENOP
85   AM_RANGE(0xe7, 0xe7) AM_WRITENOP
86   AM_RANGE(0xf0, 0xf0) AM_READ(st0016_dma_r)
87ADDRESS_MAP_END
88
89static READ32_HANDLER(shared_r)
90{
91   return shared[offset];
92}
93
94static WRITE32_HANDLER(shared_w)
95{
96   shared[offset]=data&0xff;
97}
98
99static WRITE32_HANDLER(videoreg_w)
100{
101   COMBINE_DATA(&speglsht_videoreg);
102}
103
104static UINT32 *cop_ram;
105
106static WRITE32_HANDLER(cop_w)
107{
108   COMBINE_DATA(&cop_ram[offset]);
109
110   if(cop_ram[offset]&0x8000) //fix (sign)
111   {
112      cop_ram[offset]|=0xffff0000;
113   }
114}
115
116//matrix * vector
117static READ32_HANDLER(cop_r)
118{
119   INT32 *cop=(INT32*)&cop_ram[0];
120
121   union
122   {
123      INT32  a;
124      UINT32 b;
125   }temp;
126
127   switch (offset)
128   {
129      case 0x40/4:
130      {
131         temp.a=((cop[0x3]*cop[0x0]+cop[0x4]*cop[0x1]+cop[0x5]*cop[0x2])>>14)+cop[0xc];
132         return temp.b;
133      }
134
135      case 0x44/4:
136      {
137         temp.a=((cop[0x6]*cop[0x0]+cop[0x7]*cop[0x1]+cop[0x8]*cop[0x2])>>14)+cop[0xd];
138         return temp.b;
139      }
140
141      case 0x48/4:
142      {
143         temp.a=((cop[0x9]*cop[0x0]+cop[0xa]*cop[0x1]+cop[0xb]*cop[0x2])>>14)+cop[0xe];
144         return temp.b;
145      }
146   }
147
148   return 0;
149}
150
151static ADDRESS_MAP_START( speglsht_mem, ADDRESS_SPACE_PROGRAM, 32 )
152   AM_RANGE(0x00000000, 0x000fffff) AM_RAM
153   AM_RANGE(0x01000000, 0x01007fff) AM_RAM //tested - STATIC RAM
154   AM_RANGE(0x01600000, 0x0160004f) AM_READWRITE(cop_r, cop_w) AM_BASE(&cop_ram)
155   AM_RANGE(0x01800200, 0x01800203) AM_WRITE(videoreg_w)
156   AM_RANGE(0x01800300, 0x01800303) AM_READ(input_port_0_dword_r)
157   AM_RANGE(0x01800400, 0x01800403) AM_READ(input_port_1_dword_r)
158   AM_RANGE(0x01a00000, 0x01afffff) AM_RAM AM_BASE(&speglsht_framebuffer)
159   AM_RANGE(0x01b00000, 0x01b07fff) AM_RAM //cleared ...  video related ?
160   AM_RANGE(0x01c00000, 0x01dfffff) AM_READ(MRA32_ROM) AM_WRITE(MWA32_ROM) AM_REGION(REGION_USER2, 0)
161   AM_RANGE(0x0a000000, 0x0a003fff) AM_READWRITE(shared_r, shared_w)
162   AM_RANGE(0x1eff0000, 0x1eff001f) AM_RAM
163   AM_RANGE(0x1eff003c, 0x1eff003f) AM_READNOP //interrupt related
164   AM_RANGE(0x1fc00000, 0x1fdfffff) AM_ROM AM_REGION(REGION_USER1, 0)
165   AM_RANGE(0x2fc00000, 0x2fdfffff) AM_ROM AM_REGION(REGION_USER1, 0) // mirror for interrupts
166ADDRESS_MAP_END
167
168static INPUT_PORTS_START( speglsht )
169
170PORT_START
171   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
172   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
173   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
174   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
175   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
176   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
177   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
178  PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
179   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
180   PORT_BIT( 0xffff0000, IP_ACTIVE_LOW, IPT_UNUSED )
181
182PORT_START
183   PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coin_A ) )
184   PORT_DIPSETTING(    0x0003, DEF_STR( 3C_1C ) )
185   PORT_DIPSETTING(    0x0004, DEF_STR( 2C_1C ) )
186   PORT_DIPSETTING(    0x0007, DEF_STR( 1C_1C ) )
187   PORT_DIPSETTING(    0x0001, "1C/1C or 2C/3C" ) /* 1 coin/1 credit or 2 coins/3 credits */
188   PORT_DIPSETTING(    0x0002, DEF_STR( 2C_3C ) )
189   PORT_DIPSETTING(    0x0006, DEF_STR( 1C_2C ) )
190   PORT_DIPSETTING(    0x0005, DEF_STR( 1C_3C ) )
191   PORT_DIPSETTING(    0x0000, "2C Start/1C Continue" )
192   PORT_DIPNAME( 0x0038, 0x0038, DEF_STR( Coin_B ) )
193   PORT_DIPSETTING(    0x0018, DEF_STR( 3C_1C ) )
194   PORT_DIPSETTING(    0x0020, DEF_STR( 2C_1C ) )
195   PORT_DIPSETTING(    0x0038, DEF_STR( 1C_1C ) )
196   PORT_DIPSETTING(    0x0008, "1C/1C or 2C/3C" ) /* 1 coin/1 credit or 2 coins/3 credits */
197   PORT_DIPSETTING(    0x0010, DEF_STR( 2C_3C ) )
198   PORT_DIPSETTING(    0x0030, DEF_STR( 1C_2C ) )
199   PORT_DIPSETTING(    0x0028, DEF_STR( 1C_3C ) )
200   PORT_DIPSETTING(    0x0000, "2C Start/1C Continue" )
201   PORT_DIPNAME( 0x0040, 0x0040, "Unkown / Unused" )
202   PORT_DIPSETTING(    0x0040, DEF_STR( Off ) )
203   PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
204   PORT_DIPNAME( 0x0080, 0x0080, "Bonus for PAR Play" )
205   PORT_DIPSETTING(    0x0080, DEF_STR( None ) )
206   PORT_DIPSETTING(    0x0000, "Extra Hole" )
207   PORT_DIPNAME( 0x0300, 0x0300, DEF_STR( Difficulty ) )
208   PORT_DIPSETTING(    0x0300, DEF_STR( Normal ) )
209   PORT_DIPSETTING(    0x0200, DEF_STR( Easy ) )
210   PORT_DIPSETTING(    0x0100, DEF_STR( Hard ) )
211   PORT_DIPSETTING(    0x0000, DEF_STR( Very_Hard ) )
212   PORT_DIPNAME( 0x0c00, 0x0c00, "Number of Players" )
213   PORT_DIPSETTING(    0x0c00, "3" )
214   PORT_DIPSETTING(    0x0800, "4" )
215   PORT_DIPSETTING(    0x0400, "2" )
216   PORT_DIPSETTING(    0x0000, "1" )
217   PORT_DIPNAME( 0x1000, 0x0000, DEF_STR( Demo_Sounds ) )
218   PORT_DIPSETTING(    0x1000, DEF_STR( Off ) )
219   PORT_DIPSETTING(    0x0000, DEF_STR( On ) )
220   PORT_DIPNAME( 0x2000, 0x0000, "Control Panel" )
221   PORT_DIPSETTING(    0x2000, "Double" )
222   PORT_DIPSETTING(    0x0000, DEF_STR( Single ) )
223   PORT_DIPNAME( 0x4000, 0x4000, "Country" )
224   PORT_DIPSETTING(    0x4000, DEF_STR( Japan ) )
225   PORT_DIPSETTING(    0x0000, DEF_STR( USA ) )
226   PORT_BIT( 0x00008000, IP_ACTIVE_LOW, IPT_UNUSED )
227   PORT_BIT( 0x00010000, IP_ACTIVE_HIGH, IPT_SERVICE ) PORT_NAME("Test Mode") PORT_CODE(KEYCODE_F2)
228   PORT_BIT( 0x00020000, IP_ACTIVE_LOW, IPT_TILT )
229   PORT_BIT( 0x00040000, IP_ACTIVE_LOW, IPT_COIN1 )
230   PORT_BIT( 0x00080000, IP_ACTIVE_LOW, IPT_COIN2 )
231   PORT_BIT( 0x00100000, IP_ACTIVE_LOW, IPT_SERVICE1 )
232   PORT_BIT( 0x80A00000, IP_ACTIVE_LOW, IPT_UNUSED )
233   PORT_BIT( 0x00400000, IP_ACTIVE_LOW, IPT_START1 )
234   PORT_BIT( 0x01000000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
235   PORT_BIT( 0x02000000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
236   PORT_BIT( 0x04000000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
237   PORT_BIT( 0x08000000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
238   PORT_BIT( 0x10000000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
239   PORT_BIT( 0x20000000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
240  PORT_BIT( 0x40000000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
241INPUT_PORTS_END
242
243static const gfx_decode gfxdecodeinfo[] =
244{
245   { -1 }   /* end of array */
246};
247
248static struct ST0016interface st0016_interface =
249{
250   &st0016_charram
251};
252
253 static INTERRUPT_GEN( irq4_gen )
254{
255   cpunum_set_input_line(1, R3000_IRQ4, ASSERT_LINE);
256}
257
258static struct r3000_config config =
259{
260   0,
261   4096,   /* code cache size */
262   2048   /* data cache size */
263};
264
265static MACHINE_RESET(speglsht)
266{
267   memset(shared,0,0x1000);
268}
269
270static MACHINE_DRIVER_START( speglsht )
271   /* basic machine hardware */
272   MDRV_CPU_ADD_TAG("main",Z80, 8000000) /* 8 MHz ? */
273   MDRV_CPU_PROGRAM_MAP(st0016_mem,0)
274   MDRV_CPU_IO_MAP(st0016_io,0)
275
276   MDRV_CPU_VBLANK_INT(irq0_line_hold,1)
277
278   MDRV_CPU_ADD(R3000LE, 25000000)
279   MDRV_CPU_CONFIG(config)
280   MDRV_CPU_PROGRAM_MAP(speglsht_mem,0)
281   MDRV_CPU_VBLANK_INT(irq4_gen,1)
282
283   MDRV_SCREEN_REFRESH_RATE(60)
284   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
285   MDRV_INTERLEAVE(100)
286   MDRV_MACHINE_RESET(speglsht)
287
288   /* video hardware */
289   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
290   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
291   MDRV_SCREEN_SIZE(512, 512)
292   MDRV_SCREEN_VISIBLE_AREA(0, 319, 8, 239-8)
293   MDRV_GFXDECODE(gfxdecodeinfo)
294   MDRV_PALETTE_LENGTH(16*16*4+1)
295
296   MDRV_VIDEO_START(st0016)
297   MDRV_VIDEO_UPDATE(st0016)
298
299   MDRV_SPEAKER_STANDARD_STEREO("left", "right")
300
301   MDRV_SOUND_ADD(ST0016, 0)
302   MDRV_SOUND_CONFIG(st0016_interface)
303   MDRV_SOUND_ROUTE(0, "left", 1.0)
304   MDRV_SOUND_ROUTE(1, "right", 1.0)
305MACHINE_DRIVER_END
306
307ROM_START( speglsht )
308   ROM_REGION( 0x210000, REGION_CPU1, 0 )
309   ROM_LOAD( "sx004-07",         0x010000, 0x200000,   CRC(2d759cc4) SHA1(9fedd829190b2aab850b2f1088caaec91e8715dd) )
310
311   ROM_COPY( REGION_CPU1,  0x10000, 0x00000, 0x08000 )
312
313   ROM_REGION32_BE( 0x200000, REGION_USER1, 0 )
314   ROM_LOAD32_BYTE( "sx004-04.u33",   0x00000, 0x80000,   CRC(e46d2e57) SHA1(b1fb836ab2ce547dc2e8d1046d7ef835b87bb04e) )
315   ROM_LOAD32_BYTE( "sx004-03.u32",   0x00001, 0x80000,   CRC(c6ffb00e) SHA1(f57ef45bb5c690c3e63101a36835d2687abfcdbd) )
316   ROM_LOAD32_BYTE( "sx004-02.u31",   0x00002, 0x80000,   CRC(21eb46e4) SHA1(0ab21ed012c9a76e01c83b60c6f4670836dfa718) )
317   ROM_LOAD32_BYTE( "sx004-01.u30",   0x00003, 0x80000,   CRC(65646949) SHA1(74931c230f4e4b1008fbc5fba169292e216aa23b) )
318
319   ROM_REGION( 0x200000, REGION_USER2,0)
320   ROM_LOAD32_WORD( "sx004-05.rd0",   0x000000, 0x100000,   CRC(f3c69468) SHA1(81daef6d0596cb67bb6f87b39874aae1b1ffe6a6) )
321   ROM_LOAD32_WORD( "sx004-06",       0x000002, 0x100000,   CRC(5af78e44) SHA1(0131d50348fef80c2b100d74b7c967c6a710d548) )
322
323ROM_END
324
325
326ROM_START( speglsha )
327   ROM_REGION( 0x210000, REGION_CPU1, 0 )
328   ROM_LOAD( "sx004-07",   0x10000, 0x200000,   CRC(2d759cc4) SHA1(9fedd829190b2aab850b2f1088caaec91e8715dd) )
329   ROM_COPY( REGION_CPU1,  0x10000, 0x00000, 0x08000 )
330
331   ROM_REGION32_BE( 0x200000, REGION_USER1, 0 )
332   ROM_LOAD32_BYTE( "sx004-04.u33",   0x00000, 0x80000,   CRC(e46d2e57) SHA1(b1fb836ab2ce547dc2e8d1046d7ef835b87bb04e) )
333   ROM_LOAD32_BYTE( "sx004-03.u32",   0x00001, 0x80000,   CRC(c6ffb00e) SHA1(f57ef45bb5c690c3e63101a36835d2687abfcdbd) )
334   ROM_LOAD32_BYTE( "sx004-02.u31",   0x00002, 0x80000,   CRC(21eb46e4) SHA1(0ab21ed012c9a76e01c83b60c6f4670836dfa718) )
335   ROM_LOAD32_BYTE( "sx004-01.u30",   0x00003, 0x80000,   CRC(65646949) SHA1(74931c230f4e4b1008fbc5fba169292e216aa23b) )
336
337   ROM_REGION( 0x200000, REGION_USER2,0)
338   ROM_LOAD( "sx004-05.rd0",   0x000000, 0x100000,   CRC(f3c69468) SHA1(81daef6d0596cb67bb6f87b39874aae1b1ffe6a6) )
339   ROM_LOAD( "sx004-06",       0x100000, 0x100000,   CRC(5af78e44) SHA1(0131d50348fef80c2b100d74b7c967c6a710d548) )
340ROM_END
341
342
343
344static DRIVER_INIT(speglsht)
345{
346   st0016_game=3;
347}
348
349
350GAME( 1994, speglsht,   0,     speglsht, speglsht, speglsht, ROT0, "Seta",  "Super Eagle Shot", GAME_IMPERFECT_GRAPHICS)
351GAME( 1994, speglsha,   speglsht, speglsht, speglsht, speglsht, ROT0, "Seta",  "Super Eagle Shot (set 2)",GAME_NOT_WORKING)
src/mame/drivers/rockola.c
r936r937
10301030   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 28*8-1)
10311031   MDRV_GFXDECODE(sasuke_gfxdecodeinfo)
10321032   MDRV_PALETTE_LENGTH(32)
1033   MDRV_COLORTABLE_LENGTH(4*4 + 4*4)
10341033
10351034   MDRV_PALETTE_INIT(satansat)
10361035   MDRV_VIDEO_START(satansat)
r936r937
11031102   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 28*8-1)
11041103   MDRV_GFXDECODE(vanguard_gfxdecodeinfo)
11051104   MDRV_PALETTE_LENGTH(64)
1106   MDRV_COLORTABLE_LENGTH(16*4)
11071105
11081106   MDRV_PALETTE_INIT(rockola)
11091107   MDRV_VIDEO_START(rockola)
src/mame/drivers/jrpacman.c
r936r937
213213
214214static const gfx_layout tilelayout =
215215{
216   8,8,   /* 8*8 characters */
217    RGN_FRAC(1,2),    /* 256 characters */
218    2,  /* 2 bits per pixel */
219    { 0, 4 },   /* the two bitplanes for 4 pixels are packed into one byte */
220    { 8*8+0, 8*8+1, 8*8+2, 8*8+3, 0, 1, 2, 3 }, /* bits are packed in groups of four */
221    { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
222    16*8    /* every char takes 16 bytes */
216   8,8,
217    RGN_FRAC(1,2),
218    2,
219    { 0, 4 },
220    { STEP4(8*8,1), STEP4(0*8,1) },
221    { STEP8(0*8,8) },
222    16*8
223223};
224224
225225
226226static const gfx_layout spritelayout =
227227{
228   16,16,   /* 16*16 sprites */
229   RGN_FRAC(1,2),   /* 64 sprites */
230   2,   /* 2 bits per pixel */
231   { 0, 4 },   /* the two bitplanes for 4 pixels are packed into one byte */
232   { 8*8, 8*8+1, 8*8+2, 8*8+3, 16*8+0, 16*8+1, 16*8+2, 16*8+3,
233         24*8+0, 24*8+1, 24*8+2, 24*8+3, 0, 1, 2, 3 },
234   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
235         32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
236   64*8   /* every sprite takes 64 bytes */
228   16,16,
229   RGN_FRAC(1,2),
230   2,
231   { 0, 4 },
232   { STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1), STEP4(0*8,1) },
233   { STEP8(0*8,8), STEP8(32*8,8) },
234   64*8
237235};
238236
239237
src/mame/drivers/cubocd32.c
r936r937
4747#include "driver.h"
4848#include "sound/custom.h"
4949#include "includes/amiga.h"
50#include "cdrom.h"
51#include "sound/cdda.h"
50#include "includes/cubocd32.h"
51//#include "memconv.h"
5252
53/*
53//READWRITE16BETO32BE(amiga_cia32,amiga_cia_r,amiga_cia_w)
54//READWRITE16BETO32BE(amiga_custom32,amiga_custom_r,amiga_custom_w)
5455
55    Akiko custom chip emulation
56
57The Akiko chip has:
58- built in 1KB NVRAM
59- chunky to planar converter
60- custom CDROM controller
61
62CDROM Commands:
63    len does not include checksum byte,
64    resp len does include checksum byte
65
66    x0: len = 0x01, resp len = 0x01
67    x1: len = 0x02, resp len = 0x03
68    x2: len = 0x01, resp len = 0x03 - Pause CD Audio
69    x3: len = 0x01, resp len = 0x03 - Unpause CD Audio
70    x4: len = 0x0C, resp len = 0x03 - CD Audio Play/Read CD Data/Seek
71    x5: len = 0x02, resp len = 0x10 - Read TOC
72    x6: len = 0x01, resp len = 0x10 - Get Next TOC entry
73    x7: len = 0x01, resp len = 0x15 - Door Status
74    x8: len = 0x04, resp len = 0x03
75    x9: len = 0x01, resp len = 0x01
76    xA: len = 0x00, resp len = 0x03 - Media Status: Response = 0A NN CK where NN = 0: no disk and NN = 1: disk inserted
77    xB: len = 0x00, resp len = 0x01
78    xC: len = 0x00, resp len = 0x01
79    xD: len = 0x00, resp len = 0x01
80    xE: len = 0x00, resp len = 0x01
81    xF: len = 0x00, resp len = 0x01
82*/
83
84#define LOG_AKIKO      0
85#define LOG_AKIKO_I2C   0
86
87enum {
88   I2C_WAIT = 0,
89   I2C_DEVICEADDR,
90   I2C_WORDADDR,
91   I2C_DATA
92};
93
94#define   NVRAM_SIZE 1024
95/* max size of one write request */
96#define   NVRAM_PAGE_SIZE   16
97
98struct akiko_def
56static READ32_HANDLER( amiga_cia32_r )
9957{
100   /* chunky to planar converter */
101   UINT32   c2p_input_buffer[8];
102   UINT32   c2p_output_buffer[8];
103   UINT32   c2p_input_index;
104   UINT32   c2p_output_index;
105
106   /* i2c bus */
107   int      i2c_state;
108   int      i2c_bitcounter;
109   int      i2c_direction;
110   int      i2c_sda_dir_nvram;
111   int      i2c_scl_out;
112   int      i2c_scl_in;
113   int      i2c_scl_dir;
114   int      i2c_oscl;
115   int      i2c_sda_out;
116   int      i2c_sda_in;
117   int      i2c_sda_dir;
118   int      i2c_osda;
119
120   /* nvram */
121   UINT8   nvram[NVRAM_SIZE];
122   UINT8   nvram_writetmp[NVRAM_PAGE_SIZE];
123   int      nvram_address;
124   int      nvram_writeaddr;
125   int      nvram_rw;
126   UINT8   nvram_byte;
127
128   /* cdrom */
129   UINT32   cdrom_status[2];
130   UINT32   cdrom_address[2];
131   UINT8   cdrom_cmd_start;
132   UINT8   cdrom_cmd_end;
133   UINT8   cdrom_cmd_resp;
134   cdrom_file *cdrom;
135} akiko;
136
137void init_akiko(void)
138{
139   akiko.c2p_input_index = 0;
140   akiko.c2p_output_index = 0;
141
142   akiko.i2c_state = I2C_WAIT;
143   akiko.i2c_bitcounter = -1;
144   akiko.i2c_direction = -1;
145   akiko.i2c_sda_dir_nvram = 0;
146   akiko.i2c_scl_out = 0;
147   akiko.i2c_scl_in = 0;
148   akiko.i2c_scl_dir = 0;
149   akiko.i2c_oscl = 0;
150   akiko.i2c_sda_out = 0;
151   akiko.i2c_sda_in = 0;
152   akiko.i2c_sda_dir = 0;
153   akiko.i2c_osda = 0;
154
155   akiko.nvram_address = 0;
156   akiko.nvram_writeaddr = 0;
157   akiko.nvram_rw = 0;
158   akiko.nvram_byte = 0;
159   memset( akiko.nvram, 0, NVRAM_SIZE );
160
161   akiko.cdrom_status[0] = akiko.cdrom_status[1] = 0;
162   akiko.cdrom_address[0] = akiko.cdrom_address[1] = 0;
163   akiko.cdrom_cmd_start = akiko.cdrom_cmd_end = akiko.cdrom_cmd_resp = 0;
164   akiko.cdrom = cdrom_open(get_disk_handle(0));
58   UINT32 result = 0;
59   if ((mem_mask & 0xffff0000) != 0xffff0000)
60      result |= amiga_cia_r(offset * 2 + 0, mem_mask >> 16) << 16;
61   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
62      result |= amiga_cia_r(offset * 2 + 1, mem_mask) << 0;
63   return result;
16564}
16665
167void akiko_c2p_write(UINT32 data)
66static WRITE32_HANDLER( amiga_cia32_w )
16867{
169   akiko.c2p_input_buffer[akiko.c2p_input_index] = data;
170   akiko.c2p_input_index++;
171   akiko.c2p_input_index &= 7;
172   akiko.c2p_output_index = 0;
68   if ((mem_mask & 0xffff0000) != 0xffff0000)
69      amiga_cia_w( offset * 2 + 0, data >> 16, mem_mask >> 16);
70   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
71      amiga_cia_w( offset * 2 + 1, data, mem_mask);
17372}
17473
175UINT32 akiko_c2p_read(void)
74static READ32_HANDLER( amiga_custom32_r )
17675{
177   UINT32 val;
178
179   if ( akiko.c2p_output_index == 0 )
180   {
181      int i;
182
183      for ( i = 0; i < 8; i++ )
184         akiko.c2p_output_buffer[i] = 0;
185
186      for (i = 0; i < 8 * 32; i++) {
187         if (akiko.c2p_input_buffer[7 - (i >> 5)] & (1 << (i & 31)))
188            akiko.c2p_output_buffer[i & 7] |= 1 << (i >> 3);
189      }
190   }
191   akiko.c2p_input_index = 0;
192   val = akiko.c2p_output_buffer[akiko.c2p_output_index];
193   akiko.c2p_output_index++;
194   akiko.c2p_output_index &= 7;
195   return val;
76   UINT32 result = 0;
77   if ((mem_mask & 0xffff0000) != 0xffff0000)
78      result |= amiga_custom_r(offset * 2 + 0, mem_mask >> 16) << 16;
79   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
80      result |= amiga_custom_r(offset * 2 + 1, mem_mask) << 0;
81   return result;
19682}
19783
198static void akiko_i2c( void )
84static WRITE32_HANDLER( amiga_custom32_w )
19985{
200    akiko.i2c_sda_in = 1;
201
202    if ( !akiko.i2c_sda_dir_nvram && akiko.i2c_scl_out && akiko.i2c_oscl )
203    {
204      if ( !akiko.i2c_sda_out && akiko.i2c_osda )   /* START-condition? */
205      {
206          akiko.i2c_state = I2C_DEVICEADDR;
207          akiko.i2c_bitcounter = 0;
208          akiko.i2c_direction = -1;
209#if LOG_AKIKO_I2C
210          logerror("START\n");
211#endif
212          return;
213      }
214      else if ( akiko.i2c_sda_out && !akiko.i2c_osda ) /* STOP-condition? */
215      {
216          akiko.i2c_state = I2C_WAIT;
217          akiko.i2c_bitcounter = -1;
218#if LOG_AKIKO_I2C
219          logerror("STOP\n");
220#endif
221          if ( akiko.i2c_direction > 0 )
222          {
223            memcpy( akiko.nvram + ( akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1) ), akiko.nvram_writetmp, NVRAM_PAGE_SIZE );
224            akiko.i2c_direction = -1;
225#if LOG_AKIKO_I2C
226            {
227               int i;
228
229               logerror("NVRAM write address %04X:", akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1));
230               for (i = 0; i < NVRAM_PAGE_SIZE; i++)
231                   logerror("%02X", akiko.nvram_writetmp[i]);
232               logerror("\n");
233            }
234#endif
235          }
236          return;
237      }
238    }
239
240    if ( akiko.i2c_bitcounter >= 0 )
241    {
242      if ( akiko.i2c_direction )
243      {
244          /* Amiga -> NVRAM */
245          if ( akiko.i2c_scl_out && !akiko.i2c_oscl )
246          {
247            if ( akiko.i2c_bitcounter == 8 )
248            {
249                akiko.i2c_sda_in = 0; /* ACK */
250
251                if ( akiko.i2c_direction > 0 )
252                {
253                  akiko.nvram_writetmp[akiko.nvram_writeaddr++] = akiko.nvram_byte;
254                  akiko.nvram_writeaddr &= (NVRAM_PAGE_SIZE - 1);
255                  akiko.i2c_bitcounter = 0;
256                }
257                else
258                {
259                   akiko.i2c_bitcounter = -1;
260                }
261             }
262             else
263             {
264                akiko.nvram_byte <<= 1;
265                akiko.nvram_byte |= akiko.i2c_sda_out;
266                akiko.i2c_bitcounter++;
267            }
268          }
269      }
270      else
271      {
272         /* NVRAM -> Amiga */
273         if ( akiko.i2c_scl_out && !akiko.i2c_oscl && akiko.i2c_bitcounter < 8 )
274         {
275            if ( akiko.i2c_bitcounter == 0 )
276               akiko.nvram_byte = akiko.nvram[akiko.nvram_address];
277
278            akiko.i2c_sda_dir_nvram = 1;
279            akiko.i2c_sda_in = (akiko.nvram_byte & 0x80) ? 1 : 0;
280            akiko.nvram_byte <<= 1;
281            akiko.i2c_bitcounter++;
282
283            if ( akiko.i2c_bitcounter == 8 )
284            {
285#if LOG_AKIKO_I2C
286                logerror("NVRAM sent byte %02X address %04X\n", akiko.nvram[akiko.nvram_address], akiko.nvram_address);
287#endif
288                akiko.nvram_address++;
289                akiko.nvram_address &= NVRAM_SIZE - 1;
290                akiko.i2c_sda_dir_nvram = 0;
291            }
292          }
293
294          if ( !akiko.i2c_sda_out && akiko.i2c_sda_dir && !akiko.i2c_scl_out ) /* ACK from Amiga */
295            akiko.i2c_bitcounter = 0;
296      }
297
298      if ( akiko.i2c_bitcounter >= 0 )
299         return;
300    }
301
302    switch( akiko.i2c_state )
303    {
304      case I2C_DEVICEADDR:
305         if ( ( akiko.nvram_byte & 0xf0 ) != 0xa0 )
306         {
307#if LOG_AKIKO_I2C
308            logerror("WARNING: I2C_DEVICEADDR: device address != 0xA0\n");
309#endif
310            akiko.i2c_state = I2C_WAIT;
311             return;
312         }
313
314         akiko.nvram_rw = (akiko.nvram_byte & 1) ? 0 : 1;
315
316         if ( akiko.nvram_rw )
317         {
318            /* 2 high address bits, only fetched if WRITE = 1 */
319            akiko.nvram_address &= 0xff;
320            akiko.nvram_address |= ((akiko.nvram_byte >> 1) & 3) << 8;
321             akiko.i2c_state = I2C_WORDADDR;
322             akiko.i2c_direction = -1;
323          }
324          else
325          {
326             akiko.i2c_state = I2C_DATA;
327             akiko.i2c_direction = 0;
328             akiko.i2c_sda_dir_nvram = 1;
329         }
330
331         akiko.i2c_bitcounter = 0;
332#if LOG_AKIKO_I2C
333         logerror("I2C_DEVICEADDR: rw %d, address %02Xxx\n", akiko.nvram_rw, akiko.nvram_address >> 8);
334#endif
335      break;
336
337      case I2C_WORDADDR:
338         akiko.nvram_address &= 0x300;
339         akiko.nvram_address |= akiko.nvram_byte;
340
341#if LOG_AKIKO_I2C
342         logerror("I2C_WORDADDR: address %04X\n", akiko.nvram_address);
343#endif
344         if ( akiko.i2c_direction < 0 )
345         {
346            memcpy( akiko.nvram_writetmp, akiko.nvram + (akiko.nvram_address & ~(NVRAM_PAGE_SIZE - 1)), NVRAM_PAGE_SIZE);
347             akiko.nvram_writeaddr = akiko.nvram_address & (NVRAM_PAGE_SIZE - 1);
348         }
349
350         akiko.i2c_state = I2C_DATA;
351         akiko.i2c_bitcounter = 0;
352         akiko.i2c_direction = 1;
353      break;
354    }
86   if ((mem_mask & 0xffff0000) != 0xffff0000)
87      amiga_custom_w( offset * 2 + 0, data >> 16, mem_mask >> 16);
88   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
89      amiga_custom_w( offset * 2 + 1, data, mem_mask);
35590}
35691
357void akiko_nvram_write(UINT32 data)
92static WRITE32_HANDLER( aga_overlay_w )
35893{
359   int      sda;
360
361   akiko.i2c_oscl = akiko.i2c_scl_out;
362   akiko.i2c_scl_out = BIT(data,31);
363   akiko.i2c_osda = akiko.i2c_sda_out;
364   akiko.i2c_sda_out = BIT(data,30);
365   akiko.i2c_scl_dir = BIT(data,15);
366   akiko.i2c_sda_dir = BIT(data,14);
367
368   sda = akiko.i2c_sda_out;
369    if ( akiko.i2c_oscl != akiko.i2c_scl_out || akiko.i2c_osda != sda )
370    {
371       akiko_i2c();
372       akiko.i2c_oscl = akiko.i2c_scl_out;
373       akiko.i2c_osda = sda;
374    }
375}
376
377UINT32 akiko_nvram_read(void)
378{
379   UINT32   v = 0;
380
381   if ( !akiko.i2c_scl_dir )
382       v |= akiko.i2c_scl_in ? (1<<31) : 0x00;
383   else
384       v |= akiko.i2c_scl_out ? (1<<31) : 0x00;
385
386   if ( !akiko.i2c_sda_dir )
387       v |= akiko.i2c_sda_in ? (1<<30) : 0x00;
388   else
389       v |= akiko.i2c_sda_out ? (1<<30) : 0x00;
390
391   v |= akiko.i2c_scl_dir ? (1<<15) : 0x00;
392   v |= akiko.i2c_sda_dir ? (1<<14) : 0x00;
393
394    return v;
395}
396
397static const char* akiko_reg_names[] =
398{
399   /*0*/   "ID",
400   /*1*/   "CDROM STATUS 1",
401   /*2*/   "CDROM_STATUS 2",
402   /*3*/   "???",
403   /*4*/   "CDROM ADDRESS 1",
404   /*5*/   "CDROM ADDRESS 2",
405   /*6*/   "CDROM COMMAND 1",
406   /*7*/   "CDROM COMMAND 2",
407   /*8*/   "CDROM READMASK",
408   /*9*/   "CDROM LONGMASK",
409   /*A*/   "???",
410   /*B*/   "???",
411   /*C*/   "NVRAM",
412   /*D*/   "???",
413   /*E*/   "C2P"
414};
415
416const char* get_akiko_reg_name(int reg)
417{
418   if (reg < 0xf )
94   if ((mem_mask & 0x00ff0000) != 0x00ff0000)
41995   {
420      return akiko_reg_names[reg];
421   }
422   else
423   {
424      return "???";
425   }
426}
96      data = (data >> 16) & 1;
42797
428static void akiko_setup_response( int len, int r0, UINT8 *r1 )
429{
430   int      resp_addr = akiko.cdrom_address[1];
431   UINT8   resp_csum = 0xff;
432   UINT8   resp_buffer[32];
433   int      i;
98      /* switch banks as appropriate */
99      memory_set_bank(1, data & 1);
434100
435   memset( resp_buffer, 0, sizeof( resp_buffer ) );
436
437   resp_buffer[0] = r0;
438
439   for( i = 0; i < len; i++ )
440   {
441      resp_buffer[i+1] = r1[i];
442      resp_csum -= resp_buffer[i];
443   }
444
445   resp_buffer[len] = resp_csum;
446   len++;
447
448   for( i = 0; i < len; i++ )
449   {
450      program_write_byte( resp_addr + ((akiko.cdrom_cmd_resp + i) & 0xff), resp_buffer[i] );
451   }
452
453   akiko.cdrom_cmd_resp = (akiko.cdrom_cmd_resp+len) & 0xff;
454
455   akiko.cdrom_status[0] |= 0x10000000; /* new data available */
456}
457
458static TIMER_CALLBACK( akiko_cd_delayed_cmd )
459{
460   UINT8   resp[32];
461
462   memset( resp, 0, sizeof( resp ) );
463
464   if ( param == 0x05 )
465   {
466      logerror( "AKIKO: Completing Command %d\n", param );
467
468      if ( akiko.cdrom == NULL || cdrom_get_last_track(akiko.cdrom) == 0 )
469      {
470         resp[0] = 0x80;
471         akiko_setup_response( 2, param, resp );
472      }
101      /* swap the write handlers between ROM and bank 1 based on the bit */
102      if ((data & 1) == 0)
103         /* overlay disabled, map RAM on 0x000000 */
104         memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0x000000, 0x1fffff, 0, 0, MWA32_BANK1);
473105      else
474      {
475         int      addrctrl = cdrom_get_adr_control( akiko.cdrom, 0 );
476         UINT32   trackstart = lba_to_msf(cdrom_get_track_start( akiko.cdrom, 0 ));
477
478         resp[0] = 0x00;
479         resp[1] = ((addrctrl & 0x0f) << 4) | ((addrctrl & 0xf0) >> 4);
480         /* 2-3: track number in BCD format */
481         /* 4-7: ??? */
482         resp[8] = (trackstart >> 16) & 0xff;
483         resp[9] = (trackstart >> 8) & 0xff;
484         resp[10] = trackstart & 0xff;
485
486         akiko_setup_response( 15, param, resp );
487      }
106         /* overlay enabled, map Amiga system ROM on 0x000000 */
107         memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0x000000, 0x1fffff, 0, 0, MWA32_ROM);
488108   }
489109}
490110
491static void akiko_update_cdrom( void )
492{
493   UINT8   resp[32];
494
495   if ( akiko.cdrom_status[0] & 0x10000000 )
496      return;
497
498   while ( akiko.cdrom_cmd_start < akiko.cdrom_cmd_end )
499   {
500      int cmd_addr = akiko.cdrom_address[1] + 0x200 + akiko.cdrom_cmd_start;
501      int cmd = program_read_byte( cmd_addr );
502
503      cmd &= 0x0f;
504
505      logerror( "CDROM command: %02X\n", cmd );
506
507      memset( resp, 0, sizeof( resp ) );
508
509      if ( cmd == 0x05 ) /* read toc */
510      {
511         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+3) & 0xff;
512
513         mame_timer_set( MAME_TIME_IN_MSEC(500), cmd, akiko_cd_delayed_cmd );
514
515         break;
516      }
517      else if ( cmd == 0x07 )   /* check door status */
518      {
519         resp[0] = 0x01;
520
521         akiko.cdrom_cmd_start = (akiko.cdrom_cmd_start+2) & 0xff;
522
523         if ( akiko.cdrom == NULL || cdrom_get_last_track(akiko.cdrom) == 0 )
524            resp[0] = 0x80;
525
526         akiko_setup_response( 20, cmd, resp );
527         break;
528      }
529      else
530      {
531         break;
532      }
533   }
534}
535
536READ32_HANDLER(amiga_akiko32_r)
537{
538   UINT32      retval;
539   if ( offset < (0x30/4) )
540   {
541      if ( LOG_AKIKO ) logerror( "Reading AKIKO reg %0x [%s] at PC=%06x\n", offset, get_akiko_reg_name(offset), activecpu_get_pc() );
542   }
543
544   switch( offset )
545   {
546      case 0x00/4:   /* ID */
547         init_akiko();
548         return 0x0000cafe;
549
550      case 0x04/4:   /* CDROM STATUS 1 */
551         return akiko.cdrom_status[0];
552
553      case 0x08/4:   /* CDROM STATUS 2 */
554         return akiko.cdrom_status[1];
555
556      case 0x10/4:   /* CDROM ADDRESS 1 */
557         return akiko.cdrom_address[0];
558
559      case 0x14/4:   /* CDROM ADDRESS 2 */
560         return akiko.cdrom_address[1];
561
562      case 0x18/4:   /* CDROM COMMAND 1 */
563         akiko_update_cdrom();
564         retval = akiko.cdrom_cmd_start;
565         retval <<= 8;
566         retval |= akiko.cdrom_cmd_resp;
567         retval <<= 8;
568         return retval;
569
570      case 0x1C/4:   /* CDROM COMMAND 2 */
571         akiko_update_cdrom();
572         retval = akiko.cdrom_cmd_end;
573         retval <<= 16;
574         return retval;
575
576      case 0x30/4:   /* NVRAM */
577         return akiko_nvram_read();
578
579      case 0x38/4:   /* C2P */
580         return akiko_c2p_read();
581
582      default:
583         break;
584   }
585
586   return 0;
587}
588
589WRITE32_HANDLER(amiga_akiko32_w)
590{
591   if ( offset < (0x30/4) )
592   {
593      if ( LOG_AKIKO ) logerror( "Writing AKIKO reg %0x [%s] with %08x at PC=%06x\n", offset, get_akiko_reg_name(offset), data, activecpu_get_pc() );
594   }
595
596   switch( offset )
597   {
598      case 0x04/4:   /* CDROM STATUS 1 */
599         akiko.cdrom_status[0] = data;
600         break;
601
602      case 0x08/4:   /* CDROM STATUS 2 */
603         akiko.cdrom_status[1] = data;
604         akiko.cdrom_status[0] &= data;
605         break;
606
607      case 0x10/4:   /* CDROM ADDRESS 1 */
608         akiko.cdrom_address[0] = data;
609         break;
610
611      case 0x14/4:   /* CDROM ADDRESS 2 */
612         akiko.cdrom_address[1] = data;
613         break;
614
615      case 0x18/4:   /* CDROM COMMAND 1 */
616         if ( ( mem_mask & 0x00ff0000 ) == 0 )
617            akiko.cdrom_cmd_start = ( data >> 16 ) & 0xff;
618
619         if ( ( mem_mask & 0x0000ff00 ) == 0 )
620            akiko.cdrom_cmd_resp = ( data >> 8 ) & 0xff;
621
622         akiko_update_cdrom();
623         break;
624
625      case 0x1C/4:   /* CDROM COMMAND 2 */
626         if ( ( mem_mask & 0x00ff0000 ) == 0 )
627            akiko.cdrom_cmd_end = ( data >> 16 ) & 0xff;
628
629         akiko_update_cdrom();
630         break;
631
632      case 0x30/4:
633         akiko_nvram_write(data);
634         break;
635
636      case 0x38/4:
637         akiko_c2p_write(data);
638         break;
639
640      default:
641         break;
642   }
643}
644
645static READ32_HANDLER(amiga_cia32_r)
646{
647   UINT32 retval = 0;
648
649#if 0
650   if ( (mem_mask & 0xffff) != 0xffff)
651      retval |= (amiga_cia_r(offset*2, mem_mask & 0xffff) );
652
653   if ( ((mem_mask >> 16) & 0xffff) != 0xffff)
654      retval |= (amiga_cia_r(offset*2 + 1, mem_mask >> 16) << 16);
655#else
656   if ( ((mem_mask >> 16) & 0xffff) != 0xffff)
657   {
658      retval |= amiga_cia_r(offset*2, (mem_mask >> 16) & 0xffff);
659      retval <<= 16;
660   }
661
662   if ( (mem_mask & 0xffff) != 0xffff )
663      retval |= amiga_cia_r(offset*2 + 1, mem_mask & 0xffff);
664
665   return retval;
666#endif
667
668   return retval;
669}
670
671static WRITE32_HANDLER(amiga_cia32_w)
672{
673//  amiga_cia_w(offset*2, data >> 16, mem_mask >> 16 );
674   if ( ((mem_mask >> 16) & 0xffff) != 0xffff)
675      amiga_cia_w(offset*2, data >> 16, mem_mask >> 16 );
676
677   if ( (mem_mask & 0xffff) != 0xffff )
678      amiga_cia_w(offset*2 + 1, data & 0xffff, mem_mask & 0xffff );
679}
680
681static READ32_HANDLER(amiga_custom32_r)
682{
683   UINT32 retval = 0;
684
685   if ( ((mem_mask >> 16) & 0xffff) != 0xffff)
686   {
687      retval |= amiga_custom_r(offset*2, (mem_mask >> 16) & 0xffff);
688      retval <<= 16;
689   }
690
691   if ( (mem_mask & 0xffff) != 0xffff )
692      retval |= amiga_custom_r(offset*2 + 1, mem_mask & 0xffff);
693
694   return retval;
695}
696
697static WRITE32_HANDLER(amiga_custom32_w)
698{
699   if ( ((mem_mask >> 16) & 0xffff) != 0xffff)
700      amiga_custom_w(offset*2, data >> 16, mem_mask >> 16 );
701
702   if ( (mem_mask & 0xffff) != 0xffff )
703      amiga_custom_w(offset*2 + 1, data & 0xffff, mem_mask & 0xffff );
704}
705
706111/*************************************
707112 *
708113 *  CIA-A port A access:
r936r937
714119 *  PA3 = /WPRO (disk write protect)
715120 *  PA2 = /CHNG (disk change)
716121 *  PA1 = /LED (LED, 0=bright / audio filter control)
717 *  PA0 = OVL (ROM/RAM overlay bit)
122 *  PA0 = MUTE
718123 *
719124 *************************************/
720125
r936r937
725130
726131static void cd32_cia_0_porta_w(UINT8 data)
727132{
728   /* switch banks as appropriate */
729   memory_set_bank(1, data & 1);
133   /* bit 1 = cd audio mute */
134   sndti_set_output_gain(SOUND_CDDA, 0, 0, ( data & 1 ) ? 0.0 : 1.0 );
730135
731   /* swap the write handlers between ROM and bank 1 based on the bit */
732   if ((data & 1) == 0)
733      /* overlay disabled, map RAM on 0x000000 */
734      memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0x000000, 0x1fffff, 0, 0, MWA32_BANK1);
735
736   else
737      /* overlay enabled, map Amiga system ROM on 0x000000 */
738      memory_install_write32_handler(0, ADDRESS_SPACE_PROGRAM, 0x000000, 0x1fffff, 0, 0, MWA32_ROM);
739
740136   /* bit 2 = Power Led on Amiga */
741137   set_led_status(0, (data & 2) ? 0 : 1);
742138}
r936r937
769165   logerror("%06x:CIA0_portb_w(%02x)\n", activecpu_get_pc(), data);
770166}
771167
772static NVRAM_HANDLER( cd32 )
168static READ32_HANDLER( dipswitch_r )
773169{
774   if (read_or_write)
775      /* save the SRAM settings */
776      mame_fwrite(file, akiko.nvram, NVRAM_SIZE);
777   else
778   {
779      /* load the SRAM settings */
780      if (file)
781         mame_fread(file, akiko.nvram, NVRAM_SIZE);
782      else
783         memset(akiko.nvram, 0, NVRAM_SIZE);
784   }
170   return readinputportbytag("DIPSW1");
785171}
786172
787173static ADDRESS_MAP_START( cd32_map, ADDRESS_SPACE_PROGRAM, 32 )
788174   ADDRESS_MAP_FLAGS( AMEF_UNMAP(1) )
789175   AM_RANGE(0x000000, 0x1fffff) AM_RAMBANK(1) AM_BASE(&amiga_chip_ram32) AM_SIZE(&amiga_chip_ram_size)
176   AM_RANGE(0x800000, 0x800003) AM_READ( dipswitch_r );
790177   AM_RANGE(0xb80000, 0xb8003f) AM_READWRITE(amiga_akiko32_r, amiga_akiko32_w)
178   AM_RANGE(0xbfa000, 0xbfa003) AM_WRITE(aga_overlay_w);
791179   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia32_r, amiga_cia32_w)
792180   AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(amiga_custom32_r, amiga_custom32_w) AM_BASE((UINT32**)&amiga_custom_regs)
793181   AM_RANGE(0xe00000, 0xe7ffff) AM_ROM AM_REGION(REGION_USER1, 0x80000)   /* CD32 Extended ROM */
r936r937
804192   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
805193
806194   PORT_START_TAG("CIA0PORTB")
807   PORT_DIPNAME( 0x01, 0x01, "DSW1 1" )
808   PORT_DIPSETTING(    0x01, "Reset" )
809   PORT_DIPSETTING(    0x00, "Set" )
810   PORT_SERVICE_NO_TOGGLE( 0x02, IP_ACTIVE_LOW )
811195   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
812196   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
813197
r936r937
841225   PORT_START_TAG("COINS")
842226   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
843227   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
228
229   PORT_START_TAG("DIPSW1")
230   PORT_DIPNAME( 0x01, 0x01, "DSW1 1" )
231   PORT_DIPSETTING(    0x01, "Reset" )
232   PORT_DIPSETTING(    0x00, "Set" )
233   PORT_DIPNAME( 0x02, 0x02, "DSW1 2" )
234   PORT_DIPSETTING(    0x02, "Reset" )
235   PORT_DIPSETTING(    0x00, "Set" )
236   PORT_DIPNAME( 0x04, 0x04, "DSW1 3" )
237   PORT_DIPSETTING(    0x04, "Reset" )
238   PORT_DIPSETTING(    0x00, "Set" )
239   PORT_DIPNAME( 0x08, 0x08, "DSW1 4" )
240   PORT_DIPSETTING(    0x08, "Reset" )
241   PORT_DIPSETTING(    0x00, "Set" )
242   PORT_DIPNAME( 0x10, 0x10, "DSW1 5" )
243   PORT_DIPSETTING(    0x10, "Reset" )
244   PORT_DIPSETTING(    0x00, "Set" )
245   PORT_DIPNAME( 0x20, 0x20, "DSW1 6" )
246   PORT_DIPSETTING(    0x20, "Reset" )
247   PORT_DIPSETTING(    0x00, "Set" )
248   PORT_SERVICE( 0x40, IP_ACTIVE_HIGH )
249   PORT_DIPNAME( 0x80, 0x80, "DSW1 8" )
250   PORT_DIPSETTING(    0x80, "Reset" )
251   PORT_DIPSETTING(    0x00, "Set" )
844252INPUT_PORTS_END
845253
846254/*************************************
r936r937
858266static MACHINE_DRIVER_START( cd32 )
859267
860268   /* basic machine hardware */
861   MDRV_CPU_ADD(M68EC020, AMIGA_68EC020_NTSC_CLOCK) /* 14.3 Mhz */
269   MDRV_CPU_ADD(M68EC020, AMIGA_68EC020_PAL_CLOCK) /* 14.3 Mhz */
862270   MDRV_CPU_PROGRAM_MAP(cd32_map,0)
863   MDRV_CPU_VBLANK_INT(amiga_scanline_callback, 262)
271   MDRV_CPU_VBLANK_INT(amiga_scanline_callback, 312)
864272
865273   MDRV_SCREEN_REFRESH_RATE(59.997)
866274   MDRV_SCREEN_VBLANK_TIME(USEC_TO_SUBSECONDS(0))
r936r937
871279   /* video hardware */
872280   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER | VIDEO_UPDATE_BEFORE_VBLANK)
873281   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
874   MDRV_SCREEN_SIZE(512*2, 262)
875   MDRV_SCREEN_VISIBLE_AREA((129-8)*2, (449+8-1)*2, 44-8, 244+8-1)
282   MDRV_SCREEN_SIZE(512*2, 312)
283   MDRV_SCREEN_VISIBLE_AREA((129-8)*2, (449+8-1)*2, 44-8, 300+8-1)
876284   MDRV_PALETTE_LENGTH(4096)
877285   MDRV_PALETTE_INIT(amiga)
878286
r936r937
884292
885293    MDRV_SOUND_ADD(CUSTOM, 3579545)
886294    MDRV_SOUND_CONFIG(amiga_custom_interface)
887    MDRV_SOUND_ROUTE(0, "left", 0.50)
888    MDRV_SOUND_ROUTE(1, "right", 0.50)
889    MDRV_SOUND_ROUTE(2, "right", 0.50)
890    MDRV_SOUND_ROUTE(3, "left", 0.50)
295    MDRV_SOUND_ROUTE(0, "left", 0.25)
296    MDRV_SOUND_ROUTE(1, "right", 0.25)
297    MDRV_SOUND_ROUTE(2, "right", 0.25)
298    MDRV_SOUND_ROUTE(3, "left", 0.25)
299
300    MDRV_SOUND_ADD( CDDA, 0 )
301   MDRV_SOUND_ROUTE( 0, "left", 0.50 )
302   MDRV_SOUND_ROUTE( 1, "right", 0.50 )
891303MACHINE_DRIVER_END
892304
893305
r936r937
970382   /* set up memory */
971383   memory_configure_bank(1, 0, 1, amiga_chip_ram32, 0);
972384   memory_configure_bank(1, 1, 1, memory_region(REGION_USER1), 0);
385
386   /* intialize akiko */
387   amiga_akiko_init();
973388}
974389
975390/***************************************************************************************************/
src/mame/drivers/nemesis.c
r936r937
341341
342342   res |= 0xd0;
343343
344   if (sndti_to_sndnum(SOUND_VLM5030, 0) >= 0 && VLM5030_BSY())
344   if (sndti_exists(SOUND_VLM5030, 0) && VLM5030_BSY())
345345      res |= 0x20;
346346
347347   return res;
src/mame/drivers/vamphalf.c
r936r937
77
88 Games Supported:
99
10    Vamp 1/2                 (c) 1999 Danbi & F2 System  (Korea version)
11    Mission Craft            (c) 2000 Sun                (version 2.4)
12    Minigame Cool Collection (c) 1999 SemiCom
13    Super Lup Lup Puzzle     (c) 1999 Omega System       (version 4.0)
14    Lup Lup Puzzle           (c) 1999 Omega System       (version 3.0 and 2.9)
15    Puzzle Bang Bang         (c) 1999 Omega System       (version 2.8)
16    Wyvern Wings             (c) 2001 SemiCom
17    Final Godori             (c) 2001 SemiCom            (version 2.20.5915)
1810
11    Minigame Cool Collection  (c) 1999 SemiCom
12    Lup Lup Puzzle            (c) 1999 Omega System       (version 3.0 and 2.9)
13    Puzzle Bang Bang          (c) 1999 Omega System       (version 2.8)
14    Super Lup Lup Puzzle      (c) 1999 Omega System       (version 4.0)
15    Vamp 1/2                  (c) 1999 Danbi & F2 System  (Korea version)
16    Date Quiz Go Go Episode 2 (c) 2000 SemiCom
17    Mission Craft             (c) 2000 Sun                (version 2.4)
18    Final Godori              (c) 2001 SemiCom            (version 2.20.5915)
19    Wyvern Wings              (c) 2001 SemiCom
20
1921 Games Needed:
2022
2123    Vamp 1/2 (World version)
2224
25 Actual games bugs:
26 - dquizgo2: bugged video test
27
2328*********************************************************************/
2429
2530#include "driver.h"
r936r937
202207   return readinputport(1) << 16;
203208}
204209
210static WRITE32_HANDLER( finalgdr_oki_bank_w )
211{
212   // is this right ?
213   if(data)
214      OKIM6295_set_bank_base(0, 0x40000 * (((data & 0x300) >> 8) - 1));
215}
216
205217static ADDRESS_MAP_START( common_map, ADDRESS_SPACE_PROGRAM, 16 )
206218   AM_RANGE(0x00000000, 0x001fffff) AM_RAM AM_BASE(&wram)
207219   AM_RANGE(0x40000000, 0x4003ffff) AM_RAM AM_BASE(&tiles)
r936r937
269281static ADDRESS_MAP_START( finalgdr_io, ADDRESS_SPACE_IO, 32 )
270282   AM_RANGE(0x2400, 0x2403) AM_READ(finalgdr_prot_r)
271283   //AM_RANGE(0x2800, 0x2803) AM_WRITE() //?
272   AM_RANGE(0x2c00, 0x2dff) AM_RAM //? it's only written
284   AM_RANGE(0x2c00, 0x2dff) AM_RAM //AM_BASE(&generic_nvram32) AM_SIZE(&generic_nvram_size)
273285   AM_RANGE(0x3000, 0x3003) AM_WRITE(ym2151_register32_w)
274286   AM_RANGE(0x3004, 0x3007) AM_READWRITE(ym2151_status32_r, ym2151_data32_w)
275287   AM_RANGE(0x3800, 0x3803) AM_READ(finalgdr_input0_r)
276288   AM_RANGE(0x3400, 0x3403) AM_READWRITE(oki32_r, oki32_w)
277289   AM_RANGE(0x3c00, 0x3c03) AM_READ(finalgdr_input1_r)
278290   AM_RANGE(0x4400, 0x4403) AM_READ(eeprom32_r)
279   //AM_RANGE(0x6000, 0x6003) AM_READ() //?
291   //AM_RANGE(0x6000, 0x6003) AM_READ(eeprom32_r) //?
280292   AM_RANGE(0x6000, 0x6003) AM_WRITE(finalgdr_eeprom_w)
281293   AM_RANGE(0x6040, 0x6043) AM_WRITE(finalgdr_prot_w)
282294   //AM_RANGE(0x6080, 0x6083) AM_WRITE(flipscreen32_w) //?
283295   //AM_RANGE(0x6060, 0x6063) AM_WRITE() //?
284   //AM_RANGE(0x60a0, 0x60a3) AM_WRITE() //oki bankswitch?
296   AM_RANGE(0x60a0, 0x60a3) AM_WRITE(finalgdr_oki_bank_w)
285297ADDRESS_MAP_END
286298
287299/*
r936r937
10091021   /* roml01 empty */
10101022   /* romh01 empty */
10111023
1012   ROM_REGION( 0x080000, REGION_SOUND1, 0 ) /* Oki Samples */
1024   ROM_REGION( 0x080000, REGION_USER2, 0 ) /* Oki Samples */
10131025   ROM_LOAD( "u7", 0x000000, 0x080000, CRC(080f61f8) SHA1(df3764b1b07f9fc38685e3706b0f834f62088727) )
1026
1027   /* $00000-$20000 stays the same in all sound banks, */
1028   /* the second half of the bank is what gets switched */
1029   ROM_REGION( 0xc0000, REGION_SOUND1, 0 ) /* Samples */
1030   ROM_COPY( REGION_USER2, 0x000000, 0x000000, 0x020000)
1031   ROM_COPY( REGION_USER2, 0x020000, 0x020000, 0x020000)
1032   ROM_COPY( REGION_USER2, 0x000000, 0x040000, 0x020000)
1033   ROM_COPY( REGION_USER2, 0x040000, 0x060000, 0x020000)
1034   ROM_COPY( REGION_USER2, 0x000000, 0x080000, 0x020000)
1035   ROM_COPY( REGION_USER2, 0x060000, 0x0a0000, 0x020000)
10141036ROM_END
10151037
1038/*
1039
1040Date Quiz Go Go Episode 2
1041SemiCom, 2000
1042
1043F-E1-16-010
1044
1045*/
1046
1047ROM_START( dquizgo2 )
1048   ROM_REGION16_BE( 0x100000, REGION_USER1, ROMREGION_ERASE00 ) /* Hyperstone CPU Code */
1049   ROM_LOAD( "rom1",         0x00000, 0x080000, CRC(81eef038) SHA1(9c925d1ef261ea85069925ccd1a5aeb939f55d5a) )
1050   ROM_LOAD( "rom2",         0x80000, 0x080000, CRC(e8789d8a) SHA1(1ee26c26cc7024c5df9d0da630b326021ece9f41) )
1051
1052   ROM_REGION( 0xc00000, REGION_GFX1, ROMREGION_DISPOSE ) /* 16x16x8 Sprites */
1053   ROM_LOAD32_WORD( "roml00", 0x000000, 0x200000, CRC(de811dd7) SHA1(bf31e165440ed2e3cdddd2174521b15afd8b2e69) )
1054   ROM_LOAD32_WORD( "romu00", 0x000002, 0x200000, CRC(2bdbfc6b) SHA1(8e755574e3c9692bd8f82c7351fe3623a31ec136) )
1055   ROM_LOAD32_WORD( "roml01", 0x400000, 0x200000, CRC(f574a2a3) SHA1(c6a8aca75bd3a4e4109db5095f3a3edb9b1e6657) )
1056   ROM_LOAD32_WORD( "romu01", 0x400002, 0x200000, CRC(d05cf02f) SHA1(624316d4ee42c6257bc64747e4260a0d3950f9cd) )
1057   ROM_LOAD32_WORD( "roml02", 0x800000, 0x200000, CRC(43ca2cff) SHA1(02ad7cce42d917dbefdba2e4e8886fc883b1dc60) )
1058   ROM_LOAD32_WORD( "romu02", 0x800002, 0x200000, CRC(b8218222) SHA1(1e1aa60e0de9c02b841896512a1163dda280c845) )
1059   /* roml03 empty */
1060   /* romu03 empty */
1061
1062   ROM_REGION( 0x40000, REGION_SOUND1, 0 ) /* Oki Samples */
1063   ROM_LOAD( "vrom1", 0x00000, 0x40000, CRC(24d5b55f) SHA1(cb4d3a22440831e37df0a7fe5433bea708d60f31) )
1064ROM_END
1065
10161066static int irq_active(void)
10171067{
10181068   UINT32 FCR = activecpu_get_reg(27);
r936r937
11391189   return wram32[0x005e874/4];
11401190}
11411191
1192static READ16_HANDLER( dquizgo2_speedup_r )
1193{
1194   if(activecpu_get_pc() == 0xaa622)
1195   {
1196      if(irq_active())
1197         cpu_spinuntil_int();
1198      else
1199         activecpu_eat_cycles(50);
1200   }
11421201
1202   return wram[(0xcde70/2)+offset];
1203}
1204
1205
11431206DRIVER_INIT( vamphalf )
11441207{
11451208   memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x0004a6d0, 0x0004a6d3, 0, 0, vamphalf_speedup_r );
r936r937
12181281   semicom_prot_data[1] = 3;
12191282}
12201283
1284DRIVER_INIT( dquizgo2 )
1285{
1286   memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x00cde70, 0x00cde73, 0, 0, dquizgo2_speedup_r );
1287
1288   palshift = 0;
1289   flip_bit = 1;
1290}
1291
12211292GAME( 1999, coolmini, 0,      coolmini, common,   coolmini, ROT0,   "SemiCom",           "Cool Minigame Collection", 0 )
12221293GAME( 1999, suplup,   0,      suplup,   common,   suplup,   ROT0,   "Omega System",      "Super Lup Lup Puzzle / Zhuan Zhuan Puzzle (version 4.0 / 990518)" , 0)
12231294GAME( 1999, luplup,   suplup, suplup,   common,   luplup,   ROT0,   "Omega System",      "Lup Lup Puzzle / Zhuan Zhuan Puzzle (version 3.0 / 990128)", 0 )
12241295GAME( 1999, luplup29, suplup, suplup,   common,   luplup29, ROT0,   "Omega System",      "Lup Lup Puzzle / Zhuan Zhuan Puzzle (version 2.9 / 990108)", 0 )
12251296GAME( 1999, puzlbang, suplup, suplup,   common,   puzlbang, ROT0,   "Omega System",      "Puzzle Bang Bang (version 2.8 / 990106)", 0 )
12261297GAME( 1999, vamphalf, 0,      vamphalf, common,   vamphalf, ROT0,   "Danbi & F2 System", "Vamp 1/2 (Korea version)", 0 )
1298GAME( 2000, dquizgo2, 0,      coolmini, common,   dquizgo2, ROT0,   "SemiCom",           "Date Quiz Go Go Episode 2" , 0)
12271299GAME( 2000, misncrft, 0,      misncrft, common,   misncrft, ROT90,  "Sun",               "Mission Craft (version 2.4)", GAME_NO_SOUND )
12281300GAME( 2001, finalgdr, 0,      finalgdr, common,   finalgdr, ROT0,   "SemiCom",           "Final Godori (Korea)", GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
12291301GAME( 2001, wyvernwg, 0,      wyvernwg, common,   wyvernwg, ROT270, "SemiCom (Game Vision License)", "Wyvern Wings", GAME_NO_SOUND )
src/mame/drivers/galaga.c
r936r937
14691469   RGN_FRAC(1,1),
14701470   2,
14711471   { 0, 4 },
1472   { 8*8+0, 8*8+1, 8*8+2, 8*8+3, 0, 1, 2, 3 },
1473   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
1472   { STEP4(8*8,1), STEP4(0*8,1) },
1473   { STEP8(0*8,8) },
14741474   16*8
14751475};
14761476
r936r937
14801480   RGN_FRAC(1,1),
14811481   1,
14821482   { 0 },
1483   { 0, 1, 2, 3, 4, 5, 6, 7 },
1484   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
1483   { STEP8(0,1) },
1484   { STEP8(0,8) },
14851485   8*8
14861486};
14871487
r936r937
14911491   RGN_FRAC(1,1),
14921492   1,
14931493   { 0 },
1494   { 7, 6, 5, 4, 3, 2, 1, 0 },
1495   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
1494   { STEP8(7,-1) },
1495   { STEP8(0,8) },
14961496   8*8
14971497};
14981498
r936r937
15021502   RGN_FRAC(1,2),
15031503   2,
15041504   { 0, RGN_FRAC(1,2) },
1505   { 0, 1, 2, 3, 4, 5, 6, 7 },
1506   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
1505   { STEP8(0,1) },
1506   { STEP8(0,8) },
15071507   8*8
15081508};
15091509
r936r937
15131513   RGN_FRAC(1,1),
15141514   2,
15151515   { 0, 4 },
1516   { 8*8, 8*8+1, 8*8+2, 8*8+3, 16*8+0, 16*8+1, 16*8+2, 16*8+3,
1517         24*8+0, 24*8+1, 24*8+2, 24*8+3, 0, 1, 2, 3  },
1518   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
1519         32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
1516   { STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1), STEP4(0*8,1) },
1517   { STEP8(0*8,8), STEP8(32*8,8) },
15201518   64*8
15211519};
15221520
r936r937
15261524   RGN_FRAC(1,1),
15271525   2,
15281526   { 0, 4 },
1529   { 0, 1, 2, 3, 8*8, 8*8+1, 8*8+2, 8*8+3, 16*8+0, 16*8+1, 16*8+2, 16*8+3,
1530         24*8+0, 24*8+1, 24*8+2, 24*8+3 },
1531   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
1532         32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
1527   { STEP4(0*8,1), STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1) },
1528   { STEP8(0*8,8), STEP8(32*8,8) },
15331529   64*8
15341530};
15351531
r936r937
15391535   RGN_FRAC(1,2),
15401536   3,
15411537   { RGN_FRAC(1,2)+4, 0, 4 },
1542   { 0, 1, 2, 3, 8*8+0, 8*8+1, 8*8+2, 8*8+3,
1543         16*8+0, 16*8+1, 16*8+2, 16*8+3, 24*8+0, 24*8+1, 24*8+2, 24*8+3 },
1544   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
1545         32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
1538   { STEP4(0*8,1), STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1) },
1539   { STEP8(0*8,8), STEP8(32*8,8) },
15461540   64*8
15471541};
15481542
r936r937
15521546   8,
15531547   3,   /* 2 bits color + 1 bit transparency */
15541548   { 5, 6, 7 },
1555   { 0*8, 1*8, 2*8, 3*8 },
1556   { 0*32, 1*32, 2*32, 3*32 },
1549   { STEP4(0,8) },
1550   { STEP4(0,32) },
15571551   16*8
15581552};
15591553
r936r937
16721666   MDRV_SCREEN_SIZE(36*8, 32*8)
16731667   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 2*8, 30*8-1)
16741668   MDRV_GFXDECODE(gfxdecodeinfo_bosco)
1675   MDRV_PALETTE_LENGTH(32+64)
1676   MDRV_COLORTABLE_LENGTH(64*4+64*4+8)
1669   MDRV_PALETTE_LENGTH(64*4+64*4+4+64)
16771670
16781671   MDRV_PALETTE_INIT(bosco)
16791672   MDRV_VIDEO_START(bosco)
r936r937
17311724   MDRV_SCREEN_SIZE(36*8, 28*8)
17321725   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 0*8, 28*8-1)
17331726   MDRV_GFXDECODE(gfxdecodeinfo_galaga)
1734   MDRV_PALETTE_LENGTH(32+64)
1735   MDRV_COLORTABLE_LENGTH(64*4+64*4)
1727   MDRV_PALETTE_LENGTH(64*4+64*4+64)
17361728
17371729   MDRV_PALETTE_INIT(galaga)
17381730   MDRV_VIDEO_START(galaga)
r936r937
18051797   MDRV_SCREEN_SIZE(36*8, 28*8)
18061798   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 0*8, 28*8-1)
18071799   MDRV_GFXDECODE(gfxdecodeinfo_xevious)
1808   MDRV_PALETTE_LENGTH(128+1)
1809   MDRV_COLORTABLE_LENGTH(128*4+64*8+64*2)
1800   MDRV_PALETTE_LENGTH(128*4+64*8+64*2)
18101801
18111802   MDRV_PALETTE_INIT(xevious)
18121803   MDRV_VIDEO_START(xevious)
r936r937
18791870   MDRV_SCREEN_SIZE(36*8, 28*8)
18801871   MDRV_SCREEN_VISIBLE_AREA(0*8, 36*8-1, 0*8, 28*8-1)
18811872   MDRV_GFXDECODE(gfxdecodeinfo_digdug)
1882   MDRV_PALETTE_LENGTH(32)
1883   MDRV_COLORTABLE_LENGTH(16*2+64*4+64*4)
1873   MDRV_PALETTE_LENGTH(16*2+64*4+64*4)
18841874
18851875   MDRV_PALETTE_INIT(digdug)
18861876   MDRV_VIDEO_START(digdug)
src/mame/drivers/istellar.c
r936r937
406406
407407/*    YEAR  NAME    PARENT   MACHINE  INPUT    INIT    MONITOR  COMPANY          FULLNAME                       FLAGS) */
408408GAME( 1983, istellar, 0,       istellar,  istellar,  istellar, ROT0,    "Funai/Gakken",  "Interstellar Laser Fantasy",  GAME_NOT_WORKING|GAME_NO_SOUND)
409/*
410Funai / Gakken Interstellar Laser Fantasy laserdisc hardware
411Driver by Andrew Gardner with help from Daphne Source
412
413Notes:
414    Holding down the TEST switch (T) while hitting reset will bring up the Self Test.
415    Hit T twice more for color and monitor calibration.
416    This is somewhat strange hardware : More z80's than necessary
417                                        3 bpp sprites
418                                        6-pin dip switches with odd handling
419                                        inverted DIP logic?
420                                        CPU2 maps RAM over where its ROM lives
421    The DIP switch settings seem to be inverted (or the test mode shows 1 for open and 0 for closed).  This is fine, but
422        the DIPLOC stuff displays the switches off when they should be on and vice-versa.  Maybe a fix the DIPlOCc code is needed?
423
424Todo:
425    How does one best make one DIP switch bit from address 0x02 tie to two bits from address 0x03?
426    Get real ROM labels!  The current labels are unfortunately a bit odd.
427    Add sprite drawing.
428    Convert to tilemaps.
429    Make it work - this one should be close right now :/.
430*/
431
432#include "driver.h"
433#include "render.h"
434#include "machine/laserdsc.h"
435
436/* There is only 1 crystal on the stack of 3 boards - speed is unknown, the following is Daphne's guess */
437#define GUESSED_CLOCK (3072000)
438
439
440/* Misc variables */
441static laserdisc_info *discinfo;
442
443static UINT8 *tile_ram;
444static UINT8 *tile_control_ram;
445static UINT8 *sprite_ram;
446
447static UINT8 ldp_latch1;
448static UINT8 ldp_latch2;
449
450static UINT8 z80_2_nmi_enable;
451
452/* VIDEO GOODS */
453VIDEO_UPDATE( istellar )
454{
455   int charx, chary;
456
457   /* clear */
458   fillbitmap(bitmap, 0, cliprect);
459
460   /* display disc information */
461   if (discinfo != NULL)
462      popmessage("%s", laserdisc_describe_state(discinfo));
463
464   /* DEBUG */
465   /*
466    for (charx = 0; charx < 0x400; charx ++)
467    {
468        printf ("%x ", sprite_ram[charx]) ;
469    }
470    printf("\n\n\n");
471    */
472
473   /* Draw tiles */
474   for (charx = 0; charx < 32; charx++)
475   {
476      for (chary = 0; chary < 32; chary++)
477      {
478         int current_screen_character = (chary*32) + charx;
479
480         drawgfx(bitmap, machine->gfx[0],
481               tile_ram[current_screen_character],
482               (tile_control_ram[current_screen_character] & 0x0f),
483               0, 0, charx*8, chary*8, cliprect, TRANSPARENCY_PEN, 0);
484      }
485   }
486
487
488   /* Draw sprites */
489
490   return 0;
491}
492
493
494
495/* MEMORY HANDLERS */
496/* Z80 0 R/W */
497READ8_HANDLER(z80_0_latch1_read)
498{
499   /*logerror("CPU0 : reading LDP status latch (%x)\n", ldp_latch1);*/
500   return ldp_latch1;
501}
502
503WRITE8_HANDLER(z80_0_latch2_write)
504{
505   /*logerror("CPU0 : writing cpu_latch2 (%x).  Potentially followed by an IRQ.\n", data);*/
506   ldp_latch2 = data;
507
508   /* A CPU2 NMI */
509   if (z80_2_nmi_enable)
510   {
511      logerror("Executing an NMI on CPU2\n");
512      cpunum_set_input_line(2, INPUT_LINE_NMI, PULSE_LINE);      /* Maybe this is a ASSERT_LINE, CLEAR_LINE combo? */
513      z80_2_nmi_enable = 0;
514   }
515}
516
517
518/* Z80 1 R/W */
519
520
521/* Z80 2 R/W */
522READ8_HANDLER(z80_2_ldp_read)
523{
524   UINT8 readResult = laserdisc_data_r(discinfo);
525   logerror("CPU2 : reading LDP : %x\n", readResult);
526   return readResult;
527}
528
529READ8_HANDLER(z80_2_latch2_read)
530{
531   logerror("CPU2 : reading latch2 (%x)\n", ldp_latch2);
532   return ldp_latch2;
533}
534
535READ8_HANDLER(z80_2_nmienable)
536{
537   logerror("CPU2 : ENABLING NMI\n");
538   z80_2_nmi_enable = 1;
539   return 0x00;
540}
541
542READ8_HANDLER(z80_2_unknown_read)
543{
544   logerror("CPU2 : c000!\n");
545   return 0x00;
546}
547
548WRITE8_HANDLER(z80_2_latch1_write)
549{
550   logerror("CPU2 : writing latch1 (%x)\n", data);
551   ldp_latch1 = data;
552}
553
554WRITE8_HANDLER(z80_2_ldp_write)
555{
556   logerror("CPU2 : writing LDP : 0x%x\n", data);
557   laserdisc_data_w(discinfo,data);
558}
559
560
561
562/* PROGRAM MAPS */
563static ADDRESS_MAP_START( z80_0_mem, ADDRESS_SPACE_PROGRAM, 8 )
564   AM_RANGE(0x0000,0x9fff) AM_ROM
565   AM_RANGE(0xa000,0xa7ff) AM_RAM
566   AM_RANGE(0xa800,0xabff) AM_RAM AM_BASE(&tile_ram)
567   AM_RANGE(0xac00,0xafff) AM_RAM AM_BASE(&tile_control_ram)
568   AM_RANGE(0xb000,0xb3ff) AM_RAM AM_BASE(&sprite_ram)
569ADDRESS_MAP_END
570
571static ADDRESS_MAP_START( z80_1_mem, ADDRESS_SPACE_PROGRAM, 8 )
572   AM_RANGE(0x0000,0x1fff) AM_ROM
573   AM_RANGE(0x4000,0x47ff) AM_RAM
574ADDRESS_MAP_END
575
576static ADDRESS_MAP_START( z80_2_mem, ADDRESS_SPACE_PROGRAM, 8 )
577   AM_RANGE(0x0000,0x17ff) AM_ROM
578   AM_RANGE(0x1800,0x1fff) AM_RAM
579   AM_RANGE(0xc000,0xc000) AM_READ(z80_2_unknown_read)      /* Seems to be thrown away every time it's read - maybe interrupt related? */
580ADDRESS_MAP_END
581
582
583/* IO MAPS */
584static ADDRESS_MAP_START( z80_0_io, ADDRESS_SPACE_IO, 8 )
585   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
586   AM_RANGE(0x00,0x00) AM_READ_PORT("IN0")
587   AM_RANGE(0x02,0x02) AM_READ_PORT("DSW1")
588   AM_RANGE(0x03,0x03) AM_READ_PORT("DSW2")
589   /*AM_RANGE(0x04,0x04) AM_WRITE(volatile_palette_write)*/
590   AM_RANGE(0x05,0x05) AM_READWRITE(z80_0_latch1_read,z80_0_latch2_write)
591ADDRESS_MAP_END
592
593static ADDRESS_MAP_START( z80_1_io, ADDRESS_SPACE_IO, 8 )
594   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
595   AM_RANGE(0x00,0x00) AM_NOP /*AM_READWRITE(z80_1_slatch_read,z80_1_slatch_write)*/
596   AM_RANGE(0x01,0x01) AM_NOP /*AM_READWRITE(z80_1_nmienable,z80_1_soundwrite_front)*/
597   AM_RANGE(0x02,0x02) AM_NOP /*AM_WRITE(z80_1_soundwrite_rear)*/
598ADDRESS_MAP_END
599
600static ADDRESS_MAP_START( z80_2_io, ADDRESS_SPACE_IO, 8 )
601   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
602   AM_RANGE(0x00,0x00) AM_READWRITE(z80_2_ldp_read,z80_2_ldp_write)
603   AM_RANGE(0x01,0x01) AM_READWRITE(z80_2_latch2_read,z80_2_latch1_write)
604   AM_RANGE(0x02,0x02) AM_READ(z80_2_nmienable)
605/*  AM_RANGE(0x03,0x03) AM_WRITE(z80_2_ldtrans_write)*/
606ADDRESS_MAP_END
607
608
609/* PORTS */
610INPUT_PORTS_START( istellar )
611   /* TEST MODE might display a 0 for a short and a 1 for an open circuit?  If so, everything below is inverted. */
612   PORT_START_TAG("DSW1")
613   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW1:1")
614   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
615   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
616   PORT_DIPNAME( 0x0e, 0x00, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:2,3,4")
617   PORT_DIPSETTING(    0x02, DEF_STR( 2C_1C ) )
618   PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
619   PORT_DIPSETTING(    0x06, DEF_STR( 2C_3C ) )
620   PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
621   PORT_DIPSETTING(    0x04, DEF_STR( 1C_3C ) )
622   PORT_DIPSETTING(    0x0c, DEF_STR( 1C_6C ) )
623   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW1:5,6")
624   PORT_DIPSETTING(    0x00, "3" )
625   PORT_DIPSETTING(    0x10, "4" )
626   PORT_DIPSETTING(    0x20, "5" )
627   PORT_DIPSETTING(    0x30, "10" )
628   PORT_DIPNAME( 0x40, 0x00, "Barrier UFO" ) PORT_DIPLOCATION("SW2:1")
629   PORT_DIPSETTING(    0x40, DEF_STR( No ) )
630   PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
631   PORT_DIPNAME( 0x80, 0x00, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:2")
632   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
633   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
634
635   /* NOTE - bit 0x80 in the above read is combined with bits 0x03 in the below read to form the Coin_B
636              settings.  I'm unaware of what mechanism MAME will use to make this work right? */
637
638   /* "In case of inter-stellar upright type the coin switch 2 is not used."  Quoth the manual. */
639   PORT_START_TAG("DSW2")
640   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:3")
641   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
642   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
643   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:4")
644   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
645   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
646   PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:5")      /* Maybe SERVICE? */
647   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
648   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
649   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "TEST" ) PORT_CODE( KEYCODE_T )
650   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN2 )
651   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
652   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_START2 )
653   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_START1 )
654
655   PORT_START_TAG("IN0")
656   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_4WAY
657   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_4WAY
658   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_4WAY
659   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_4WAY
660   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 )
661   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2 )
662   /* SERVICE might be hanging out back here */
663INPUT_PORTS_END
664
665PALETTE_INIT( istellar )
666{
667   int i;
668
669   /* Oddly enough, the top 4 bits of each byte is 0 */
670   for (i = 0; i < machine->drv->total_colors; i++)
671   {
672      int r,g,b;
673      int bit0,bit1,bit2,bit3;
674
675      /* Daphne says "TODO: get the real interstellar resistor values" */
676
677      /* red component */
678      bit0 = (color_prom[i+0x000] >> 0) & 0x01;
679      bit1 = (color_prom[i+0x000] >> 1) & 0x01;
680      bit2 = (color_prom[i+0x000] >> 2) & 0x01;
681      bit3 = (color_prom[i+0x000] >> 3) & 0x01;
682      r = (0x8f * bit3) + (0x43 * bit2) + (0x1f * bit1) + (0x0e * bit0);
683
684      /* green component */
685      bit0 = (color_prom[i+0x100] >> 0) & 0x01;
686      bit1 = (color_prom[i+0x100] >> 1) & 0x01;
687      bit2 = (color_prom[i+0x100] >> 2) & 0x01;
688      bit3 = (color_prom[i+0x100] >> 3) & 0x01;
689      g = (0x8f * bit3) + (0x43 * bit2) + (0x1f * bit1) + (0x0e * bit0);
690
691      /* blue component */
692      bit0 = (color_prom[i+0x200] >> 0) & 0x01;
693      bit1 = (color_prom[i+0x200] >> 1) & 0x01;
694      bit2 = (color_prom[i+0x200] >> 2) & 0x01;
695      bit3 = (color_prom[i+0x200] >> 3) & 0x01;
696      b = (0x8f * bit3) + (0x43 * bit2) + (0x1f * bit1) + (0x0e * bit0);
697
698      palette_set_color(machine,i,MAKE_RGB(r,g,b));
699   }
700}
701
702static const gfx_layout istellar_gfx_layout =
703{
704   8,8,
705   0x2000/8,
706   3,
707   { 0, 0x2000*8, 0x4000*8 },
708   { 0,1,2,3,4,5,6,7 },
709   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
710   8*8
711};
712
713static const gfx_decode gfxdecodeinfo[] =
714{
715   { REGION_GFX1, 0, &istellar_gfx_layout, 0x0, 0x100 },
716   { -1 }
717};
718
719static MACHINE_START( istellar )
720{
721   discinfo = laserdisc_init(LASERDISC_TYPE_LDV1000, get_disk_handle(0), 0);
722   return;
723}
724
725static INTERRUPT_GEN( vblank_callback_istellar )
726{
727   /* Interrupt presumably comes from VBlank */
728   cpunum_set_input_line(0, 0, ASSERT_LINE);
729
730   /* Interrupt presumably comes from the LDP's status strobe */
731   cpunum_set_input_line(2, 0, ASSERT_LINE);
732
733   /* Only do the LDP's sync once */
734   if (cpu_getactivecpu() == 0)
735      laserdisc_vsync(discinfo);
736}
737
738
739/* DRIVER */
740static MACHINE_DRIVER_START( istellar )
741/*  main cpu */
742   MDRV_CPU_ADD(Z80, GUESSED_CLOCK)
743   MDRV_CPU_PROGRAM_MAP(z80_0_mem,0)
744   MDRV_CPU_IO_MAP(z80_0_io,0)
745   MDRV_CPU_VBLANK_INT(vblank_callback_istellar, 1)
746
747/*  sound cpu */
748   MDRV_CPU_ADD(Z80, GUESSED_CLOCK)
749   MDRV_CPU_PROGRAM_MAP(z80_1_mem,0)
750   MDRV_CPU_IO_MAP(z80_1_io,0)
751
752/*  ldp comm cpu */
753   MDRV_CPU_ADD(Z80, GUESSED_CLOCK)
754   MDRV_CPU_PROGRAM_MAP(z80_2_mem,0)
755   MDRV_CPU_IO_MAP(z80_2_io,0)
756
757   MDRV_MACHINE_START(istellar)
758
759/*  video */
760   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
761
762   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
763   MDRV_SCREEN_REFRESH_RATE(60)
764   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
765   MDRV_SCREEN_SIZE(32*8, 32*8)
766   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 32*8-1)
767
768   MDRV_PALETTE_LENGTH(256)
769   MDRV_PALETTE_INIT(istellar)
770
771   MDRV_GFXDECODE(gfxdecodeinfo)
772   MDRV_VIDEO_UPDATE(istellar)
773
774/*  sound */
775MACHINE_DRIVER_END
776
777
778/* There is a photo of the PCB with blurry IC locations and labels.  Comments reflect what I can (barely) see. */
779ROM_START( istellar )
780   /* Main program CPU */
781   ROM_REGION( 0xa000, REGION_CPU1, 0 )
782   ROM_LOAD( "rom2.top", 0x0000, 0x2000, CRC(5d643381) SHA1(75ca52c28a52f534eda00c18b0db97e9923ff670) )   /* At IC location C63 (top board) - label ? */
783   ROM_LOAD( "rom3.top", 0x2000, 0x2000, CRC(ce5a2b09) SHA1(2de6a6e993c3411577ac0c834db8aaf16fb007ed) )   /* At IC location C64 (top board) - label ? */
784   ROM_LOAD( "rom4.top", 0x4000, 0x2000, CRC(7c2cb1f1) SHA1(ffd92510c03c2d35a59d233883c2b9f57394a51c) )   /* At IC location C65 (top board) - label ? */
785   ROM_LOAD( "rom5.top", 0x6000, 0x2000, CRC(354377f6) SHA1(bcf95b7ee1b47854e10baf24b0d8af3d56738b99) )   /* At IC location C66 (top board) - label ? */
786   ROM_LOAD( "rom6.top", 0x8000, 0x2000, CRC(0319bf40) SHA1(f324626e457c3eb7d6b74bc6afbfcc3aab2b3c72) )   /* At IC location C67 (top board) - label ? */
787
788   /* Sound CPU */
789   ROM_REGION( 0x2000, REGION_CPU2, 0 )
790   ROM_LOAD( "rom1.top", 0x0000, 0x2000, CRC(4f34fb1d) SHA1(56ca19344c84c5989d0be797e2759f84760310be) )   /* At IC location C62 (top board) - label ? */
791
792   /* LDP Communications CPU */
793   ROM_REGION( 0x2000, REGION_CPU3, 0 )
794   ROM_LOAD( "rom11.bot", 0x0000, 0x2000, CRC(165cbc57) SHA1(39463888f22ec3125f0686066d923a9aae79a8f7) )   /* At IC location C12 (bottom board) - label IS11 */
795
796   /* Tiles */
797   ROM_REGION( 0x6000, REGION_GFX1, ROMREGION_DISPOSE )
798   ROM_LOAD( "rom9.bot", 0x0000, 0x2000, CRC(9d79acb6) SHA1(72af972695face0016afce8a26c629d963e86d48) )   /* At IC location C47? (bottom board) - label ? */
799   ROM_LOAD( "rom8.bot", 0x2000, 0x2000, CRC(e9c9e490) SHA1(79aa35552b984018bc723adece5c40a0833a313c) )   /* At IC location C48? (bottom board) - label ? */
800   ROM_LOAD( "rom7.bot", 0x4000, 0x2000, CRC(1447ce3a) SHA1(8545cec108df6adab303802b1407c89b2dceba21) )   /* At IC location C49? (bottom board) - label ? */
801
802   /* Color PROMs */
803   ROM_REGION( 0x300, REGION_PROMS, 0 )
804   ROM_LOAD( "red6b.bot",   0x000, 0x100, CRC(5c52f844) SHA1(a8a3d91f3247ad13c805d8d8288b07f3cdaf1189) )   /* At IC location C63? (bottom board) - label ? */
805   ROM_LOAD( "green6c.bot", 0x100, 0x100, CRC(7d8c845c) SHA1(04ae2ca0cc6679e21346ce34e9e01aa5bf4e2067) )   /* At IC location C62? (bottom board) - label ? */
806   ROM_LOAD( "blue6d.bot",  0x200, 0x100, CRC(5ebb81f9) SHA1(285d60f2894c524ca80fc68ad7c2dfd9093a67ea) )   /* At IC location C61? (bottom board) - label ? */
807ROM_END
808
809
810static DRIVER_INIT( istellar )
811{
812   z80_2_nmi_enable = 0;
813}
814
815/*    YEAR  NAME    PARENT   MACHINE  INPUT    INIT    MONITOR  COMPANY          FULLNAME                       FLAGS) */
816GAME( 1983, istellar, 0,       istellar,  istellar,  istellar, ROT0,    "Funai/Gakken",  "Interstellar Laser Fantasy",  GAME_NOT_WORKING|GAME_NO_SOUND)
src/mame/drivers/pacland.c
r936r937
376376   RGN_FRAC(1,2),
377377   4,
378378   { 0, 4, RGN_FRAC(1,2)+0, RGN_FRAC(1,2)+4 },
379   { 0, 1, 2, 3, 8*8, 8*8+1, 8*8+2, 8*8+3,
380         16*8+0, 16*8+1, 16*8+2, 16*8+3, 24*8+0, 24*8+1, 24*8+2, 24*8+3 },
381   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
382         32*8, 33*8, 34*8, 35*8, 36*8, 37*8, 38*8, 39*8 },
379   { STEP4(0*8,1), STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1) },
380   { STEP8(0*8,8), STEP8(32*8,8) },
383381   64*8
384382};
385383
r936r937
389387   RGN_FRAC(1,1),
390388   2,
391389   { 0, 4 },
392   { 8*8, 8*8+1, 8*8+2, 8*8+3, 0, 1, 2, 3 },
393   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
390   { STEP4(8*8,1), STEP4(0*8,1) },
391   { STEP8(0*8,8) },
394392   16*8
395393};
396394
r936r937
435433   MDRV_SCREEN_SIZE(64*8, 32*8)
436434   MDRV_SCREEN_VISIBLE_AREA(3*8, 39*8-1, 2*8, 30*8-1)
437435   MDRV_GFXDECODE(gfxdecodeinfo)
438   MDRV_PALETTE_LENGTH(256)
439   MDRV_COLORTABLE_LENGTH(256*4+256*4+2*64*16)
436   MDRV_PALETTE_LENGTH(256*4+256*4+2*64*16)
440437
441438   MDRV_PALETTE_INIT(pacland)
442439   MDRV_VIDEO_START(pacland)
src/mame/drivers/ddrible.c
r936r937
103103   /* b5 : VLM5030-ST        */
104104   /* b4 : VLM5300-VCU       */
105105   /* b3 : ROM bank select   */
106   if (sndti_to_sndnum(SOUND_VLM5030, 0) >= 0)
106   if (sndti_exists(SOUND_VLM5030, 0))
107107   {
108108      VLM5030_RST( data & 0x40 ? 1 : 0 );
109109      VLM5030_ST(  data & 0x20 ? 1 : 0 );
r936r937
113113   /* b2 : SSG-C rc filter enable */
114114   /* b1 : SSG-B rc filter enable */
115115   /* b0 : SSG-A rc filter enable */
116   if (sndti_to_sndnum(SOUND_FILTER_RC, 2) >= 0)
116   if (sndti_exists(SOUND_FILTER_RC, 2))
117117   {
118118      filter_rc_set_RC(2,FLT_RC_LOWPASS, 1000,2200,1000,data & 0x04 ? CAP_N(150) : 0); /* YM2203-SSG-C */
119119      filter_rc_set_RC(1,FLT_RC_LOWPASS, 1000,2200,1000,data & 0x02 ? CAP_N(150) : 0); /* YM2203-SSG-B */
src/mame/drivers/thayers.c
r936r937
507507   cop_g_latch = 0xff;
508508}
509509
510/*    YEAR  NAME     PARENT   MACHINE  INPUT    INIT     MONITOR  COMPANY               FULLNAME           FLAGS) */
511GAME( 1983, thayers, 0,       thayers, thayers, thayers, ROT0,    "RDI Video Systems",  "Thayer's Quest",  GAME_NOT_WORKING|GAME_NO_SOUND)
512/*
513RDI Video Systems Thayer's Quest laserdisc hardware
514Driver by Andrew Gardner from schematics with help from Daphne Source
515
516Notes:
517    How odd.  The schematics say there's a COP421L hooked up, but they also make mention of
518      a COP404L - A ROMless COP420 with 1k of RAM.  I wonder which one is correct?
519
520Todo:
521    Add SIO to the cop420 core.
522    Fix up my poor interpretation of the hard-to-read schematics.
523    Write a real SC-01 (SSI-263) emulator for MAME.
524    Convert to tilemaps.
525*/
526
527#include "driver.h"
528#include "render.h"
529#include "machine/laserdsc.h"
530#include "cpu/cop400/cop400.h"
531
532#define SCHEMATIC_CLOCK (4000000)
533
534/*
535 * Z80 IRQ Status bit
536 * ------------------
537 *
538 * Bit      | Use
539 * 76543210-+----------------
540 * -------x | Unused
541 * ------x- | Unused
542 * -----x-- | SSI-263 Request Data.
543 * ----x--- | always high. (? but it's checked at 0x1bb ?)
544 * ---x---- | /TIMER INT.
545 * --x----- | /DATA RDY INT.
546 * -x------ | /CART PRES.
547 * x------- | Unused
548 */
549static UINT8 z80_irq_status;
550
551#define Z80_IRQ_STATUS_SET()   (z80_irq_status = 0x00)
552#define Z80_IRQ_STATUS_CLEAR() (z80_irq_status = 0xff)
553
554#define Z80_SSI_REQUEST()  ((z80_irq_status & 0x04) >> 2)
555#define Z80_TIMER_INT()    ((z80_irq_status & 0x10) >> 4)
556#define Z80_DATA_RDY_INT() ((z80_irq_status & 0x20) >> 5)
557#define Z80_CART_PRES()    ((z80_irq_status & 0x40) >> 6)
558
559#define SET_Z80_SSI_REQUEST()  (z80_irq_status &= ~0x04)
560#define SET_Z80_TIMER_INT()    (z80_irq_status &= ~0x10)
561#define SET_Z80_DATA_RDY_INT() (z80_irq_status &= ~0x20)
562#define SET_Z80_CART_PRES()    (z80_irq_status &= ~0x40)
563
564#define CLEAR_Z80_SSI_REQUEST()  (z80_irq_status |= 0x04)
565#define CLEAR_Z80_TIMER_INT()    (z80_irq_status |= 0x10)
566#define CLEAR_Z80_DATA_RDY_INT() (z80_irq_status |= 0x20)
567#define CLEAR_Z80_CART_PRES()    (z80_irq_status |= 0x40)
568
569
570/* Misc variables */
571static UINT8* ram_ic;
572static laserdisc_info *discinfo;
573
574static UINT8 m_ssi_control;
575static UINT8 cop_g_latch;
576static UINT8 cop_l_latch;
577
578
579
580/* VIDEO GOODS */
581VIDEO_UPDATE( thayers )
582{
583   /* display disc information */
584   if (discinfo != NULL)
585      popmessage("%s", laserdisc_describe_state(discinfo));
586
587   return 0;
588}
589
590
591
592/* MEMORY HANDLERS */
593/* Z80 R/W */
594READ8_HANDLER(z80_irq_status_r)
595{
596   return z80_irq_status;
597}
598
599READ8_HANDLER(ram_ic_read)
600{
601   /* Daphne patches.
602    if (offset == 0xbe07-0x8000)
603        return 0x02;
604
605    if (offset == 0xbe17-0x8000)
606        return 0x01;
607    */
608
609   return ram_ic[offset];
610}
611
612static UINT32 laserdisc_status_r(void *param)
613{
614   if (discinfo == NULL)
615      return 0;
616
617   /* Someday handle multiple LD players */
618   return (laserdisc_line_r(discinfo, LASERDISC_LINE_STATUS) == ASSERT_LINE) ? 0 : 1;
619}
620
621static UINT32 laserdisc_command_r(void *param)
622{
623   if (discinfo == NULL)
624      return 0;
625
626   /* Someday handle multiple LD players */
627   return (laserdisc_line_r(discinfo, LASERDISC_LINE_COMMAND) == ASSERT_LINE) ? 0 : 1;
628}
629
630WRITE8_HANDLER(ram_ic_write)
631{
632   ram_ic[offset] = data;
633}
634
635WRITE8_HANDLER(data_ready_int_w)
636{
637   CLEAR_Z80_DATA_RDY_INT();
638   /* Hackaroo? */
639   /* cop_l_latch = 0x00; */
640}
641
642WRITE8_HANDLER(timer_int_w)
643{
644   CLEAR_Z80_TIMER_INT();
645}
646
647WRITE8_HANDLER(write_cop)
648{
649   logerror("Writing 0x%x to COP port G\n", data);
650
651   /* Bits 5-7 write to COP421 ports G0-G2 */
652   cop_g_latch = (data >> 5) & 0x07;
653
654   /* Bit 2 goes to BANKSELT */
655   /* bankselect = (data & 0x04) >> 2; */
656
657   /* Bit 1 goes to CS128x? (illegible schems) */
658}
659
660WRITE8_HANDLER(data_write_cop)
661{
662   cop_l_latch = data;
663}
664
665WRITE8_HANDLER(intrq_w)
666{
667   cpunum_set_input_line(0, 0, ASSERT_LINE);
668}
669
670WRITE8_HANDLER(sc01_register_w)
671{
672   /* (Thank you Daphne) */
673   switch (offset)
674   {
675      case 0x00:
676         if (m_ssi_control)
677         {
678            logerror("SC-01 control mode : 0x%x\n", data);
679
680            switch(data)
681            {
682               /* Stop requesting phonemes */
683               case 0x00:
684                  CLEAR_Z80_SSI_REQUEST();
685                  break;
686
687               /* Start adding phonemes */
688               case 0xc0:
689                  SET_Z80_SSI_REQUEST();
690                    if (!(Z80_SSI_REQUEST()))
691                     logerror("SETTING IRQ LINE sc01\n");
692                        cpunum_set_input_line(0, 0, ASSERT_LINE);
693                  break;
694
695               default:
696                  logerror("SC-01 control mode invalid code 0x%x\n", data);
697                  break;
698            }
699         }
700         else
701         {
702            logerror("SC-01 receiving phonemes 0x%x\n", data & 0x3f);
703         }
704         break;
705
706      case 0x01:
707         logerror("SC-01 inflection changed to 0x%x\n", data);
708         break;
709
710      case 0x02:
711         logerror("SC-01 speech rate changed to 0x%x\n", data);
712         break;
713
714      case 0x03:
715         if (data & 0x80)
716         {
717            m_ssi_control = 1;
718            logerror("SC-01 now in control mode.\n");
719         }
720         else if (data & 0x70)
721         {
722            m_ssi_control = 0;
723            logerror("SC-01 control mode cleared.\n");
724         }
725         else
726         {
727            logerror("SC-01 amplitude manipulated 0x%x.\n", data);
728         }
729         break;
730
731      case 0x04:
732         logerror("SC-01 filter frequency changed to 0x%x.\n", data);
733         break;
734   }
735}
736
737
738/* COP R/W */
739/* All 8 l pins are hooked up here */
740READ8_HANDLER(cop_l_read)
741{
742   logerror("COP - Reading from L @ (0x%x)\n", activecpu_get_pc());
743   return cop_l_latch;
744}
745
746/* Pins g0, g1, g2, and g3 are all hooked up */
747READ8_HANDLER(cop_g_read)
748{
749   logerror("COP - Reading from G @ (0x%x)\n", activecpu_get_pc());
750   return cop_g_latch;
751}
752
753WRITE8_HANDLER(cop_l_write)
754{
755   logerror("COP - WRITING TO L 0x%x @ (0x%x)\n", data, activecpu_get_pc());
756   cop_l_latch = data;
757}
758
759WRITE8_HANDLER(cop_g_write)
760{
761   logerror("COP - WRITING TO G 0x%x @ (0x%x)\n", data, activecpu_get_pc());
762
763   /* Bit 3 goes to an enable pin on the data latch? */
764   /* Bits 0-2 seem to go into the wrong side of a logic IC? */
765}
766
767/* Schematics say pins d0 and d1 are the only two that are hooked up */
768WRITE8_HANDLER(cop_d_write)
769{
770   int irq_flag = 0;
771
772   logerror("COP - WRITING TO D 0x%x @ (0x%x)\n", data, activecpu_get_pc());
773
774   /* Pin d0 - TIMER INT */
775   if (!(data & 0x01))
776   {
777      SET_Z80_TIMER_INT();
778      irq_flag = 1;
779      logerror("THE COP IS TRIPPING THE TIMER INTERRUPT\n");
780   }
781   else
782   {
783      CLEAR_Z80_TIMER_INT();
784   }
785
786   /* Pin d1 - DATA READY INT */
787   if (!(data & 0x02))
788   {
789      SET_Z80_DATA_RDY_INT();
790      irq_flag = 1;
791      logerror("THE COP IS TRIPPING THE DATA READY INTERRUPT\n");
792   }
793   else
794   {
795      CLEAR_Z80_DATA_RDY_INT();
796   }
797
798   /* Assert the Z80's interrupt line if necessary */
799   if (irq_flag)
800   {
801      cpunum_set_input_line(0, 0, ASSERT_LINE);
802   }
803}
804
805WRITE8_HANDLER(cop_sk_write)
806{
807   /* I think this data falls off into a black hole - the pins aren't hooked up.
808       The COP400 XAS instruction writes to both SK and SIO, that's why the CPU writes data here at all. */
809}
810
811WRITE8_HANDLER(cop_sio_write)
812{
813   /* This data is sent to the CLK pin of the keyboard handling logic.  We don't need to emulate it here. */
814}
815
816
817
818/* PROGRAM MAPS */
819static ADDRESS_MAP_START( mainmem, ADDRESS_SPACE_PROGRAM, 8 )
820   AM_RANGE(0x0000, 0x7fff) AM_ROM
821   AM_RANGE(0x8000, 0xbfff) AM_READWRITE(ram_ic_read,ram_ic_write) AM_BASE(&ram_ic)   /* Not quite sure how big the RAM IC is. */
822   AM_RANGE(0xc000, 0xdfff) AM_ROM                                          /* This is what Daphne says - we'll soon see. */
823ADDRESS_MAP_END
824
825static ADDRESS_MAP_START( copmem, ADDRESS_SPACE_PROGRAM, 8 )
826   AM_RANGE(0x000, 0x3ff) AM_ROM                  /* The schematics seem to claim this is a 2716 (0x800 bytes) - is the dump too small? */
827ADDRESS_MAP_END
828
829
830/* IO MAPS */
831static ADDRESS_MAP_START( mainio, ADDRESS_SPACE_IO, 8 )
832   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
833   AM_RANGE(0x00,0x04) AM_WRITE(sc01_register_w)
834   AM_RANGE(0x20,0x20) AM_WRITE(write_cop)
835   AM_RANGE(0x40,0x40) AM_READ(z80_irq_status_r)
836/*  AM_RANGE(0x80,0x80) AM_WRITE(data_write_cop) */
837   AM_RANGE(0xa0,0xa0) AM_WRITE(timer_int_w)
838   AM_RANGE(0xc0,0xc0) AM_WRITE(data_ready_int_w)
839
840/*  AM_RANGE(0xf0,0xf0) */                  /* Laserdisc data read */
841   AM_RANGE(0xf1,0xf1)   AM_READ_PORT("DSWB")   /* 4 dips, 2 coins, Laserdisc 'ready' and 'enter' pins */
842   AM_RANGE(0xf2,0xf2)   AM_READ_PORT("DSWA")   /* 8 dips */
843   AM_RANGE(0xf3,0xf3)   AM_WRITE(intrq_w)      /* goes to /INTRQ */
844/*  AM_RANGE(0xf4,0xf4) */                  /* Laserdisc data write */
845/*  AM_RANGE(0xf5,0xf5) */                  /* Coin counter, 0xf4 write enable, DIP-controlled (SWB-6) LDV1000 'enter' line, and LDV1000 INT/!EXT line */
846/*  AM_RANGE(0xf6,0xf6) */                  /* Scoreboard DEN1 */
847/*  AM_RANGE(0xf7,0xf7) */                  /* Scoreboard DEN2 */
848ADDRESS_MAP_END
849
850static ADDRESS_MAP_START( copio, ADDRESS_SPACE_IO, 8 )
851   AM_RANGE(COP400_PORT_L,  COP400_PORT_L)   AM_READWRITE(cop_l_read,cop_l_write)
852   AM_RANGE(COP400_PORT_G,  COP400_PORT_G)   AM_READWRITE(cop_g_read,cop_g_write)
853   AM_RANGE(COP400_PORT_D,  COP400_PORT_D)   AM_WRITE(cop_d_write)
854   AM_RANGE(COP400_PORT_SK, COP400_PORT_SK)  AM_WRITE(cop_sk_write)
855   AM_RANGE(COP400_PORT_SIO,COP400_PORT_SIO) AM_READWRITE(port_tag_to_handler8("THAYERS_LETTERS"),cop_sio_write)   /* Unemulated in COP40x core, so nothing happens ATM */
856ADDRESS_MAP_END                                                                              /* This is also very wrong.  The keyboard interface needs to
857                                                                                                                       be understood much better than what I have here */
858
859/* PORTS */
860INPUT_PORTS_START( thayers )
861   PORT_START_TAG("DSWA")
862   PORT_DIPNAME( 0x07, 0x07, "Time Per Coin" ) PORT_DIPLOCATION( "A:3,2,1" )
863   PORT_DIPSETTING(    0x07, "110 Seconds" )
864   PORT_DIPSETTING(    0x06, "95 Seconds" )
865   PORT_DIPSETTING(    0x05, "80 Seconds" )
866   PORT_DIPSETTING(    0x04, "70 Seconds" )
867   PORT_DIPSETTING(    0x03, "60 Seconds" )
868   PORT_DIPSETTING(    0x02, "45 Seconds" )
869   PORT_DIPSETTING(    0x01, "30 Seconds" )
870   PORT_DIPSETTING(    0x00, DEF_STR ( Free_Play ) )
871   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Coinage ) ) PORT_DIPLOCATION( "A:4" )
872   PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
873   PORT_DIPSETTING(    0x08, DEF_STR( 1C_1C ) )
874   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Lives ) ) PORT_DIPLOCATION( "A:5" )
875   PORT_DIPSETTING(    0x10, "3" )
876   PORT_DIPSETTING(    0x00, "5" )
877   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION( "A:6" )
878   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
879   PORT_DIPSETTING(    0x20, DEF_STR( On ) )
880   PORT_DIPNAME( 0x40, 0x40, "Attract Mode Audio" ) PORT_DIPLOCATION( "A:7" )
881   PORT_DIPSETTING(    0x40, "Always Playing" )
882   PORT_DIPSETTING(    0x00, "One Out of 8 Times" )
883   PORT_DIPUNUSED_DIPLOC( 0x80, IP_ACTIVE_LOW, "A:8" )
884
885   PORT_START_TAG("DSWB")
886   PORT_DIPNAME( 0x01, 0x01, "Gameplay Mode" ) PORT_DIPLOCATION( "B:1" )
887   PORT_DIPSETTING(    0x01, "Normal Play" )
888   PORT_DIPSETTING(    0x00, "Self-Diagnostics Mode" )
889   PORT_DIPUNUSED_DIPLOC( 0x02, IP_ACTIVE_LOW, "B:2" )
890   PORT_DIPUNUSED_DIPLOC( 0x04, IP_ACTIVE_LOW, "B:3" )
891   PORT_DIPNAME( 0x08, 0x08, "LD Player" ) PORT_DIPLOCATION( "B:4" )
892   PORT_DIPSETTING(    0x08, "LDV-1000" )
893   PORT_DIPSETTING(    0x00, "PR-7820" )
894   /* DIP SWITCH 5 isn't read here, but it also controls LD player selection - I wonder how to add it properly? */
895   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN1 )
896   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN2 )
897   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(laserdisc_command_r, 0 )   /* Enter pin on LD player */
898   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(laserdisc_status_r, 0 )   /* Ready pin on LD player */
899
900   /* The following 3 port definitions can be combined into one (thus making this scheme work) if the port bit limit is raised from 32 to 64 */
901   /* But maybe there's a better way to do it than what I have here? */
902   /* Or maybe this doesn't even work at all :) */
903   /* "Scan codes" heisted from Daphne - need to be tested! */
904   PORT_START_TAG("THAYERS_ACTIONS")
905   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( DEF_STR( No ) ) PORT_CODE( KEYCODE_DEL_PAD )
906   PORT_BIT( 0x31, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( DEF_STR( Yes ) ) PORT_CODE( KEYCODE_0_PAD )
907   PORT_BIT( 0x32, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Items" ) PORT_CODE( KEYCODE_1_PAD )
908   PORT_BIT( 0x33, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Drop Item" ) PORT_CODE( KEYCODE_2_PAD )
909   PORT_BIT( 0x34, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Give Score" ) PORT_CODE( KEYCODE_3_PAD )
910   PORT_BIT( 0x35, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Replay" ) PORT_CODE( KEYCODE_4_PAD )
911   PORT_BIT( 0x36, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Combine Action" ) PORT_CODE( KEYCODE_6_PAD )
912   PORT_BIT( 0x37, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Save Game" ) PORT_CODE( KEYCODE_7_PAD )
913   PORT_BIT( 0x38, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Update" ) PORT_CODE( KEYCODE_8_PAD )
914   PORT_BIT( 0x39, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Hint" ) PORT_CODE( KEYCODE_9_PAD )
915
916   PORT_START_TAG("THAYERS_LETTERS")
917   PORT_BIT( 0x41, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "A" ) PORT_CODE( KEYCODE_A )
918   PORT_BIT( 0x42, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "B - Silver Wheat" ) PORT_CODE( KEYCODE_B )
919   PORT_BIT( 0x43, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "C - Spell of Seeing" ) PORT_CODE( KEYCODE_C )
920   PORT_BIT( 0x44, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "D - Great Circlet" ) PORT_CODE( KEYCODE_D )
921   PORT_BIT( 0x45, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "E - Black Mace" ) PORT_CODE( KEYCODE_E )
922   PORT_BIT( 0x46, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "F - Hunting Horn" ) PORT_CODE( KEYCODE_F )
923   PORT_BIT( 0x47, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "G - Long Bow" ) PORT_CODE( KEYCODE_G )
924   PORT_BIT( 0x48, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "H - Medallion" ) PORT_CODE( KEYCODE_H )
925   PORT_BIT( 0x49, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "I - Crown" ) PORT_CODE( KEYCODE_I )
926   PORT_BIT( 0x4a, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "J - Onyx Seal" ) PORT_CODE( KEYCODE_J )
927   PORT_BIT( 0x4b, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "K - Orb of Quoid" ) PORT_CODE( KEYCODE_K )
928   PORT_BIT( 0x4c, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "L" ) PORT_CODE( KEYCODE_L )
929   PORT_BIT( 0x4d, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "M - Spell of Understanding" ) PORT_CODE( KEYCODE_M )
930   PORT_BIT( 0x4e, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "N - Staff" ) PORT_CODE( KEYCODE_N )
931   PORT_BIT( 0x4f, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "O - Crystal" ) PORT_CODE( KEYCODE_O )
932   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "P" ) PORT_CODE( KEYCODE_P )
933   PORT_BIT( 0x51, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Q" ) PORT_CODE( KEYCODE_Q )
934   PORT_BIT( 0x52, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "R - Blood Sword" ) PORT_CODE( KEYCODE_R )
935   PORT_BIT( 0x53, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "S - Dagger" ) PORT_CODE( KEYCODE_S )
936   PORT_BIT( 0x54, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "T - Chalice" ) PORT_CODE( KEYCODE_T )
937   PORT_BIT( 0x55, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "U - Cold Fire" ) PORT_CODE( KEYCODE_U )
938   PORT_BIT( 0x56, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "V - Shield" ) PORT_CODE( KEYCODE_V )
939   PORT_BIT( 0x57, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "W - Amulet" ) PORT_CODE( KEYCODE_W )
940   PORT_BIT( 0x58, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "X - Scepter" ) PORT_CODE( KEYCODE_X )
941   PORT_BIT( 0x59, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Y - Coins" ) PORT_CODE( KEYCODE_Y )
942   PORT_BIT( 0x5a, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "Z - Spell of Release" ) PORT_CODE( KEYCODE_Z )
943
944   PORT_START_TAG("THAYERS_NUMBERS")
945   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "1 - Clear" ) PORT_CODE( KEYCODE_LCONTROL )
946   PORT_BIT( 0x81, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "2" ) PORT_CODE( KEYCODE_RCONTROL )
947   PORT_BIT( 0x82, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "3 - Enter" ) PORT_CODE( KEYCODE_ENTER )
948   PORT_BIT( 0x83, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME( "4 - Space" ) PORT_CODE( KEYCODE_SPACE )
949INPUT_PORTS_END
950
951
952static MACHINE_START( thayers )
953{
954   discinfo = laserdisc_init(LASERDISC_TYPE_LDV1000, get_disk_handle(0), 0);
955   return;
956}
957
958static INTERRUPT_GEN( vblank_callback_thayers )
959{
960   laserdisc_vsync(discinfo);
961}
962
963
964/* DRIVER */
965static MACHINE_DRIVER_START( thayers )
966/*  main cpu */
967   MDRV_CPU_ADD(Z80, SCHEMATIC_CLOCK)
968   MDRV_CPU_PROGRAM_MAP(mainmem,0)
969   MDRV_CPU_IO_MAP(mainio,0)
970   MDRV_CPU_VBLANK_INT(vblank_callback_thayers, 1)
971
972   MDRV_MACHINE_START(thayers)
973
974/*  io device cpu */
975   MDRV_CPU_ADD(COP420, SCHEMATIC_CLOCK/2/8);      /* Can't read the schematics, but this is what daphne says */
976   MDRV_CPU_PROGRAM_MAP(copmem,0)
977   MDRV_CPU_IO_MAP(copio,0)
978
979/*  video */
980   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
981
982   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
983   MDRV_SCREEN_REFRESH_RATE(60)
984   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
985   MDRV_SCREEN_SIZE(32*10, 32*8)
986   MDRV_SCREEN_VISIBLE_AREA(0*10, 32*10-1, 0*8, 32*8-1)
987
988   MDRV_PALETTE_LENGTH(256)
989   MDRV_VIDEO_UPDATE(thayers)
990
991/*  sound */
992MACHINE_DRIVER_END
993
994
995ROM_START( thayers )
996   ROM_REGION( 0xe000, REGION_CPU1, 0 )
997   ROM_LOAD( "tq_u33.bin", 0x0000, 0x8000, CRC(82df5d89) SHA1(58dfd62bf8c5a55d1eba397d2c284e99a4685a3f) )
998   ROM_LOAD( "tq_u1.bin",  0xc000, 0x2000, CRC(e8e7f566) SHA1(df7b83ef465c65446c8418bc6007447693b75021) )
999
1000   ROM_REGION( 0x400, REGION_CPU2, 0 )
1001   ROM_LOAD( "tq_cop.bin", 0x000, 0x400, CRC(6748e6b3) SHA1(5d7d1ecb57c1501ef6a2d9691eecc9970586606b) )
1002ROM_END
1003
1004ROM_START( thayersa )
1005   ROM_REGION( 0xe000, REGION_CPU1, 0 )
1006   ROM_LOAD( "tq_u33.bin", 0x0000, 0x8000, CRC(82df5d89) SHA1(58dfd62bf8c5a55d1eba397d2c284e99a4685a3f) )
1007   ROM_LOAD( "tq_u1.bin",  0xc000, 0x2000, CRC(33817e25) SHA1(f9750da863dd57fe2f5b6e8fce9c6695dc5c9adc) )
1008
1009   ROM_REGION( 0x400, REGION_CPU2, 0 )
1010   ROM_LOAD( "tq_cop.bin", 0x000, 0x400, CRC(6748e6b3) SHA1(5d7d1ecb57c1501ef6a2d9691eecc9970586606b) )
1011ROM_END
1012
1013static DRIVER_INIT( thayers )
1014{
1015   Z80_IRQ_STATUS_CLEAR();
1016   m_ssi_control = 0;
1017
1018   cop_g_latch = 0xff;
1019}
1020
5101021/*    YEAR  NAME      PARENT   MACHINE  INPUT    INIT     MONITOR  COMPANY               FULLNAME                           FLAGS) */
5111022GAME( 1983, thayers,  0,       thayers, thayers, thayers, ROT0,    "RDI Video Systems",  "Thayer's Quest",                  GAME_NOT_WORKING|GAME_NO_SOUND)
5121023GAME( 1983, thayersa, thayers, thayers, thayers, thayers, ROT0,    "RDI Video Systems",  "Thayer's Quest (Alternate Set)",  GAME_NOT_WORKING|GAME_NO_SOUND)
src/mame/drivers/srmp2.c
r936r937
11951195
11961196***************************************************************************/
11971197
1198/***************************************************************************
1199
1200Super Real Mahjong PI
1201(c)1987 Seta
1202PO-023
1203M6100242A
1204860161517
1205
1206CPU: 68000
1207Sound: AY-3-8910, M5205
1208OSC: 8.000MHz(X1) 20.000MHz(X2)
1209Custom chips: X1-003, X2-003(x3), X1-004(x2), X0-005
1210plus 2 chips covered with heatsink
1211Others: Battery, D8243HC
1212
1213UB0-1.19     [a5960661] 831000
1214UB0-2.17     [b88dbeba]  |
1215UB0-3.18     [6302cfa8] /
1216
1217UB0-4.60     [cb6f7cce]
1218UB0-5.61     [7b48c540]
1219UB0-6.62     [6c891ac5]
1220UB0-7.63     [60a45755]
1221
1222UB0-8.64     [b58024b9] MB83256
1223UB0-9.65     [e28c2566]  |
1224UB0-10.66    [d20a935c]  |
1225UB0-11.67    [30957ca8] /
1226
1227UB1.12       [d2ed93c8] MB7124E
1228UB2.13       [7e7d25f7] /
1229
1230UB-3 (PAL16L8A - not dumped)
1231
1232***************************************************************************/
1233
1234ROM_START( srmp1 )
1235   ROM_REGION( 0x40000, REGION_CPU1, 0 )               /* 68000 Code */
1236   ROM_LOAD16_BYTE( "ub0-2.17", 0x000000, 0x20000, BAD_DUMP CRC(b88dbeba) SHA1(b4120c09aba6b6696148480f55aeee2f4a82b504) )   // 1ST AND 2ND HALF IDENTICAL
1237   ROM_LOAD16_BYTE( "ub0-3.18", 0x000001, 0x20000, BAD_DUMP CRC(6302cfa8) SHA1(214834437c996816e8f63e98f990dc8bce49643a) )   // 1ST AND 2ND HALF IDENTICAL
1238
1239   ROM_REGION( 0x200000, REGION_GFX1, ROMREGION_DISPOSE )   /* Sprites */
1240   ROM_LOAD       ( "ubo-4.60",  0x000000, 0x040000, CRC(cb6f7cce) SHA1(27d7c2f4f998023081fac1bbacfd4b0b56edaee2) )
1241   ROM_LOAD       ( "ubo-5.61",  0x040000, 0x040000, CRC(7b48c540) SHA1(06229caec6846581f95409204ea22f0f76684b08) )
1242   ROM_LOAD16_BYTE( "ub0-8.64",  0x080000, 0x008000, CRC(b58024b9) SHA1(d38750fa90c1b14288884a3c2713b90f0b941bfb) )
1243   ROM_LOAD16_BYTE( "ub0-9.65",  0x080001, 0x008000, CRC(e28c2566) SHA1(91ce9d7138e05f9bcd31dfeaaa558d4431ae9515) )
1244   ROM_LOAD       ( "ubo-6.62",  0x100000, 0x040000, CRC(6c891ac5) SHA1(eab595bce16e4cdc465a5e2e029c3949a0f28629) )
1245   ROM_LOAD       ( "ubo-7.63",  0x140000, 0x040000, CRC(60a45755) SHA1(22bbf024bbe2186b621389a23697e55d512b501a) )
1246   ROM_LOAD16_BYTE( "ub0-10.66", 0x180000, 0x008000, CRC(d20a935c) SHA1(1d01b0ccfb6c2ea226e16e555796acd10b10e835) )
1247   ROM_LOAD16_BYTE( "ub0-11.67", 0x180001, 0x008000, CRC(30957ca8) SHA1(02aaa3f2f266e8f4db2d35c177546365d7836004) )
1248
1249   ROM_REGION( 0x020000, REGION_SOUND1, 0 )            /* Samples */
1250   ROM_LOAD( "ub0-1.19", 0x000000, 0x20000, CRC(a5960661) SHA1(76e7a58276a7ae245bbe266b50cefa7d03043f77) )   // 1ST AND 2ND HALF IDENTICAL
1251
1252   ROM_REGION( 0x800, REGION_PROMS, 0 )               /* Color PROMs */
1253   ROM_LOAD( "ub1.12", 0x000, 0x200, CRC(d2ed93c8) SHA1(334d4fe6fa477758b336b138ffc306e2d6334371) )
1254   ROM_LOAD( "ub2.13", 0x400, 0x200, CRC(7e7d25f7) SHA1(e5bf5071567f95c3bb70347f0b86a9703f9f2e6c) )
1255ROM_END
1256
11981257ROM_START( srmp2 )
11991258   ROM_REGION( 0x040000, REGION_CPU1, 0 )               /* 68000 Code */
12001259   ROM_LOAD16_BYTE( "uco-2.17", 0x000000, 0x020000, CRC(0d6c131f) SHA1(be85f2578b0ae2a072565605b7dbeb970e5e3851) )
r936r937
13221381ROM_END
13231382
13241383
1325GAME( 1987, srmp2,     0,        srmp2,    srmp2,    srmp2,   ROT0, "Seta", "Super Real Mahjong Part 2 (Japan)", 0 )
1326GAME( 1988, srmp3,     0,        srmp3,    srmp3,    srmp3,   ROT0, "Seta", "Super Real Mahjong Part 3 (Japan)", 0 )
1327GAME( 1990, mjyuugi,   0,        mjyuugi,  mjyuugi,  0,       ROT0, "Visco", "Mahjong Yuugi (Japan set 1)", 0 )
1328GAME( 1990, mjyuugia,  mjyuugi,  mjyuugi,  mjyuugi,  0,       ROT0, "Visco", "Mahjong Yuugi (Japan set 2)", 0 )
1384GAME( 1987, srmp1,     0,        srmp2,    srmp2,    0,       ROT0, "Seta",  "Super Real Mahjong Part 1 (Japan)",  GAME_NOT_WORKING )
1385GAME( 1987, srmp2,     0,        srmp2,    srmp2,    srmp2,   ROT0, "Seta",  "Super Real Mahjong Part 2 (Japan)",  0 )
1386GAME( 1988, srmp3,     0,        srmp3,    srmp3,    srmp3,   ROT0, "Seta",  "Super Real Mahjong Part 3 (Japan)",  0 )
1387GAME( 1990, mjyuugi,   0,        mjyuugi,  mjyuugi,  0,       ROT0, "Visco", "Mahjong Yuugi (Japan set 1)",        0 )
1388GAME( 1990, mjyuugia,  mjyuugi,  mjyuugi,  mjyuugi,  0,       ROT0, "Visco", "Mahjong Yuugi (Japan set 2)",        0 )
13291389GAME( 1991, ponchin,   0,        mjyuugi,  ponchin,  0,       ROT0, "Visco", "Mahjong Pon Chin Kan (Japan set 1)", 0 )
13301390GAME( 1991, ponchina,  ponchin,  mjyuugi,  ponchin,  0,       ROT0, "Visco", "Mahjong Pon Chin Kan (Japan set 2)", 0 )
src/mame/drivers/ksys573.c
r936r937
30363036   DISK_IMAGE_READONLY( "706jaa02", 0, MD5(4f096051df039b0d104d4c0fff5dadb8) SHA1(4c8d976096c2da6d01804a44957daf9b50103c90) )
30373037ROM_END
30383038
3039ROM_START( ddrextrm )
3040   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3041   SYS573_BIOS_A
3042
3043   ROM_REGION( 0x0001014, REGION_USER2, 0 ) /* security cart eeprom */
3044   ROM_LOAD( "gcc36ja.u1",   0x000000, 0x001014, BAD_DUMP CRC(c1601287) SHA1(929691a78f7bb6dd830f832f301116df0da1619b) )
3045
3046   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3047   ROM_FILL( 0x0000000, 0x1000000, 0xff )
3048
3049   ROM_REGION( 0x2000000, REGION_USER5, 0 ) /* PCCARD2 */
3050   ROM_FILL( 0x0000000, 0x2000000, 0xff )
3051
3052   ROM_REGION( 0x000008, REGION_USER9, 0 ) /* security cart id */
3053   ROM_LOAD( "gcc36ja.u6",   0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
3054
3055   DISK_REGION( REGION_DISKS )
3056   DISK_IMAGE_READONLY( "c36jaa02", 0, MD5(83fa51031d826d603c0371b18180aeda) SHA1(a1591cb4f1da7e460de57afb17a85592719243e0) )
3057ROM_END
3058
30393059ROM_START( ddru )
30403060   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
30413061   SYS573_BIOS_A
r936r937
30723092   ROM_LOAD( "gc845ja.u1",   0x000000, 0x000224, NO_DUMP )
30733093
30743094   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3075   ROM_LOAD( "gc845ja.31m",  0x000000, 0x200000, NO_DUMP )
3076   ROM_LOAD( "gc845ja.27m",  0x200000, 0x200000, NO_DUMP )
3077   ROM_LOAD( "gc845ja.31l",  0x400000, 0x200000, NO_DUMP )
3078   ROM_LOAD( "gc845ja.27l",  0x600000, 0x200000, NO_DUMP )
3079   ROM_LOAD( "gc845ja.31j",  0x800000, 0x200000, NO_DUMP )
3080   ROM_LOAD( "gc845ja.27j",  0xa00000, 0x200000, NO_DUMP )
3081   ROM_LOAD( "gc845ja.31h",  0xc00000, 0x200000, NO_DUMP )
3082   ROM_LOAD( "gc845ja.27h",  0xe00000, 0x200000, NO_DUMP )
3095   ROM_LOAD( "gc845jaa.31m",  0x000000, 0x200000, NO_DUMP )
3096   ROM_LOAD( "gc845jaa.27m",  0x200000, 0x200000, NO_DUMP )
3097   ROM_LOAD( "gc845jaa.31l",  0x400000, 0x200000, NO_DUMP )
3098   ROM_LOAD( "gc845jaa.27l",  0x600000, 0x200000, NO_DUMP )
3099   ROM_LOAD( "gc845jaa.31j",  0x800000, 0x200000, NO_DUMP )
3100   ROM_LOAD( "gc845jaa.27j",  0xa00000, 0x200000, NO_DUMP )
3101   ROM_LOAD( "gc845jaa.31h",  0xc00000, 0x200000, NO_DUMP )
3102   ROM_LOAD( "gc845jaa.27h",  0xe00000, 0x200000, NO_DUMP )
30833103
30843104   DISK_REGION( REGION_DISKS )
3085   DISK_IMAGE_READONLY( "845jab02", 0, MD5(2ef6cbc2289f9a6b23afa59129a1ac04) SHA1(6ee7f1c576a6248d3bb6833bd3bb500e538d3ade) )
3105   DISK_IMAGE_READONLY( "845jaa02", 0, MD5(045237b7ba76f393f69dd95eae14b61a) SHA1(eb59d00300424be89817ce3f8d7e68b8cf0f7943) )
30863106   DISK_IMAGE_READONLY( "845jaa01", 1, NO_DUMP ) // if this even exists
30873107ROM_END
30883108
3109ROM_START( ddrjb )
3110   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3111   SYS573_BIOS_A
3112
3113   ROM_REGION( 0x0000224, REGION_USER2, 0 ) /* security cart eeprom */
3114   ROM_LOAD( "gc845ja.u1",   0x000000, 0x000224, NO_DUMP )
3115
3116   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3117   ROM_LOAD( "gc845jab.31m",  0x000000, 0x200000, NO_DUMP )
3118   ROM_LOAD( "gc845jab.27m",  0x200000, 0x200000, NO_DUMP )
3119   ROM_LOAD( "gc845jab.31l",  0x400000, 0x200000, NO_DUMP )
3120   ROM_LOAD( "gc845jab.27l",  0x600000, 0x200000, NO_DUMP )
3121   ROM_LOAD( "gc845jab.31j",  0x800000, 0x200000, NO_DUMP )
3122   ROM_LOAD( "gc845jab.27j",  0xa00000, 0x200000, NO_DUMP )
3123   ROM_LOAD( "gc845jab.31h",  0xc00000, 0x200000, NO_DUMP )
3124   ROM_LOAD( "gc845jab.27h",  0xe00000, 0x200000, NO_DUMP )
3125
3126   DISK_REGION( REGION_DISKS )
3127   DISK_IMAGE_READONLY( "845jab02", 0, MD5(ebaaf265a1a7efae93cd745a67ea2cb2) SHA1(10ee3081065ebf5a814abbd30c8dee91b384a849) )
3128   DISK_IMAGE_READONLY( "845jab01", 1, NO_DUMP ) // if this even exists
3129ROM_END
3130
30893131ROM_START( ddra )
30903132   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
30913133   SYS573_BIOS_A
r936r937
31113153   ROM_FILL( 0x0000000, 0x1000000, 0xff )
31123154
31133155   DISK_REGION( REGION_DISKS )
3114   DISK_IMAGE_READONLY( "895ja", 0, BAD_DUMP MD5(2013c3aac0d7fdbae10eadf1aaa8a174) SHA1(03e64fc507d42d3fd6fec288893ec065e4313b00) )
3156   DISK_IMAGE_READONLY( "895jaa02", 0, MD5(f83ea1459c51aba2e16830b775444db3) SHA1(f1d47440ec7ba902f0fc5cad241729613f24fce1) )
31153157ROM_END
31163158
31173159ROM_START( ddr2mc )
r936r937
31263168
31273169   DISK_REGION( REGION_DISKS )
31283170   DISK_IMAGE_READONLY( "896jaa01", 0, MD5(3cab3bc6d9459360da8f6784dd861067) SHA1(cb99e52eac5223509e914648d9b5dec59ed242f8) )
3129   DISK_IMAGE_READONLY( "895ja",    1, BAD_DUMP MD5(2013c3aac0d7fdbae10eadf1aaa8a174) SHA1(03e64fc507d42d3fd6fec288893ec065e4313b00) )
3171   DISK_IMAGE_READONLY( "895jaa02", 1, MD5(f83ea1459c51aba2e16830b775444db3) SHA1(f1d47440ec7ba902f0fc5cad241729613f24fce1) )
31303172ROM_END
31313173
31323174ROM_START( ddr2mc2 )
r936r937
31413183
31423184   DISK_REGION( REGION_DISKS )
31433185   DISK_IMAGE_READONLY( "984jaa01", 0, MD5(945de47f526007f7c607c398b9b6275a) SHA1(da257e5a553a75439970393bdafc581f6971f946) )
3144   DISK_IMAGE_READONLY( "895ja",    1, BAD_DUMP MD5(2013c3aac0d7fdbae10eadf1aaa8a174) SHA1(03e64fc507d42d3fd6fec288893ec065e4313b00) )
3186   DISK_IMAGE_READONLY( "895jaa02", 1, MD5(f83ea1459c51aba2e16830b775444db3) SHA1(f1d47440ec7ba902f0fc5cad241729613f24fce1) )
31453187ROM_END
31463188
31473189ROM_START( ddr2ml )
r936r937
34883530
34893531   DISK_REGION( REGION_DISKS )
34903532   DISK_IMAGE_READONLY( "892jaa01", 0, MD5(b29b63bafdd35f38662ff8daf5fc59f7) SHA1(c929c488d206e055e756ca506c3b1ff430a46aaa) )
3491   DISK_IMAGE_READONLY( "895ja",    1, BAD_DUMP MD5(2013c3aac0d7fdbae10eadf1aaa8a174) SHA1(03e64fc507d42d3fd6fec288893ec065e4313b00) )
3533   DISK_IMAGE_READONLY( "895jaa02", 1, MD5(f83ea1459c51aba2e16830b775444db3) SHA1(f1d47440ec7ba902f0fc5cad241729613f24fce1) )
34923534ROM_END
34933535
34943536ROM_START( ddrs2k )
r936r937
37673809   DISK_IMAGE_READONLY( "c23eaa02", 0, MD5(e7275ba9f53334ac528afaa278df7153) SHA1(661f0b53ab64fc746b8e3b7ff3dd32d2bed852ac) )
37683810ROM_END
37693811
3770ROM_START( dstage )
3812ROM_START( dsfdct )
37713813   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
37723814   SYS573_BIOS_A
37733815
3774   ROM_REGION( 0x0000224, REGION_USER2, 0 ) /* security cart eeprom */
3775   ROM_LOAD( "gn845ea.u1",   0x000000, 0x000224, BAD_DUMP CRC(db643af7) SHA1(881221da640b883302e657b906ea0a4e74555679) )
3816   ROM_REGION( 0x0000084, REGION_USER2, 0 ) /* install security cart eeprom */
3817   ROM_LOAD( "ge887ja_gn887ja.u1",   0x000000, 0x000084, BAD_DUMP CRC(08a60147) SHA1(0d39dca5e9e17fff0e64f296c8416e4ca23fdc1b) )
37763818
3819   ROM_REGION( 0x0000084, REGION_USER8, 0 ) /* game security cart eeprom */
3820   ROM_LOAD( "gc910jc.u1",   0x000000, 0x000084, BAD_DUMP CRC(3c1ca973) SHA1(32211a72e3ac88b2723f82dac0b26f93031b3a9c) )
3821
37773822   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
37783823   ROM_FILL( 0x0000000, 0x1000000, 0xff )
37793824
3825   ROM_REGION( 0x2000000, REGION_USER5, 0 ) /* PCCARD2 */
3826   ROM_FILL( 0x0000000, 0x2000000, 0xff )
3827
3828   ROM_REGION( 0x000008, REGION_USER9, 0 ) /* install security cart id */
3829   ROM_LOAD( "ge887ja_gn887ja.u6",   0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
3830
3831   ROM_REGION( 0x000008, REGION_USER10, 0 ) /* game security cart id */
3832   ROM_LOAD( "gc910jc.u6",   0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
3833
37803834   DISK_REGION( REGION_DISKS )
3781   DISK_IMAGE_READONLY( "845ea", 0, BAD_DUMP MD5(32d52ee2b37559d7413788c87085f37c) SHA1(e82610e1a34fba144499f9ee892ac882d1e96853) )
3835   DISK_IMAGE_READONLY( "910jca02", 0, MD5(c909982a234dbd59388892bd627a466e) SHA1(687ce1d480eb13e78289171b6c56fd5b1e7d5d9e) )
37823836ROM_END
37833837
3838ROM_START( dsfdcta )
3839   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3840   SYS573_BIOS_A
3841
3842   ROM_REGION( 0x0000084, REGION_USER2, 0 ) /* install security cart eeprom */
3843   ROM_LOAD( "gn884ja.u1",  0x000000, 0x000084, BAD_DUMP CRC(ce6b98ce) SHA1(75549d9470345ce06d2706d373b19416d97e5b9a) )
3844
3845   ROM_REGION( 0x0000084, REGION_USER8, 0 ) /* game security cart eeprom */
3846   ROM_LOAD( "gc910ja.u1",   0x000000, 0x000084, BAD_DUMP CRC(59a23808) SHA1(fcff1c68ff6cfbd391ac997a40fb5253fc62de82) )
3847
3848   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3849   ROM_FILL( 0x0000000, 0x1000000, 0xff )
3850
3851   ROM_REGION( 0x2000000, REGION_USER5, 0 ) /* PCCARD2 */
3852   ROM_FILL( 0x0000000, 0x2000000, 0xff )
3853
3854   ROM_REGION( 0x000008, REGION_USER9, 0 ) /* install security cart id */
3855   ROM_LOAD( "gn884ja.u6",  0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
3856
3857   ROM_REGION( 0x000008, REGION_USER10, 0 ) /* game security cart id */
3858   ROM_LOAD( "gc910ja.u6",   0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
3859
3860   DISK_REGION( REGION_DISKS )
3861   DISK_IMAGE_READONLY( "910jaa02", 0, MD5(e5380280b5cbb10822391f74866f8bee) SHA1(3d17320f56be7edb1be6b1bd53269d452f71123d) )
3862ROM_END
3863
37843864ROM_START( dsftkd )
37853865   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
37863866   SYS573_BIOS_A
r936r937
37983878   DISK_IMAGE_READONLY( "884jaa02", 0, MD5(d73444ab74efb8587c2bf455e3ec0d13) SHA1(92522380b92333b10d401fda4f81592073f3e601) )
37993879ROM_END
38003880
3881ROM_START( dstage )
3882   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3883   SYS573_BIOS_A
3884
3885   ROM_REGION( 0x0000224, REGION_USER2, 0 ) /* security cart eeprom */
3886   ROM_LOAD( "gn845ea.u1",   0x000000, 0x000224, BAD_DUMP CRC(db643af7) SHA1(881221da640b883302e657b906ea0a4e74555679) )
3887
3888   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3889   ROM_FILL( 0x0000000, 0x1000000, 0xff )
3890
3891   DISK_REGION( REGION_DISKS )
3892   DISK_IMAGE_READONLY( "845ea", 0, BAD_DUMP MD5(32d52ee2b37559d7413788c87085f37c) SHA1(e82610e1a34fba144499f9ee892ac882d1e96853) )
3893ROM_END
3894
38013895ROM_START( fbait2bc )
38023896   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
38033897   SYS573_BIOS_A
r936r937
42114305GAME( 1999, dstage,   sys573,   konami573, ddr,       ddr,        ROT0, "Konami", "Dancing Stage (GN845 VER. EAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42124306GAME( 1999, ddru,     dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution (GN845 VER. UAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42134307GAME( 1998, ddrj,     dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution - Internet Ranking Ver (GC845 VER. JBA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4214GAME( 1998, ddrja,    dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution (GC845 VER. JAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4308GAME( 1998, ddrja,    dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution (GC845 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4309GAME( 1998, ddrjb,    dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution (GC845 VER. JAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
42154310GAME( 1999, ddra,     dstage,   konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution (GN845 VER. AAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42164311GAME( 1998, fbait2bc, sys573,   konami573, fbaitbc,   ge765pwbba, ROT0, "Konami", "Fisherman's Bait 2 - A Bass Challenge (GE865 VER. UAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42174312GAME( 1999, drmn,     sys573,   konami573, drmn,      drmn,       ROT0, "Konami", "DrumMania (GQ881 VER. JAD)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
r936r937
42304325GAME( 1999, ddr2mc2,  ddr2m,    konami573, ddr,       ddr,        ROT0, "Konami", "Dance Dance Revolution 2nd Mix with beatmaniaIIDX substream CLUB VERSiON 2 (GE984 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42314326GAME( 1999, gtrfrk2m, sys573,   konami573, gtrfrks,   gtrfrks,    ROT0, "Konami", "Guitar Freaks 2nd Mix Ver 1.01 (GQ883 VER. JAD)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42324327GAME( 1999, dsftkd,   sys573,   konami573, ddr,       ddr,        ROT0, "Konami", "Dancing Stage featuring TRUE KiSS DESTiNATiON (G*884 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4328GAME( 2000, ddr3mk,   sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix - Ver.Korea2 (GN887 VER. KBA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.3 */
4329GAME( 2000, ddr3mka,  ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix - Ver.Korea (GN887 VER. KAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.3 */
4330GAME( 1999, ddr3ma,   ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix (GN887 VER. AAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.1 */
4331GAME( 1999, ddr3mj,   ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix (GN887 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.0 */
42334332GAME( 1999, ddrsbm,   sys573,   konami573, ddrsolo,   ddrsolo,    ROT0, "Konami", "Dance Dance Revolution Solo Bass Mix (GQ894 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
42344333GAME( 1999, ddrs2k,   sys573,   konami573, ddrsolo,   ddrsolo,    ROT0, "Konami", "Dance Dance Revolution Solo 2000 (GC905 VER. AAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.3 */
42354334GAME( 1999, ddrs2kj,  ddrs2k,   konami573, ddrsolo,   ddrsolo,    ROT0, "Konami", "Dance Dance Revolution Solo 2000 (GC905 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.2 */
4335GAME( 1999, dsfdct,   sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dancing Stage featuring Dreams Come True (GC910 VER. JCA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4336GAME( 1999, dsfdcta,  dsfdct,   konami573, ddr,       ddr,        ROT0, "Konami", "Dancing Stage featuring Dreams Come True (GC910 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
42364337GAME( 1999, drmn2m,   sys573,   konami573, drmn,      drmndigital,ROT0, "Konami", "DrumMania 2nd Mix (GE912 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.5 */
4237GAME( 2000, ddr3mk,   sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix - Ver.Korea2 (GN887 VER. KBA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.3 */
4238GAME( 2000, ddr3mka,  ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix - Ver.Korea (GN887 VER. KAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.3 */
4239GAME( 1999, ddr3ma,   ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix (GN887 VER. AAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.1 */
4240GAME( 1999, ddr3mj,   ddr3mk,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 3rd Mix (GN887 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.0 */
42414338GAME( 2000, dncfrks,  sys573,   konami573, dmx,       dmx,        ROT0, "Konami", "Dance Freaks (G*874 VER. KAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.6 */
42424339GAME( 2000, dmx,      dncfrks,  konami573, dmx,       dmx,        ROT0, "Konami", "Dance Maniax (G*874 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.6 */
42434340GAME( 2000, gtrfrk3m, sys573,   konami573, gtrfrks,   gtrfrkdigital,ROT0, "Konami", "Guitar Freaks 3rd Mix (GE949 VER. JAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.4 */
r936r937
42614358GAME( 2001, ddrmax,   sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "DDR Max - Dance Dance Revolution 6th Mix (G*B19 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.9 */
42624359GAME( 2002, ddrmax2,  sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "DDR Max 2 - Dance Dance Revolution 7th Mix (G*B20 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.9 */
42634360GAME( 2002, dsem2,    sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dancing Stage Euro Mix 2 (G*C23 VER. EAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.95 */
4361GAME( 2002, ddrextrm, sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution Extreme (G*C36 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.95 */
42644362GAME( 2004, gtfrk11m, sys573,   konami573, gtrfrks,   gtrfrkdigital,ROT0, "Konami", "Guitar Freaks 11th Mix (G*D39 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.95 */
src/mame/drivers/legionna.c
r936r937
370370
371371static void protection_hit_jsr(UINT32 work_ram1,UINT32 work_ram2)
372372{
373   static UINT16 x1,y1,x2,y2/*,hit1,hit2*/;
373   int x1,y1,x2,y2/*,hit1,hit2*/;
374374   x1 = (program_read_word(work_ram1+0x8));
375375   y1 = (program_read_word(work_ram1+0x4));
376376   //hit1 = (program_read_word(work_ram1-));//this sprite is attacking
r936r937
382382
383383   if((x1 >= (x2-0x80)) &&
384384      (x1 <= (x2+0x80)) &&
385      (y1 >= (y1-3))  &&
385      (y1 >= (y2-3))  &&
386386      (y1 <= (y2+3)))
387387      hit_check = 0;
388388   else
src/mame/drivers/taitowlf.c
r936r937
5151         UINT8 pen = dp[index++];
5252         if (pen)
5353         {
54            p[i] = gfx->colortable[att & 0xf];
54            p[i] = Machine->remapped_colortable[gfx->color_base + (att & 0xf)];
5555         }
5656         else
5757         {
58            p[i] = gfx->colortable[(att >> 4) & 0x7];
58            p[i] = Machine->remapped_colortable[gfx->color_base  + ((att >> 4) & 0x7)];
5959         }
6060      }
6161   }
src/mame/drivers/lastfght.c
r936r937
1/*
1/*********************************************************************************************************************
22
3  Last Fighting
4  (c) 2000 Subsino
3Last Fighting  (C)2000 Subsino
54
6 Main CPU: H8/3044
5driver by Luca Elia
76
8
97PCB Layout
108----------
119
r936r937
3432|     |       |-------|   | |7032 |                    |
3533|     |     CN2           | |-----|             3V_BATT|
3634|-----|-------------------|----------------------------|
35
3736Notes:
3837      H8/3044 - Subsino re-badged Hitachi H8/3044 HD6433044A22F Microcontroller (QFP100)
3938                The H8/3044 is a H8/3002 with 24bit address bus and has 32k MASKROM and 2k RAM, clock input is 16.000MHz [32/2]
r936r937
6160                V106.U16 - MX27C4000 4MBit DIP32 EPROM; Main Program
6261                V100.U7  - ST M27C801 8MBit DIP32 EPROM; Audio Samples?
6362
64*/
63*********************************************************************************************************************/
6564
6665#include "driver.h"
6766#include "cpu/h83002/h83002.h"
6867
69static int clr_offset=0;
68/***************************************************************************
69                                Video Hardware
70***************************************************************************/
7071
71INPUT_PORTS_START( lastfght )
72INPUT_PORTS_END
72static mame_bitmap *lastfght_bitmap[2];
73static int clr_offset;
74static int lastfght_dest;
7375
7476static VIDEO_START( lastfght )
7577{
78   int i;
79   for (i = 0; i < 2; i++)
80      lastfght_bitmap[i] = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
81
82   colorram = auto_malloc(256*3);
7683}
7784
85
7886static VIDEO_UPDATE( lastfght )
7987{
80   int x,y;
81   int count;
82   static int base = 0;
88#ifdef MAME_DEBUG
89#if 1
90   // gfx roms viewer (toggle with enter, use pgup/down to browse)
91   int x, y, count = 0;
92   static unsigned base = 0;
93   static int view_roms = 0;
94   UINT8 *gfxdata = memory_region( REGION_GFX1 );
95   UINT8 data;
8396
84   fillbitmap( bitmap, get_black_pen(machine), cliprect );
85   fillbitmap( priority_bitmap, 0, cliprect );
97   if ( input_code_pressed_once(KEYCODE_ENTER) )   view_roms ^= 1;
98   if ( view_roms )
99   {
100      if ( input_code_pressed_once(KEYCODE_PGDN) )   base += 512 * 256;
101      if ( input_code_pressed_once(KEYCODE_PGUP) )   base -= 512 * 256;
102      base %= memory_region_length( REGION_GFX1 );
86103
87   if ( input_code_pressed_once(KEYCODE_Z) )
88      base += 512*512;
104      count = base;
89105
90   if ( input_code_pressed_once(KEYCODE_X) )
91      base -= 512*512;
92
93   count = base;
94
95   for (y=0;y<512;y++)
96   {
97      for (x=0;x<512;x++)
106      fillbitmap( bitmap, get_black_pen(machine), cliprect );
107      for ( y = 0 ; y < 256; y++ )
98108      {
99         UINT8 *gfxdata = memory_region( REGION_GFX1 );
100         *BITMAP_ADDR16(bitmap, y, x) = gfxdata[count];
101         count++;
109         for ( x = 0; x < 512; x++ )
110         {
111            data = ( ((count&0xf)==0)&&((count&0x1e00)==0) )? get_white_pen(Machine) : gfxdata[count];   // white grid or data
112            *BITMAP_ADDR16(bitmap, y, x) = data;
113            count++;
114         }
102115      }
116      popmessage("%x",base);
117      return 0;
103118   }
119#endif
120#endif
104121
105   if(input_code_pressed(KEYCODE_Q))
122   copybitmap(bitmap,lastfght_bitmap[lastfght_dest^1],0,0,0,0,&machine->screen[0].visarea,TRANSPARENCY_NONE,0);
123
124   return 0;
125}
126
127// Palette: HMC HM86171 VGA 256 colour RAMDAC
128
129static WRITE16_HANDLER(colordac_w)
130{
131   if (ACCESSING_LSB)
106132   {
107      cpunum_set_input_line(0, 0, PULSE_LINE);
133      colorram[clr_offset] = data;
134      palette_set_color_rgb(Machine, clr_offset/3,
135         pal6bit(colorram[(clr_offset/3)*3+0]),
136         pal6bit(colorram[(clr_offset/3)*3+1]),
137         pal6bit(colorram[(clr_offset/3)*3+2])
138      );
139      clr_offset = (clr_offset+1) % (256*3);
108140   }
109141
110   if(input_code_pressed(KEYCODE_W))
142   if (ACCESSING_MSB)
111143   {
112      cpunum_set_input_line(0, 1, PULSE_LINE);
144      clr_offset = (data>>8) * 3;
113145   }
146}
114147
115   if(input_code_pressed(KEYCODE_E))
148//  Blitter (supports zooming)
149
150static int lastfght_hi, lastfght_sx, lastfght_sx1, lastfght_dsx, lastfght_sy, lastfght_sy1, lastfght_dsy, lastfght_sp, lastfght_sr;
151static int lastfght_x, lastfght_y, lastfght_w, lastfght_h;
152
153// high byte of a 16 bit register
154static WRITE16_HANDLER( lastfght_hi_w )
155{
156   if (ACCESSING_MSB)   logerror("%06x: 600000.b = %02x\n", activecpu_get_pc(),data>>8);
157   if (ACCESSING_LSB)
116158   {
117      cpunum_set_input_line(0, 2, PULSE_LINE);
159      lastfght_hi   =   data << 8;
160      //logerror("%06x: lastfght_hi  = %02x\n", activecpu_get_pc(),data);
118161   }
119
120   if(input_code_pressed(KEYCODE_R))
162}
163// screen x
164static WRITE16_HANDLER( lastfght_x_w )
165{
166   if (ACCESSING_MSB)   logerror("%06x: 800008.b = %02x\n", activecpu_get_pc(),data>>8);
167   if (ACCESSING_LSB)
121168   {
122      cpunum_set_input_line(0, 3, PULSE_LINE);
169      lastfght_x   =   lastfght_hi | data;
170      //logerror("%06x: lastfght_x   = %02x\n", activecpu_get_pc(),data);
123171   }
124
125   if(input_code_pressed(KEYCODE_T))
172}
173// screen y, screen width - 1
174static WRITE16_HANDLER( lastfght_yw_w )
175{
176   if (ACCESSING_MSB)
126177   {
127      cpunum_set_input_line(0, 4, PULSE_LINE);
178      lastfght_y   =   lastfght_hi | (data >> 8);
179      //logerror("%06x: lastfght_y   = %02x\n", activecpu_get_pc(),data>>8);
128180   }
129
130   if(input_code_pressed(KEYCODE_Y))
181   if (ACCESSING_LSB)
131182   {
132      cpunum_set_input_line(0, 5, PULSE_LINE);
183      lastfght_w   =   lastfght_hi | data;
184      //logerror("%06x: lastfght_w   = %02x\n", activecpu_get_pc(),data);
133185   }
134
135   if(input_code_pressed(KEYCODE_U))
186}
187// screen height - 1
188static WRITE16_HANDLER( lastfght_h_w )
189{
190   if (ACCESSING_MSB)
136191   {
137      cpunum_set_input_line(0, 6, PULSE_LINE);
192      lastfght_h   =   lastfght_hi | (data >> 8);
193      //logerror("%06x: lastfght_h   = %02x\n", activecpu_get_pc(),data>>8);
138194   }
139
140   if(input_code_pressed(KEYCODE_I))
195   if (ACCESSING_LSB)   logerror("%06x: 80000d.b = %02x\n", activecpu_get_pc(),data);
196}
197// source delta x << 6, source x << 6
198static WRITE16_HANDLER( lastfght_sx_w )
199{
200   if (ACCESSING_MSB)
141201   {
142      cpunum_set_input_line(0, 7, PULSE_LINE);
202      lastfght_dsx   =   lastfght_hi | (data >> 8);
203      //logerror("%06x: lastfght_dsx = %02x\n", activecpu_get_pc(),data>>8);
143204   }
144   return 0;
205   if (ACCESSING_LSB)
206   {
207      lastfght_sx   =   lastfght_hi | data;
208      //logerror("%06x: lastfght_sx  = %02x\n", activecpu_get_pc(),data);
209   }
145210}
146
147static WRITE16_HANDLER(colordac_w)
211// source y << 6, source y1 << 6
212static WRITE16_HANDLER( lastfght_sy_w )
148213{
149   if(ACCESSING_LSB)
214   if (ACCESSING_MSB)
150215   {
151      colorram[clr_offset]=data;
152      palette_set_color_rgb(Machine,clr_offset/3,pal6bit(colorram[(clr_offset/3)*3]),pal6bit(colorram[(clr_offset/3)*3+1]),pal6bit(colorram[(clr_offset/3)*3+2]));
153      clr_offset=(clr_offset+1)%768;
216      lastfght_sy   =   lastfght_hi | (data >> 8);
217      //logerror("%06x: lastfght_sy  = %02x\n", activecpu_get_pc(),data>>8);
154218   }
155
156   if(ACCESSING_MSB)
219   if (ACCESSING_LSB)
157220   {
158      clr_offset=(data>>8)*3;
221      lastfght_sy1   =   lastfght_hi | data;
222      //logerror("%06x: lastfght_sy1 = %02x\n", activecpu_get_pc(),data);
159223   }
160224}
225// source rom (0x200000 bytes), source page (512x256 bytes)
226static WRITE16_HANDLER( lastfght_sr_w )
227{
228   if (ACCESSING_MSB)
229   {
230      lastfght_sp   =   (lastfght_hi>>8) >> 4;
231      //logerror("%06x: lastfght_sp  = %02x\n", activecpu_get_pc(),data>>8);
232   }
233   if (ACCESSING_LSB)
234   {
235      lastfght_sr   =   data;
236      //logerror("%06x: lastfght_sr  = %02x\n", activecpu_get_pc(),data);
237   }
238}
239// source x1 << 6, source delta y << 6
240static WRITE16_HANDLER( lastfght_sd_w )
241{
242   if (ACCESSING_MSB)
243   {
244      lastfght_sx1   =   lastfght_hi | (data >> 8);
245      //logerror("%06x: lastfght_sx1 = %02x\n", activecpu_get_pc(),data>>8);
246   }
247   if (ACCESSING_LSB)
248   {
249      lastfght_dsy   =   lastfght_hi | data;
250      //logerror("%06x: lastfght_dsy = %02x\n", activecpu_get_pc(),data);
251   }
252}
253// start blit
254static WRITE16_HANDLER( lastfght_blit_w )
255{
256   if (ACCESSING_MSB)
257   {
258      int x,y, addr;
259      UINT8 *gfxdata = memory_region( REGION_GFX1 );
260      mame_bitmap *dest = lastfght_bitmap[lastfght_dest];
161261
262#if 0
263      logerror("%06x: blit x %03x, y %03x, w %03x, h %03x, sx %03x.%02x, sx1 %03x.%02x, dsx %03x.%02x, sy %03x.%02x, sy1 %03x.%02x, dsy %03x.%02x, sp %02x, sr %02x, data %02x\n", activecpu_get_pc(),
264            lastfght_x,lastfght_y,lastfght_w+1,lastfght_h+1,
265            lastfght_sx>>6,lastfght_sx&0x3f,   lastfght_sx1>>6,lastfght_dsx&0x3f,   lastfght_sx1>>6,lastfght_sx1&0x3f,
266            lastfght_sy>>6,lastfght_sy&0x3f,   lastfght_sy1>>6,lastfght_dsy&0x3f,   lastfght_sy1>>6,lastfght_sy1&0x3f,
267            lastfght_sp,lastfght_sr,
268            data>>8   );
269#endif
270
271      for (y = 0; y <= lastfght_h; y++)
272      {
273         for (x = 0; x <= lastfght_w; x++)
274         {
275            addr   =   (( (lastfght_sx + lastfght_sx1 + lastfght_dsx * x) >> 6 ) & 0x1ff) +
276                     (( (lastfght_sy + lastfght_sy1 + lastfght_dsy * y) >> 6 ) & 0xff ) * 0x200 +
277                     lastfght_sp * 0x200 * 0x100 +
278                     lastfght_sr * 0x200000;
279
280            data   =   gfxdata[addr];
281
282            if (data && (lastfght_x + x >= 0) && (lastfght_x + x < 512) && (lastfght_y + y >= 0) && (lastfght_y + y < 256))
283               *BITMAP_ADDR16(dest, lastfght_y + y, lastfght_x + x) = data;
284         }
285      }
286   }
287   if (ACCESSING_LSB)   logerror("%06x: 600007.b = %02x\n", activecpu_get_pc(),data);
288}
289// toggle framebuffer
290static WRITE16_HANDLER( lastfght_dest_w )
291{
292   if (ACCESSING_LSB)   lastfght_dest ^= 1;
293}
294
295static READ16_HANDLER( lastfght_c00000_r )
296{
297   // high byte:
298   // bit 7 = blitter busy
299   // bit 6 = blitter?
300   return 0x4000;
301
302}
303
304static READ16_HANDLER( lastfght_c00002_r )
305{
306   // high byte:
307   // mask 0x1c: from sound?
308   return (mame_rand(Machine) & 0x1c00) | readinputport(0);
309}
310
311static READ16_HANDLER( lastfght_c00004_r )
312{
313   return readinputport(1);
314}
315
316static READ16_HANDLER( lastfght_c00006_r )
317{
318   // low byte:
319   // bit 7 = protection?
320   // bit 5 = blitter?
321   return readinputport(2);
322}
323
324static WRITE16_HANDLER( lastfght_c00006_w )
325{
326   static UINT16 val = 0;
327   COMBINE_DATA(&val);
328//  popmessage("%04x",val);
329}
330
331static READ16_HANDLER( lastfght_sound_r )
332{
333   // low byte:
334   // bit 3
335   return 8;
336}
337
338static WRITE16_HANDLER( lastfght_sound_w )
339{
340   if (ACCESSING_MSB)   logerror("%06x: sound_w msb = %02x\n", activecpu_get_pc(),data>>8);
341   if (ACCESSING_LSB)   logerror("%06x: sound_w lsb = %02x\n", activecpu_get_pc(),data);
342}
343
344/***************************************************************************
345                                Memory Maps
346***************************************************************************/
347
162348static ADDRESS_MAP_START( lastfght_map, ADDRESS_SPACE_PROGRAM, 16 )
163349   ADDRESS_MAP_FLAGS( AMEF_ABITS(24) )
164   AM_RANGE(0x000000, 0x07ffff) AM_ROM AM_REGION(REGION_CPU1, 0)
165   AM_RANGE(0x080000, 0x0fffff) AM_ROM AM_REGION(REGION_CPU1, 0)
166   AM_RANGE(0x200000, 0x20ffff) AM_RAM
167   AM_RANGE(0x600008, 0x600009) AM_WRITE(colordac_w)
168   AM_RANGE(0x800000, 0x80001f) AM_RAM // blitter regs ?
169   AM_RANGE(0xc00000, 0xc0001f) AM_RAM // protection ?
170   AM_RANGE(0xff0000, 0xffffff) AM_RAM
350
351   AM_RANGE( 0x000000, 0x07ffff ) AM_ROM AM_REGION(REGION_CPU1, 0)
352   AM_RANGE( 0x080000, 0x0fffff ) AM_ROM AM_REGION(REGION_CPU1, 0)
353
354   AM_RANGE( 0x200000, 0x20ffff ) AM_RAM AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size)   // battery
355
356   AM_RANGE( 0x600000, 0x600001 ) AM_WRITE( lastfght_hi_w )
357   AM_RANGE( 0x600002, 0x600003 ) AM_READWRITE( lastfght_sound_r, lastfght_sound_w )
358   AM_RANGE( 0x600006, 0x600007 ) AM_WRITE( lastfght_blit_w )
359   AM_RANGE( 0x600008, 0x600009 ) AM_WRITE( colordac_w )
360   AM_RANGE( 0x60000a, 0x60000b ) AM_WRITE( MWA16_NOP )   // colordac?
361
362   AM_RANGE( 0x800000, 0x800001 ) AM_WRITE( lastfght_sx_w )
363   AM_RANGE( 0x800002, 0x800003 ) AM_WRITE( lastfght_sd_w )
364   AM_RANGE( 0x800004, 0x800005 ) AM_WRITE( lastfght_sy_w )
365   AM_RANGE( 0x800006, 0x800007 ) AM_WRITE( lastfght_sr_w )
366   AM_RANGE( 0x800008, 0x800009 ) AM_WRITE( lastfght_x_w )
367   AM_RANGE( 0x80000a, 0x80000b ) AM_WRITE( lastfght_yw_w )
368   AM_RANGE( 0x80000c, 0x80000d ) AM_WRITE( lastfght_h_w )
369
370   AM_RANGE( 0x800014, 0x800015 ) AM_WRITE( lastfght_dest_w )
371
372   AM_RANGE( 0xc00000, 0xc00001 ) AM_READ( lastfght_c00000_r )
373   AM_RANGE( 0xc00002, 0xc00003 ) AM_READ( lastfght_c00002_r )
374   AM_RANGE( 0xc00004, 0xc00005 ) AM_READ( lastfght_c00004_r )
375   AM_RANGE( 0xc00006, 0xc00007 ) AM_READWRITE( lastfght_c00006_r, lastfght_c00006_w )
376
377   AM_RANGE( 0xff0000, 0xffffff ) AM_RAM
171378ADDRESS_MAP_END
172379
380
381/***************************************************************************
382                                Input Ports
383***************************************************************************/
384
385INPUT_PORTS_START( lastfght )
386   PORT_START   // IN0 - c00002&3
387   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE1      )
388   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN      )
389   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_OTHER         ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F1)
390   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN      )
391   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )
392   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN      )
393   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE      )
394   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
395
396   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN      )
397   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN      )
398   PORT_BIT( 0x0400, IP_ACTIVE_HIGH,IPT_SPECIAL      )
399   PORT_BIT( 0x0800, IP_ACTIVE_HIGH,IPT_SPECIAL      )
400   PORT_BIT( 0x1000, IP_ACTIVE_HIGH,IPT_SPECIAL      )
401   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
402   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
403   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
404
405   PORT_START   // IN1 - c00004&5
406   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON1      )
407   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON2      )
408   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN      )
409   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_UP   )
410   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )
411   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_START1         )
412   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
413   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN   )
414
415   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT   )
416   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT   )
417   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT   ) PORT_PLAYER(2)
418   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
419   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
420   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
421   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_COIN1         )
422   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN2         )
423
424   PORT_START   // IN2 - c00006&7
425   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN      )
426   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN      )
427   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN      )
428   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN      )
429   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )
430   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN      )
431   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
432   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
433
434   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON1      ) PORT_PLAYER(2)
435   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2      ) PORT_PLAYER(2)
436   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNKNOWN      )
437   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_UP   ) PORT_PLAYER(2)
438   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
439   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_START2         )
440   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN      )
441   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN   ) PORT_PLAYER(2)
442INPUT_PORTS_END
443
444
445/***************************************************************************
446                                Machine Drivers
447***************************************************************************/
448
173449static INTERRUPT_GEN( unknown_interrupt )
174450{
175   cpunum_set_input_line(0, cpu_getiloops(), PULSE_LINE);
451   switch (cpu_getiloops())
452   {
453      case 0:
454         cpunum_set_input_line(0, 0, PULSE_LINE);
455         break;
456      default:
457         h8_3002_InterruptRequest(24);
458         break;
459   }
176460}
177461
178
179462static MACHINE_DRIVER_START( lastfght )
180   MDRV_CPU_ADD(H83002, 16000000)
463   MDRV_CPU_ADD(H83002, 32000000/2)
181464   MDRV_CPU_PROGRAM_MAP( lastfght_map, 0 )
182//  MDRV_CPU_VBLANK_INT(unknown_interrupt,6)
465   MDRV_CPU_VBLANK_INT(unknown_interrupt,2)
183466
184   MDRV_SCREEN_REFRESH_RATE( 60 )
185   MDRV_SCREEN_VBLANK_TIME(USEC_TO_SUBSECONDS( 0 ))
467   MDRV_NVRAM_HANDLER(generic_0fill)
186468
469   /* video hardware */
187470   MDRV_VIDEO_ATTRIBUTES( VIDEO_TYPE_RASTER )
188471   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
189   MDRV_SCREEN_SIZE( 512, 512 )
190   MDRV_SCREEN_VISIBLE_AREA( 0, 512-1, 0, 512-1 )
472   MDRV_SCREEN_SIZE( 512, 256 )
473   MDRV_SCREEN_VISIBLE_AREA( 0, 512-1, 0, 256-16-1 )
191474   MDRV_PALETTE_LENGTH( 256 )
475   MDRV_SCREEN_REFRESH_RATE( 60 )
192476
193477   MDRV_VIDEO_START( lastfght )
194478   MDRV_VIDEO_UPDATE( lastfght )
195
196   MDRV_SPEAKER_STANDARD_STEREO("left", "right")
197479MACHINE_DRIVER_END
198480
481
482/***************************************************************************
483                                ROMs Loading
484***************************************************************************/
485
199486ROM_START( lastfght )
200   // H8/3044 program
201   ROM_REGION( 0x100000, REGION_CPU1, 0 )
202   ROM_LOAD( "v106.u16",     0x000000, 0x080000, CRC(7aec89f4) SHA1(7cff00844ad82a0f8d19b1bd07ba3a2bced69d66) )
487   ROM_REGION( 0x100000, REGION_CPU1, 0 )      // H8/3044 program
488   ROM_LOAD( "v106.u16", 0x000000, 0x080000, CRC(7aec89f4) SHA1(7cff00844ad82a0f8d19b1bd07ba3a2bced69d66) )
203489
204   // graphics (512x256? pages)
205   ROM_REGION( 0x800000, REGION_GFX1, 0 )
206   ROM_LOAD( "1.b1",         0x000000, 0x200000, CRC(6c438136) SHA1(138934e948bbd6bd80f354f037badedef6cd8cb1) )
207   ROM_LOAD( "2.b2",         0x200000, 0x200000, CRC(9710bcff) SHA1(0291385489a065ed895c99ae7197fdeac0a0e2a0) )
208   ROM_LOAD( "3.b3",         0x400000, 0x200000, CRC(4236c79a) SHA1(94f093d12c096d38d1e7278796f6d58e4ba14e2e) )
209   ROM_LOAD( "4.b4",         0x600000, 0x200000, CRC(68153b0f) SHA1(46ddf37d5885f411e0e6de9c7e8969ba3a00f17f) )
490   ROM_REGION( 0x800000, REGION_GFX1, 0 )      // Blitter data
491   ROM_LOAD( "1.b1", 0x000000, 0x200000, CRC(6c438136) SHA1(138934e948bbd6bd80f354f037badedef6cd8cb1) )
492   ROM_LOAD( "2.b2", 0x200000, 0x200000, CRC(9710bcff) SHA1(0291385489a065ed895c99ae7197fdeac0a0e2a0) )
493   ROM_LOAD( "3.b3", 0x400000, 0x200000, CRC(4236c79a) SHA1(94f093d12c096d38d1e7278796f6d58e4ba14e2e) )
494   ROM_LOAD( "4.b4", 0x600000, 0x200000, CRC(68153b0f) SHA1(46ddf37d5885f411e0e6de9c7e8969ba3a00f17f) )
210495
211   // samples?
212   ROM_REGION( 0x100000, REGION_SOUND1, 0 )
213   ROM_LOAD( "v100.u7",      0x000000, 0x100000, CRC(c134378c) SHA1(999c75f3a7890421cfd904a926ca377ee43a6825) )
496   ROM_REGION( 0x100000, REGION_SOUND1, 0 )   // Samples
497   ROM_LOAD( "v100.u7", 0x000000, 0x100000, CRC(c134378c) SHA1(999c75f3a7890421cfd904a926ca377ee43a6825) )
214498ROM_END
215499
216500static DRIVER_INIT(lastfght)
217501{
218   colorram=auto_malloc(768);
502   UINT16 *rom = (UINT16*)memory_region(REGION_CPU1);
219503
220   // remove comment to pass initial check (protection ? hw?)
221   // memory_region(REGION_CPU1)[0x00355]=0x40;
504   // pass initial check (protection ? hw?)
505   rom[0x00354/2] = 0x403e;
506
507   // rts -> rte
508   rom[0x01b86/2] = 0x5670;
222509}
223510
224GAME(2000, lastfght, 0, lastfght, lastfght, lastfght, ROT0, "Subsino", "Last Fighting", GAME_NOT_WORKING|GAME_NO_SOUND)
511GAME(2000, lastfght, 0, lastfght, lastfght, lastfght, ROT0, "Subsino", "Last Fighting", GAME_NO_SOUND)
src/mame/drivers/wilytowr.c
r936r937
226226
227227static WRITE8_HANDLER( snddata_w )
228228{
229   int num_ays = (sndti_to_sndnum(SOUND_AY8910, 1) != -1) ? 2 : 1;
229   int num_ays = (sndti_exists(SOUND_AY8910, 1)) ? 2 : 1;
230230   if ((p2 & 0xf0) == 0xe0)
231231      AY8910_control_port_0_w(0,offset);
232232   else if ((p2 & 0xf0) == 0xa0)
src/mame/drivers/bishjan.c
r0r937
1/*********************************************************************************************************************
2
3Bishou Jan (Laugh World)  (C)1999 Subsino
4
5driver by Luca Elia
6
7PCB Layout
8----------
9
10|------------------------------------------------------|
11|TDA1519A           28-WAY                             |
12|     VOL                                              |
13|                HM86171                       ULN2003 |
14|   LM324                                              |
15|           S-1                                ULN2003 |
16|                                                      |
17|                                   |-------|  DSW1(8) |
18|                       |-------|   |SUBSINO|          |
19|            2-V201.U9  |SUBSINO|   |SS9802 |          |
20|                       |SS9904 |   |       |          |
21|                       |       |   |-------|          |
22|                       |-------|                      |
23|                                                      |
24|                         44.1MHz             CXK58257 |
25|  3-V201.U25                                          |
26|                                  1-V203.U21          |
27|  4-V201.U26                                       SW1|
28|             |-------|    |-------|   |-----|         |
29|  5-V201.U27 |SUBSINO|    |SUBSINO|   |H8   |         |
30|             |SS9601 |    |SS9803 |   |3044 |         |
31|  6-V201.U28 |       |    |       |   |-----|         |
32|             |-------|    |-------|                   |
33|          62256  62256   BATTERY                      |
34|------------------------------------------------------|
35Notes:
36      H8/3044 - Subsino re-badged Hitachi H8/3044 HD6433044A22F Microcontroller (QFP100)
37                The H8/3044 is a H8/3002 with 24bit address bus and has 32k MASKROM and 2k RAM, clock input is 14.7MHz [44.1/3]
38                MD0,MD1 & MD2 are configured to MODE 6 16MByte Expanded Mode with the on-chip 32k MASKROM enabled.
39     CXK58257 - Sony CXK58257 32k x8 SRAM (SOP28)
40      HM86171 - Hualon Microelectronics HMC HM86171 VGA 256 colour RAMDAC (DIP28)
41          S-1 - ?? Probably some kind of audio OP AMP or DAC? (DIP8)
42          SW1 - Push Button Test Switch
43        HSync - 15.75kHz
44        VSync - 60Hz
45
46*********************************************************************************************************************/
47
48#include "driver.h"
49#include "cpu/h83002/h83002.h"
50
51/***************************************************************************
52                                Video Hardware
53***************************************************************************/
54
55static int clr_offset;
56
57static UINT16 *bishjan_scroll, *bishjan_layers;
58
59static UINT16   *bishjan_videoram1,   *bishjan_videoram2;
60static tilemap   *tmap1,            *tmap2;
61
62static TILE_GET_INFO( get_tile_info1 )   {   SET_TILE_INFO(0, bishjan_videoram1[ tile_index ], 0, 0);   }
63static TILE_GET_INFO( get_tile_info2 )   {   SET_TILE_INFO(0, bishjan_videoram2[ tile_index ], 0, 0);   }
64
65VIDEO_START(bishjan)
66{
67   tmap1 = tilemap_create(   get_tile_info1, tilemap_scan_rows,
68                     TILEMAP_TYPE_PEN, 8,8, 0x80,0x40   );
69
70   tmap2 = tilemap_create(   get_tile_info2, tilemap_scan_rows,
71                     TILEMAP_TYPE_PEN, 8,8, 0x80,0x40   );
72
73   tilemap_set_transparent_pen(tmap1, 0);
74   tilemap_set_transparent_pen(tmap2, 0);
75
76   bishjan_videoram1 = (UINT16*)auto_malloc(sizeof(UINT16) * 0x80 * 0x40);
77   bishjan_videoram2 = (UINT16*)auto_malloc(sizeof(UINT16) * 0x80 * 0x40);
78
79   colorram = auto_malloc(256*3);
80}
81
82VIDEO_UPDATE( bishjan )
83{
84   int layers_ctrl = ~bishjan_layers[0];
85
86   int scroll1_x = ((bishjan_scroll[1] & 0x0f00)>>0) | (bishjan_scroll[0] >> 8);
87   int scroll1_y = ((bishjan_scroll[1] & 0xf000)>>4) | (bishjan_scroll[0] & 0xff);
88
89   int scroll2_x = ((bishjan_scroll[2] & 0x0f)<<8) | (bishjan_scroll[1] & 0xff);
90   int scroll2_y = ((bishjan_scroll[2] & 0xf0)<<4) | (bishjan_scroll[2] >> 8);
91
92#ifdef MAME_DEBUG
93if (input_code_pressed(KEYCODE_Z))
94{
95   int msk = 0;
96   if (input_code_pressed(KEYCODE_Q))   msk |= 1;
97   if (input_code_pressed(KEYCODE_W))   msk |= 2;
98   if (msk != 0) layers_ctrl &= msk;
99}
100#endif
101
102   scroll1_y += 1;
103   scroll2_y += 1;
104
105   tilemap_set_scrollx( tmap1, 0, scroll1_x);   tilemap_set_scrolly( tmap1, 0, scroll1_y );
106   tilemap_set_scrollx( tmap2, 0, scroll2_x);   tilemap_set_scrolly( tmap2, 0, scroll2_y );
107
108   fillbitmap(bitmap,get_black_pen(machine),cliprect);
109
110   if (layers_ctrl & 1)   tilemap_draw(bitmap,cliprect, tmap1, 0, 0);
111   if (layers_ctrl & 2)   tilemap_draw(bitmap,cliprect, tmap2, 0, 0);
112
113//  popmessage("23: %03x,%03x - %03x,%03x LY: %02x", scroll1_x,scroll1_y, scroll2_x,scroll2_y, (int)*bishjan_layers);
114
115   return 0;
116}
117
118// Palette: HMC HM86171 VGA 256 colour RAMDAC
119
120static WRITE16_HANDLER(colordac_w)
121{
122   if (ACCESSING_LSB)
123   {
124      colorram[clr_offset] = data;
125      palette_set_color_rgb(Machine, clr_offset/3,
126         pal6bit(colorram[(clr_offset/3)*3+0]),
127         pal6bit(colorram[(clr_offset/3)*3+1]),
128         pal6bit(colorram[(clr_offset/3)*3+2])
129      );
130      clr_offset = (clr_offset+1) % (256*3);
131   }
132
133   if (ACCESSING_MSB)
134   {
135      clr_offset = (data>>8) * 3;
136   }
137}
138
139// Tilemaps
140
141static UINT16 bishjan_low;
142
143static WRITE16_HANDLER( bishjan_low_w )
144{
145   if (ACCESSING_MSB)   bishjan_low = data >> 8;
146}
147
148static WRITE16_HANDLER( bishjan_tmap1_w )
149{
150   if (ACCESSING_MSB)
151   {
152      bishjan_videoram1[offset*2] = data | bishjan_low;
153      tilemap_mark_tile_dirty(tmap1, offset*2);
154   }
155   if (ACCESSING_LSB)
156   {
157      bishjan_videoram1[offset*2+1] = (data << 8) | bishjan_low;
158      tilemap_mark_tile_dirty(tmap1, offset*2+1);
159   }
160}
161static WRITE16_HANDLER( bishjan_tmap2_w )
162{
163   if (ACCESSING_MSB)
164   {
165      bishjan_videoram2[offset*2] = data | bishjan_low;
166      tilemap_mark_tile_dirty(tmap2, offset*2);
167   }
168   if (ACCESSING_LSB)
169   {
170      bishjan_videoram2[offset*2+1] = (data << 8) | bishjan_low;
171      tilemap_mark_tile_dirty(tmap2, offset*2+1);
172   }
173}
174
175static READ16_HANDLER( bishjan_tmap1_lo_r )
176{
177   return (bishjan_videoram1[offset*2+0] << 8) | (bishjan_videoram1[offset*2+1] & 0x00ff);
178}
179static READ16_HANDLER( bishjan_tmap1_hi_r )
180{
181   return (bishjan_videoram1[offset*2+0] & 0xff00) | (bishjan_videoram1[offset*2+1] >> 8);
182}
183
184static READ16_HANDLER( bishjan_tmap2_lo_r )
185{
186   return (bishjan_videoram2[offset*2+0] << 8) | (bishjan_videoram2[offset*2+1] & 0x00ff);
187}
188static READ16_HANDLER( bishjan_tmap2_hi_r )
189{
190   return (bishjan_videoram2[offset*2+0] & 0xff00) | (bishjan_videoram2[offset*2+1] >> 8);
191}
192
193// Inputs
194
195static UINT16 bishjan_sel, bishjan_input, bishjan_hopper;
196
197static WRITE16_HANDLER( bishjan_sel_w )
198{
199   if (ACCESSING_MSB)   bishjan_sel = data >> 8;
200}
201
202static READ16_HANDLER( bishjan_unk_r )
203{
204   return
205      (mame_rand(Machine) & 0x9800)   |   // bit 7 eeprom?
206      (((bishjan_sel==0x12) ? 0x40:0x00) << 8) |
207//      (mame_rand() & 0xff);
208//      (((cpu_getcurrentframe()%60)==0)?0x18:0x00);
209      0x18;
210}
211
212static WRITE16_HANDLER( bishjan_input_w )
213{
214   if (ACCESSING_MSB)   bishjan_input = data >> 8;
215}
216
217static READ16_HANDLER( bishjan_input_r )
218{
219   int i;
220   UINT16 res = 0xff;
221
222   for (i = 0; i < 5; i++)
223      if (bishjan_input & (1 << i))
224         res = readinputport(4+i);
225
226   return   (res << 8) |
227         readinputport(3) |
228         ((bishjan_hopper && !(cpu_getcurrentframe()%10)) ? 0x00 : 0x04)   // bit 2: hopper sensor
229   ;
230}
231
232static WRITE16_HANDLER( bishjan_coin_w )
233{
234   if (ACCESSING_LSB)
235   {
236      // coin out         data & 0x01;
237      bishjan_hopper   =   data & 0x02;   // hopper
238      coin_counter_w( 1,   data & 0x10 );
239   }
240}
241
242/***************************************************************************
243                                Memory Maps
244***************************************************************************/
245
246/*
247432000 & 436000 W + lo (80*20=1000)
248412000 & 422000 R (lo & hi)
249416000 & 426000 R (lo & hi)
250
251433000 & 437000 W
252413000 & 423000 R
253417000 & 427000 R
254*/
255
256static ADDRESS_MAP_START( bishjan_map, ADDRESS_SPACE_PROGRAM, 16 )
257   ADDRESS_MAP_FLAGS( AMEF_ABITS(24) )
258
259   AM_RANGE( 0x000000, 0x07ffff ) AM_ROM AM_REGION(REGION_CPU1, 0)
260   AM_RANGE( 0x080000, 0x0fffff ) AM_ROM AM_REGION(REGION_CPU1, 0)
261
262   AM_RANGE( 0x200000, 0x207fff ) AM_RAM AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size)   // battery
263
264   AM_RANGE( 0x412000, 0x412fff ) AM_READ( bishjan_tmap2_lo_r )   //?
265   AM_RANGE( 0x413000, 0x413fff ) AM_READ( MRA16_RAM ) AM_SHARE(1)
266   AM_RANGE( 0x416000, 0x416fff ) AM_READ( bishjan_tmap1_lo_r )   //?
267   AM_RANGE( 0x417000, 0x417fff ) AM_READ( MRA16_RAM ) AM_SHARE(1)
268   AM_RANGE( 0x422000, 0x422fff ) AM_READ( bishjan_tmap2_hi_r )   //?
269   AM_RANGE( 0x423000, 0x423fff ) AM_READ( MRA16_RAM ) AM_SHARE(2)
270   AM_RANGE( 0x426000, 0x426fff ) AM_READ( bishjan_tmap1_hi_r )
271   AM_RANGE( 0x427000, 0x427fff ) AM_READ( MRA16_RAM ) AM_SHARE(2)
272   AM_RANGE( 0x430000, 0x431fff ) AM_WRITE( bishjan_tmap2_w )
273   AM_RANGE( 0x432000, 0x432fff ) AM_WRITE( bishjan_tmap2_w )      //?
274   AM_RANGE( 0x433000, 0x433fff ) AM_WRITE( MWA16_RAM ) AM_SHARE(1)
275   AM_RANGE( 0x434000, 0x435fff ) AM_WRITE( bishjan_tmap1_w )
276   AM_RANGE( 0x436000, 0x436fff ) AM_WRITE( bishjan_tmap1_w )      //?
277   AM_RANGE( 0x437000, 0x437fff ) AM_WRITE( MWA16_RAM ) AM_SHARE(2)
278
279   AM_RANGE( 0x600000, 0x600001 ) AM_READWRITE( MRA16_NOP, bishjan_sel_w )
280   AM_RANGE( 0x600060, 0x600061 ) AM_WRITE( colordac_w )
281   AM_RANGE( 0x600062, 0x600063 ) AM_WRITE( MWA16_NOP )   // ff to 600062
282   AM_RANGE( 0x6000a0, 0x6000a1 ) AM_WRITE( bishjan_low_w )
283
284   AM_RANGE( 0xa0001e, 0xa0001f ) AM_WRITE( MWA16_RAM ) AM_BASE( &bishjan_layers )
285
286   AM_RANGE( 0xa00020, 0xa00025 ) AM_WRITE( MWA16_RAM ) AM_BASE( &bishjan_scroll )
287
288   AM_RANGE( 0xc00000, 0xc00001 ) AM_READ( input_port_1_word_r )   // c00001 sw1
289   AM_RANGE( 0xc00002, 0xc00003 ) AM_READWRITE( input_port_2_word_r, bishjan_input_w )   // in c
290   AM_RANGE( 0xc00004, 0xc00005 ) AM_READ( bishjan_input_r )   // in a & b
291   AM_RANGE( 0xc00006, 0xc00007 ) AM_READ( bishjan_unk_r )      // c00006 in d ($18)
292   AM_RANGE( 0xc00008, 0xc00009 ) AM_READWRITE( input_port_0_word_r, bishjan_coin_w )   // c00009 reset
293ADDRESS_MAP_END
294
295
296/***************************************************************************
297                                Graphics Layout
298***************************************************************************/
299
300static const gfx_layout bishjan_8x8_layout =
301{
302   8,8,
303   RGN_FRAC(1,1),
304   8,
305   { STEP8(0,1) },
306   { STEP8(0,8) },
307   { STEP8(0,8*8) },
308   8*8*8
309};
310
311static const gfx_decode bishjan_gfxdecodeinfo[] =
312{
313   { REGION_GFX1, 0, &bishjan_8x8_layout, 0, 1 },
314   { -1 }
315};
316
317
318/***************************************************************************
319                                Input Ports
320***************************************************************************/
321
322INPUT_PORTS_START( bishjan )
323   PORT_START   // IN0 - Reset
324   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F1)
325
326   PORT_START   // IN1 - DSW(SW1)
327   PORT_DIPNAME( 0x0001, 0x0001, DEF_STR( Controls ) )
328   PORT_DIPSETTING(      0x0001, "Keyboard" )
329   PORT_DIPSETTING(      0x0000, DEF_STR( Joystick ) )
330   PORT_DIPNAME( 0x0002, 0x0002, DEF_STR( Unknown ) )
331   PORT_DIPSETTING(      0x0002, DEF_STR( Off ) )
332   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
333   PORT_DIPNAME( 0x0004, 0x0004, DEF_STR( Unknown ) )
334   PORT_DIPSETTING(      0x0004, DEF_STR( Off ) )
335   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
336   PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ) )
337   PORT_DIPSETTING(      0x0008, DEF_STR( Off ) )
338   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
339   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )
340   PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )
341   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
342   PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )
343   PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
344   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
345   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ) )
346   PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
347   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
348   PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ) )
349   PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
350   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
351
352   PORT_START   // IN2 - C
353   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START1         )   // start (joy)
354   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN   )   // down (joy)
355   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN      )
356   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT   )   // left (joy)
357   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT   )   // right (joy)
358   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON1      )   // n (joy)
359   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_MAHJONG_BET   )   // bet (joy)
360   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON2      )   // select (joy)
361
362   PORT_START   // IN3 - A
363   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN      )
364   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_SERVICE      )   // test
365   PORT_BIT( 0x0004, IP_ACTIVE_HIGH,IPT_SPECIAL      )   // hopper sensor
366   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_SERVICE1      )   // stats
367   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE2      )   // pay out? "hopper empty"
368   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_COIN1         )   PORT_IMPULSE(2)   // coin
369   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE3      )   // pay out? "hopper empty"
370   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_COIN2         )   PORT_IMPULSE(2)   // coin
371
372   PORT_START   // IN4 - B(1)
373   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_A      )   // a
374   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_E      )   // e
375   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_I      )   // i
376   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_M      )   // m
377   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // i2
378   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_START1         )   // b2 (start)
379   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
380   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
381
382   PORT_START   // IN5 - B(2)
383   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_B      )   // b
384   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_F      )   // f
385   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_J      )   // j
386   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_N      )   // n
387   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // l2
388   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_MAHJONG_BET   )   // c2 (bet)
389   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
390   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
391
392   PORT_START   // IN6 - B(3)
393   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_C      )   // c
394   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_G      )   // g
395   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_K      )   // k
396   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // k2
397   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // m2
398   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN      )
399   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
400   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
401
402   PORT_START   // IN7 - B(4)
403   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_D      )   // d
404   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_H      )   // h
405   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_L      )   // l
406   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // j2
407   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )
408   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN      )
409   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
410   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
411
412   PORT_START   // IN8 - B(5)
413   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN      )
414   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // g2
415   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // e2
416   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN      )
417   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // d2
418   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN      )   // f2
419   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN      )
420   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN      )
421INPUT_PORTS_END
422
423
424/***************************************************************************
425                                Machine Drivers
426***************************************************************************/
427
428static INTERRUPT_GEN( bishjan_interrupt )
429{
430   switch (cpu_getiloops())
431   {
432      case 0:
433         cpunum_set_input_line(0, 0, PULSE_LINE);
434         break;
435      default:
436         h8_3002_InterruptRequest(24);
437         break;
438   }
439}
440
441static MACHINE_DRIVER_START( bishjan )
442   MDRV_CPU_ADD(H83002, 44100000/3)
443   MDRV_CPU_PROGRAM_MAP( bishjan_map, 0 )
444   MDRV_CPU_VBLANK_INT(bishjan_interrupt,2)
445
446   MDRV_NVRAM_HANDLER(generic_0fill)
447
448   /* video hardware */
449   MDRV_VIDEO_ATTRIBUTES( VIDEO_TYPE_RASTER )
450   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
451   MDRV_SCREEN_SIZE( 512, 256 )
452   MDRV_SCREEN_VISIBLE_AREA( 0, 512-1, 0, 256-16-1 )
453   MDRV_GFXDECODE(bishjan_gfxdecodeinfo)
454   MDRV_PALETTE_LENGTH( 256 )
455   MDRV_SCREEN_REFRESH_RATE( 60 )
456
457   MDRV_VIDEO_START( bishjan )
458   MDRV_VIDEO_UPDATE( bishjan )
459MACHINE_DRIVER_END
460
461/***************************************************************************
462                                ROMs Loading
463***************************************************************************/
464
465ROM_START( bishjan )
466   ROM_REGION( 0x100000, REGION_CPU1, 0 )      // H8/3044 program
467   ROM_LOAD( "1-v203.u21", 0x000000, 0x080000, CRC(1f891d48) SHA1(0b6a5aa8b781ba8fc133289790419aa8ea21c400) )
468
469   ROM_REGION( 0x400000, REGION_GFX1, 0 )      // Tiles
470   ROM_LOAD32_BYTE( "3-v201.u25", 0x000000, 0x100000, CRC(e013e647) SHA1(a5b0f82f3454393c1ea5e635b0d37735a25e2ea5) )
471   ROM_LOAD32_BYTE( "4-v201.u26", 0x000001, 0x100000, CRC(e0d40ef1) SHA1(95f80889103a7b93080b46387274cb1ffe0c8768) )
472   ROM_LOAD32_BYTE( "5-v201.u27", 0x000002, 0x100000, CRC(85067d40) SHA1(3ecf7851311a77a0dfca90775fcbf6faabe9c2ab) )
473   ROM_LOAD32_BYTE( "6-v201.u28", 0x000003, 0x100000, CRC(430bd9d7) SHA1(dadf5a7eb90cf2dc20f97dbf20a4b6c8e7734fb1) )
474
475   ROM_REGION( 0x100000, REGION_SOUND1, 0 )   // Samples
476   ROM_LOAD( "2-v201.u9", 0x000000, 0x100000, CRC(ea42764d) SHA1(13fe1cd30e474f4b092949c440068e9ddca79976) )
477ROM_END
478
479static DRIVER_INIT(bishjan)
480{
481   UINT16 *rom = (UINT16*)memory_region(REGION_CPU1);
482
483   // check
484   rom[0x042EA/2] = 0x4008;
485
486   // rts -> rte
487   rom[0x33386/2] = 0x5670;
488   rom[0x0CC5C/2] = 0x5670;
489}
490
491GAME(1999, bishjan, 0, bishjan, bishjan, bishjan, ROT0, "Subsino", "Bishou Jan", GAME_NO_SOUND)
src/mame/drivers/equites.c
r936r937
604604   256,
605605   2,
606606   { 0, 4 },
607   { 8*8+3, 8*8+2, 8*8+1, 8*8, 3, 2, 1, 0 },
608   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
607   { STEP4(8*8+3,-1), STEP4(0*8+3,-1) },
608   { STEP8(0*8,8) },
609609   16*8
610610};
611611
r936r937
615615   256,
616616   3,
617617   { 0, 0x4000*8, 0x4000*8+4 },
618   {
619     128*1+3, 128*1+2, 128*1+1, 128*1+0,
620     128*2+3, 128*2+2, 128*2+1, 128*2+0,
621     128*3+3, 128*3+2, 128*3+1, 128*3+0,
622           3,       2,       1,       0
623   },
624   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 },
618   { STEP4(128*1+3,-1), STEP4(128*2+3,-1), STEP4(128*3+3,-1), STEP4(128*0+3,-1) },
619   { STEP16(0,8) },
625620   64*8
626621};
627622
r936r937
631626   256,
632627   3,
633628   { 0, 0x4000*8, 0x4000*8+4 },
634   {
635           3,       2,       1,       0,
636     128*1+3, 128*1+2, 128*1+1, 128*1+0,
637     128*2+3, 128*2+2, 128*2+1, 128*2+0,
638     128*3+3, 128*3+2, 128*3+1, 128*3+0
639   },
640   { 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8 },
629   { STEP4(128*0+3,-1), STEP4(128*1+3,-1), STEP4(128*2+3,-1), STEP4(128*3+3,-1) },
630   { STEP16(1*8,8) },
641631   64*8
642632};
643633
r936r937
658648   512,
659649   2,
660650   { 0, 4 },
661   { 8*8+3, 8*8+2, 8*8+1, 8*8, 3, 2, 1, 0 },
662   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
651   { STEP4(8*8+3,-1), STEP4(0*8+3,-1) },
652   { STEP8(0*8,8) },
663653   16*8
664654};
665655
r936r937
669659   256,
670660   2,
671661   { 0, 4 },
672   {
673     16*8+3, 16*8+2, 16*8+1, 16*8+0,
674     32*8+3, 32*8+2, 32*8+1, 32*8+0,
675     48*8+3, 48*8+2, 48*8+1, 48*8+0,
676          3,      2,      1,      0
677   },
678   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 },
662   { STEP4(16*8+3,-1), STEP4(32*8+3,-1), STEP4(48*8+3,-1), STEP4(0*8+3,-1) },
663   { STEP16(0*8,8) },
679664   64*8
680665};
681666
r936r937
685670   128,
686671   3,
687672   { 0, 0x8000*8, 0x8000*8+4 },
688   {
689     0*8+3, 0*8+2, 0*8+1, 0*8+0, 1*8+3, 1*8+2, 1*8+1, 1*8+0,
690     2*8+3, 2*8+2, 2*8+1, 2*8+0, 3*8+3, 3*8+2, 3*8+1, 3*8+0,
691     4*8+3, 4*8+2, 4*8+1, 4*8+0, 5*8+3, 5*8+2, 5*8+1, 5*8+0,
692     6*8+3, 6*8+2, 6*8+1, 6*8+0, 7*8+3, 7*8+2, 7*8+1, 7*8+0
693   },
694   {
695     0*8*8, 1*8*8, 2*8*8, 3*8*8, 4*8*8, 5*8*8, 6*8*8, 7*8*8,
696     8*8*8, 9*8*8,10*8*8,11*8*8,12*8*8,13*8*8,14*8*8,15*8*8,
697    31*8*8,30*8*8,29*8*8,28*8*8,27*8*8,26*8*8,25*8*8,24*8*8,
698    23*8*8,22*8*8,21*8*8,20*8*8,19*8*8,18*8*8,17*8*8,16*8*8
699   },
673   { STEP4(0*8+3,-1), STEP4(1*8+3,-1), STEP4(2*8+3,-1), STEP4(3*8+3,-1), STEP4(4*8+3,-1), STEP4(5*8+3,-1), STEP4(6*8+3,-1), STEP4(7*8+3,-1) },
674   { STEP16(0*8*8,8*8), STEP16(31*8*8,-8*8) },
700675   8*32*8
701676};
702677
r936r937
727702   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
728703   MDRV_SCREEN_SIZE(256 +BMPAD*2, 256 +BMPAD*2)
729704   MDRV_SCREEN_VISIBLE_AREA(0 +BMPAD, 256-1 +BMPAD, 24 +BMPAD, 232-1 +BMPAD)
730   MDRV_PALETTE_LENGTH(256)
731   MDRV_COLORTABLE_LENGTH(384)
705   MDRV_PALETTE_LENGTH(384)
732706   MDRV_GFXDECODE(equites_gfxdecodeinfo)
733707
734708   MDRV_PALETTE_INIT(equites)
r936r937
756730   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
757731   MDRV_SCREEN_SIZE(256, 256)
758732   MDRV_SCREEN_VISIBLE_AREA(0, 256-1, 64, 256-1)
759   MDRV_PALETTE_LENGTH(256)
760   MDRV_COLORTABLE_LENGTH(1536)
733   MDRV_PALETTE_LENGTH(1536)
761734   MDRV_GFXDECODE(splndrbt_gfxdecodeinfo)
762735
763736   MDRV_PALETTE_INIT(splndrbt)
src/mame/drivers/namcoic.c
r936r937
273273   if (!scalex || !scaley) return;
274274   if (dest_bmp->bpp == 16)
275275   {
276      if( gfx && gfx->colortable )
276      if( gfx )
277277      {
278278         int shadow_offset = (machine->drv->video_attributes&VIDEO_HAS_SHADOWS)?machine->drv->total_colors:0;
279         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
279         const pen_t *pal = &machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
280280         UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
281281         int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
282282         int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
r936r937
15771577      {
15781578         gfx_element *pGfx = allocgfx( &RoadTileLayout );
15791579            decodegfx(pGfx, 0x10000+(UINT8 *)mpRoadRAM, 0, pGfx->total_elements);
1580            pGfx->colortable = &machine->remapped_colortable[0xf00];
1580            pGfx->color_base = 0xf00;
15811581            pGfx->total_colors = 0x3f;
15821582
15831583            machine->gfx[gfxbank] = pGfx;
src/mame/drivers/nwk-tr.c
r936r937
279279
280280   if (machine->drv->color_table_len)
281281   {
282      machine->gfx[K001604_gfx_index[chip][0]]->colortable = machine->remapped_colortable;
283282      machine->gfx[K001604_gfx_index[chip][0]]->total_colors = machine->drv->color_table_len / 16;
284      machine->gfx[K001604_gfx_index[chip][1]]->colortable = machine->remapped_colortable;
285283      machine->gfx[K001604_gfx_index[chip][1]]->total_colors = machine->drv->color_table_len / 16;
286284   }
287285   else
288286   {
289      machine->gfx[K001604_gfx_index[chip][0]]->colortable = machine->pens;
290287      machine->gfx[K001604_gfx_index[chip][0]]->total_colors = machine->drv->total_colors / 16;
291      machine->gfx[K001604_gfx_index[chip][1]]->colortable = machine->pens;
292288      machine->gfx[K001604_gfx_index[chip][1]]->total_colors = machine->drv->total_colors / 16;
293289   }
294290
src/mame/drivers/vulgus.c
r936r937
263263   MDRV_SCREEN_SIZE(32*8, 32*8)
264264   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
265265   MDRV_GFXDECODE(gfxdecodeinfo)
266   MDRV_PALETTE_LENGTH(256)
267   MDRV_COLORTABLE_LENGTH(64*4+16*16+4*32*8)
266   MDRV_PALETTE_LENGTH(64*4+16*16+4*32*8)
268267
269268   MDRV_PALETTE_INIT(vulgus)
270269   MDRV_VIDEO_START(vulgus)
src/mame/drivers/baraduke.c
r936r937
473473
474474
475475
476ROM_START( baraduke )
476ROM_START( aliensec )
477477   ROM_REGION( 0x10000, REGION_CPU1, 0 ) /* 6809 code */
478   ROM_LOAD( "prg1.9c",   0x6000, 0x02000, CRC(ea2ea790) SHA1(ab6f523803b2b0ea04b78f2f252de6c2d344a26c) )
479   ROM_LOAD( "prg2.9a",   0x8000, 0x04000, CRC(9a0a9a87) SHA1(6d88fb5b443c822ede4884d4452e333834b16aca) )
480   ROM_LOAD( "prg3.9b",   0xc000, 0x04000, CRC(383e5458) SHA1(091f25e287f0a81649c9a4fa196ebe4112a82295) )
478   ROM_LOAD( "bd1_3.9c", 0x6000, 0x02000, CRC(ea2ea790) SHA1(ab6f523803b2b0ea04b78f2f252de6c2d344a26c) )
479   ROM_LOAD( "bd2_1.9a", 0x8000, 0x04000, CRC(9a0a9a87) SHA1(6d88fb5b443c822ede4884d4452e333834b16aca) )
480   ROM_LOAD( "bd2_2.9b", 0xc000, 0x04000, CRC(383e5458) SHA1(091f25e287f0a81649c9a4fa196ebe4112a82295) )
481481
482482   ROM_REGION(  0x10000 , REGION_CPU2, 0 ) /* MCU code */
483   ROM_LOAD( "prg4.3b",       0x8000, 0x4000, CRC(abda0fe7) SHA1(f7edcb5f9fa47bb38a8207af5678cf4ccc243547) )   /* subprogram for the MCU */
483   ROM_LOAD( "bd1_4.3b",       0x8000, 0x4000, CRC(abda0fe7) SHA1(f7edcb5f9fa47bb38a8207af5678cf4ccc243547) )   /* subprogram for the MCU */
484484   ROM_LOAD( "cus60-60a1.mcu", 0xf000, 0x1000, CRC(076ea82a) SHA1(22b5e62e26390d7d5cacc0503c7aa5ed524204df) )   /* MCU internal code */
485485
486486   ROM_REGION( 0x02000, REGION_GFX1, ROMREGION_DISPOSE )
487   ROM_LOAD( "ch1.3j",      0x00000, 0x2000, CRC(706b7fee) SHA1(e5694289bd4346c1a3a004feaa940710cea755c6) )   /* characters */
487   ROM_LOAD( "bd1_5.3j", 0x00000, 0x2000, CRC(706b7fee) SHA1(e5694289bd4346c1a3a004feaa940710cea755c6) )   /* characters */
488488
489489   ROM_REGION( 0x10000, REGION_GFX2, ROMREGION_DISPOSE )
490   ROM_LOAD( "ch2.4p",      0x00000, 0x4000, CRC(b0bb0710) SHA1(797832aea59bf80342fd2a3505645f2766bde65b) )   /* tiles */
491   ROM_LOAD( "ch3.4n",      0x04000, 0x4000, CRC(0d7ebec9) SHA1(6b86b476db61f5760bc8610b51adc1115cfdad96) )
492   ROM_LOAD( "ch4.4m",      0x08000, 0x4000, CRC(e5da0896) SHA1(abb8bf7e9dc1c60bc0a20a691109fb145bb1d8e0) )
490   ROM_LOAD( "bd2_8.4p", 0x00000, 0x4000, CRC(432bd7d9) SHA1(876e071b514864d434ab49002c5432f9c88665c1) )   /* tiles */
491   ROM_LOAD( "bd1_7.4n", 0x04000, 0x4000, CRC(0d7ebec9) SHA1(6b86b476db61f5760bc8610b51adc1115cfdad96) )
492   ROM_LOAD( "bd2_6.4m", 0x08000, 0x4000, CRC(f4c1df60) SHA1(8a3a6682884b227fe4293adb09624a4389ee660d) )
493493   /* 0xc000-0xffff  will be unpacked from 0x8000-0xbfff */
494494
495495   ROM_REGION( 0x10000, REGION_GFX3, ROMREGION_DISPOSE )
496   ROM_LOAD( "obj1.8k",   0x00000, 0x4000, CRC(87a29acc) SHA1(3aa00efc95d1da50f6e4637d101640328287dea1) )   /* sprites */
497   ROM_LOAD( "obj2.8l",   0x04000, 0x4000, CRC(72b6d20c) SHA1(e40b48dacefce4fd62ab28d3e6ff3932d4ff005b) )
498   ROM_LOAD( "obj3.8m",   0x08000, 0x4000, CRC(3076af9c) SHA1(57ce09b298fd0bae94e4d8c817a34ce812c3ddfc) )
499   ROM_LOAD( "obj4.8n",   0x0c000, 0x4000, CRC(8b4c09a3) SHA1(46e0ef39cb313c6780f6137769153dc4a054c77f) )
496   ROM_LOAD( "bd1_9.8k",  0x00000, 0x4000, CRC(87a29acc) SHA1(3aa00efc95d1da50f6e4637d101640328287dea1) )   /* sprites */
497   ROM_LOAD( "bd1_10.8l", 0x04000, 0x4000, CRC(72b6d20c) SHA1(e40b48dacefce4fd62ab28d3e6ff3932d4ff005b) )
498   ROM_LOAD( "bd1_11.8m", 0x08000, 0x4000, CRC(3076af9c) SHA1(57ce09b298fd0bae94e4d8c817a34ce812c3ddfc) )
499   ROM_LOAD( "bd1_12.8n", 0x0c000, 0x4000, CRC(8b4c09a3) SHA1(46e0ef39cb313c6780f6137769153dc4a054c77f) )
500500
501501   ROM_REGION( 0x1000, REGION_PROMS, 0 )
502   ROM_LOAD( "prmcolbg.1n",0x0000, 0x0800, CRC(0d78ebc6) SHA1(0a0c1e23eb4d1748c4e6c448284d785286c77911) )   /* Blue + Green palette */
503   ROM_LOAD( "prmcolr.2m",   0x0800, 0x0800, CRC(03f7241f) SHA1(16ae059f084ba0ac4ddaa95dbeed113295f106ea) )   /* Red palette */
502   ROM_LOAD( "bd1-1.1n", 0x0000, 0x0800, CRC(0d78ebc6) SHA1(0a0c1e23eb4d1748c4e6c448284d785286c77911) )   /* Blue + Green palette (prom type mb7138e) */
503   ROM_LOAD( "bd1-2.2m", 0x0800, 0x0800, CRC(03f7241f) SHA1(16ae059f084ba0ac4ddaa95dbeed113295f106ea) )   /* Red palette (prom type mb7128e) */
504504ROM_END
505505
506ROM_START( baraduka )
506ROM_START( baraduke )
507507   ROM_REGION( 0x10000, REGION_CPU1, 0 ) /* 6809 code */
508   ROM_LOAD( "prg1.9c",   0x6000, 0x02000, CRC(ea2ea790) SHA1(ab6f523803b2b0ea04b78f2f252de6c2d344a26c) )
509   ROM_LOAD( "bd1_1.9a",   0x8000, 0x04000, CRC(4e9f2bdc) SHA1(bc6e71d4d3b2064e662a105c1a77d2731070d58e) )
510   ROM_LOAD( "bd1_2.9b",   0xc000, 0x04000, CRC(40617fcd) SHA1(51d17f3a2fc96e13c8ef5952efece526e0fb33f4) )
508   ROM_LOAD( "bd1_3.9c", 0x6000, 0x02000, CRC(ea2ea790) SHA1(ab6f523803b2b0ea04b78f2f252de6c2d344a26c) )
509   ROM_LOAD( "bd1_1.9a", 0x8000, 0x04000, CRC(4e9f2bdc) SHA1(bc6e71d4d3b2064e662a105c1a77d2731070d58e) )
510   ROM_LOAD( "bd1_2.9b", 0xc000, 0x04000, CRC(40617fcd) SHA1(51d17f3a2fc96e13c8ef5952efece526e0fb33f4) )
511511
512512   ROM_REGION(  0x10000 , REGION_CPU2, 0 ) /* MCU code */
513513   ROM_LOAD( "bd1_4b.3b",       0x8000, 0x4000, CRC(a47ecd32) SHA1(a2a75e65deb28224a5729ed134ee4d5ea8c50706) )   /* subprogram for the MCU */
514514   ROM_LOAD( "cus60-60a1.mcu", 0xf000, 0x1000, CRC(076ea82a) SHA1(22b5e62e26390d7d5cacc0503c7aa5ed524204df) )   /* MCU internal code */
515515
516516   ROM_REGION( 0x02000, REGION_GFX1, ROMREGION_DISPOSE )
517   ROM_LOAD( "ch1.3j",      0x00000, 0x2000, CRC(706b7fee) SHA1(e5694289bd4346c1a3a004feaa940710cea755c6) )   /* characters */
517   ROM_LOAD( "bd1_5.3j", 0x00000, 0x2000, CRC(706b7fee) SHA1(e5694289bd4346c1a3a004feaa940710cea755c6) )   /* characters */
518518
519519   ROM_REGION( 0x10000, REGION_GFX2, ROMREGION_DISPOSE )
520   ROM_LOAD( "ch2.4p",      0x00000, 0x4000, CRC(b0bb0710) SHA1(797832aea59bf80342fd2a3505645f2766bde65b) )   /* tiles */
521   ROM_LOAD( "ch3.4n",      0x04000, 0x4000, CRC(0d7ebec9) SHA1(6b86b476db61f5760bc8610b51adc1115cfdad96) )
522   ROM_LOAD( "ch4.4m",      0x08000, 0x4000, CRC(e5da0896) SHA1(abb8bf7e9dc1c60bc0a20a691109fb145bb1d8e0) )
520   ROM_LOAD( "bd1_8.4p", 0x00000, 0x4000, CRC(b0bb0710) SHA1(797832aea59bf80342fd2a3505645f2766bde65b) )   /* tiles */
521   ROM_LOAD( "bd1_7.4n", 0x04000, 0x4000, CRC(0d7ebec9) SHA1(6b86b476db61f5760bc8610b51adc1115cfdad96) )
522   ROM_LOAD( "bd1_6.4m", 0x08000, 0x4000, CRC(e5da0896) SHA1(abb8bf7e9dc1c60bc0a20a691109fb145bb1d8e0) )
523523   /* 0xc000-0xffff  will be unpacked from 0x8000-0xbfff */
524524
525525   ROM_REGION( 0x10000, REGION_GFX3, ROMREGION_DISPOSE )
526   ROM_LOAD( "obj1.8k",   0x00000, 0x4000, CRC(87a29acc) SHA1(3aa00efc95d1da50f6e4637d101640328287dea1) )   /* sprites */
527   ROM_LOAD( "obj2.8l",   0x04000, 0x4000, CRC(72b6d20c) SHA1(e40b48dacefce4fd62ab28d3e6ff3932d4ff005b) )
528   ROM_LOAD( "obj3.8m",   0x08000, 0x4000, CRC(3076af9c) SHA1(57ce09b298fd0bae94e4d8c817a34ce812c3ddfc) )
529   ROM_LOAD( "obj4.8n",   0x0c000, 0x4000, CRC(8b4c09a3) SHA1(46e0ef39cb313c6780f6137769153dc4a054c77f) )
526   ROM_LOAD( "bd1_9.8k",  0x00000, 0x4000, CRC(87a29acc) SHA1(3aa00efc95d1da50f6e4637d101640328287dea1) )   /* sprites */
527   ROM_LOAD( "bd1_10.8l", 0x04000, 0x4000, CRC(72b6d20c) SHA1(e40b48dacefce4fd62ab28d3e6ff3932d4ff005b) )
528   ROM_LOAD( "bd1_11.8m", 0x08000, 0x4000, CRC(3076af9c) SHA1(57ce09b298fd0bae94e4d8c817a34ce812c3ddfc) )
529   ROM_LOAD( "bd1_12.8n", 0x0c000, 0x4000, CRC(8b4c09a3) SHA1(46e0ef39cb313c6780f6137769153dc4a054c77f) )
530530
531531   ROM_REGION( 0x1000, REGION_PROMS, 0 )
532   ROM_LOAD( "prmcolbg.1n",0x0000, 0x0800, CRC(0d78ebc6) SHA1(0a0c1e23eb4d1748c4e6c448284d785286c77911) )   /* Blue + Green palette */
533   ROM_LOAD( "prmcolr.2m",   0x0800, 0x0800, CRC(03f7241f) SHA1(16ae059f084ba0ac4ddaa95dbeed113295f106ea) )   /* Red palette */
532   ROM_LOAD( "bd1-1.1n", 0x0000, 0x0800, CRC(0d78ebc6) SHA1(0a0c1e23eb4d1748c4e6c448284d785286c77911) )   /* Blue + Green palette (prom type mb7138e) */
533   ROM_LOAD( "bd1-2.2m", 0x0800, 0x0800, CRC(03f7241f) SHA1(16ae059f084ba0ac4ddaa95dbeed113295f106ea) )   /* Red palette (prom type mb7128e) */
534534ROM_END
535535
536536ROM_START( metrocrs )
r936r937
612612
613613GAME( 1985, metrocrs, 0,        baraduke, metrocrs, baraduke, ROT0, "Namco", "Metro-Cross (set 1)", 0 )
614614GAME( 1985, metrocra, metrocrs, baraduke, metrocrs, baraduke, ROT0, "Namco", "Metro-Cross (set 2)", 0 )
615GAME( 1985, baraduke, 0,        baraduke, baraduke, baraduke, ROT0, "Namco", "Baraduke (set 1)", 0 )
616GAME( 1985, baraduka, baraduke, baraduke, baraduke, baraduke, ROT0, "Namco", "Baraduke (set 2)", 0 )
615GAME( 1985, aliensec, 0,        baraduke, baraduke, baraduke, ROT0, "Namco", "Alien Sector", 0 )
616GAME( 1985, baraduke, aliensec, baraduke, baraduke, baraduke, ROT0, "Namco", "Baraduke", 0 )
src/mame/drivers/dec8.c
r936r937
34543454
34553455   sound_cpu = 1;
34563456   /* Oscar has three CPUs */
3457   if (machine->drv->cpu[2].cpu_type != 0) sound_cpu = 2;
3457   if (machine->drv->cpu[2].cpu_type != CPU_DUMMY) sound_cpu = 2;
34583458
34593459   /* bits 5 and 6 of the opcodes are swapped */
34603460   rom = memory_region(REGION_CPU1+sound_cpu);
src/mame/drivers/thepit.c
r936r937
118118#include "sound/ay8910.h"
119119
120120
121#define MASTER_CLOCK      (18432000)
122#define SOUND_CLOCK         (10000000)
123
124#define PIXEL_CLOCK         (MASTER_CLOCK/3)
125
126/* H counts from 128->511, HBLANK starts at 128 and ends at 256 */
127#define HTOTAL            (384)
128#define HBEND            (0)      /*(256)*/
129#define HBSTART            (256)   /*(128)*/
130
131#define VTOTAL            (264)
132#define VBEND            (16)
133#define VBSTART            (224+16)
134
135
136
137
121138extern UINT8 *thepit_videoram;
122139extern UINT8 *thepit_colorram;
123140extern UINT8 *thepit_attributesram;
r936r937
127144PALETTE_INIT( thepit );
128145PALETTE_INIT( suprmous );
129146VIDEO_START( thepit );
130VIDEO_START( intrepid );
131VIDEO_START( suprmous );
132147VIDEO_UPDATE( thepit );
133148WRITE8_HANDLER( thepit_videoram_w );
134149WRITE8_HANDLER( thepit_colorram_w );
r936r937
554569
555570static const gfx_layout thepit_charlayout =
556571{
557   8,8,    /* 8*8 characters */
558   256,    /* 256 characters */
559   2,      /* 2 bits per pixel */
560   { 0x1000*8, 0 }, /* the two bitplanes are separated */
561   { 0, 1, 2, 3, 4, 5, 6, 7 },
562   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
563   8*8     /* every char takes 8 consecutive bytes */
572   8,8,
573   256,
574   2,
575   { 0x1000*8, 0 },
576   { STEP8(0,1) },
577   { STEP8(0,8) },
578   8*8
564579};
565580
566581
567582static const gfx_layout thepit_spritelayout =
568583{
569   16,16,  /* 16*16 sprites */
570   64,     /* 64 sprites */
571   2,      /* 2 bits per pixel */
572   { 0x1000*8, 0 },   /* the two bitplanes are separated */
573   { 0, 1, 2, 3, 4, 5, 6, 7,
574     8*8+0, 8*8+1, 8*8+2, 8*8+3, 8*8+4, 8*8+5, 8*8+6, 8*8+7 },
575   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
576     16*8, 17*8, 18*8, 19*8, 20*8, 21*8, 22*8, 23*8 },
577   32*8    /* every sprite takes 32 consecutive bytes */
584   16,16,
585   64,
586   2,
587   { 0x1000*8, 0 },
588   { STEP8(0,1), STEP8(8*8,1) },
589   { STEP8(0,8), STEP8(16*8,8) },
590   32*8
578591};
579592
580593
581594static const gfx_layout suprmous_charlayout =
582595{
583   8,8,   /* 8*8 characters */
584   256,   /* 256 characters */
585   3,       /* 3 bits per pixel */
586   { 0x2000*8, 0x1000*8, 0 },   /* the three bitplanes for 4 pixels are separated */
587   { 0, 1, 2, 3, 4, 5, 6, 7 },
588   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
589   8*8       /* every char takes 8 consecutive bytes */
596   8,8,
597   256,
598   3,
599   { 0x2000*8, 0x1000*8, 0 },
600   { STEP8(0,1) },
601   { STEP8(0,8) },
602   8*8
590603};
591604
592605
593606static const gfx_layout suprmous_spritelayout =
594607{
595   16,16,   /* 16*16 sprites */
596   64,      /* 64 sprites */
597   3,       /* 3 bits per pixel */
598   { 0x2000*8, 0x1000*8, 0 },   /* the bitplanes are separated */
599   { 0, 1, 2, 3, 4, 5, 6, 7,
600     8*8+0, 8*8+1, 8*8+2, 8*8+3, 8*8+4, 8*8+5, 8*8+6, 8*8+7 },
601   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
602     16*8, 17*8, 18*8, 19*8, 20*8, 21*8, 22*8, 23*8 },
603   32*8   /* every sprite takes 32 consecutive bytes */
608   16,16,
609   64,
610   3,
611   { 0x2000*8, 0x1000*8, 0 },
612   { STEP8(0,1), STEP8(8*8,1) },
613   { STEP8(0,8), STEP8(16*8,8) },
614   32*8
604615};
605616
606617
607618static const gfx_decode thepit_gfxdecodeinfo[] =
608619{
609   { REGION_GFX1, 0, &thepit_charlayout,   0, 8 + 8 },
610   { REGION_GFX1, 0, &thepit_spritelayout, 0, 8 + 8 },
620   { REGION_GFX1, 0, &thepit_charlayout,   0, 8 },
621   { REGION_GFX1, 0, &thepit_spritelayout, 0, 8 },
611622   { -1 }
612623};
613624
614625static const gfx_decode intrepid_gfxdecodeinfo[] =
615626{
616   { REGION_GFX1, 0x0000, &thepit_charlayout,   0, 8 + 8 },
617   { REGION_GFX1, 0x0000, &thepit_spritelayout, 0, 8 + 8 },
618   { REGION_GFX1, 0x0800, &thepit_charlayout,   0, 8 + 8 },
619   { REGION_GFX1, 0x0800, &thepit_spritelayout, 0, 8 + 8 },
627   { REGION_GFX1, 0x0000, &thepit_charlayout,   0, 8 },
628   { REGION_GFX1, 0x0000, &thepit_spritelayout, 0, 8 },
629   { REGION_GFX1, 0x0800, &thepit_charlayout,   0, 8 },
630   { REGION_GFX1, 0x0800, &thepit_spritelayout, 0, 8 },
620631   { -1 }
621632};
622633
623634static const gfx_decode suprmous_gfxdecodeinfo[] =
624635{
625   { REGION_GFX1, 0x0000, &suprmous_charlayout,   0, 4 + 8 },
626   { REGION_GFX1, 0x0800, &suprmous_spritelayout, 0, 4 + 8 },
636   { REGION_GFX1, 0x0000, &suprmous_charlayout,   0, 4 },
637   { REGION_GFX1, 0x0800, &suprmous_spritelayout, 0, 4 },
627638   { -1 }
628639};
629640
r936r937
637648static MACHINE_DRIVER_START( thepit )
638649
639650   /* basic machine hardware */
640   MDRV_CPU_ADD_TAG("main", Z80, 18432000/6)     /* 3.072 MHz */
651   MDRV_CPU_ADD_TAG("main", Z80, PIXEL_CLOCK/2)     /* 3.072 MHz */
641652   MDRV_CPU_PROGRAM_MAP(thepit_main_map,0)
642653   MDRV_CPU_VBLANK_INT(nmi_line_pulse,1)
643654
644   MDRV_CPU_ADD(Z80, 10000000/4)     /* 2.5 MHz */
645   /* audio CPU */
655   MDRV_CPU_ADD(Z80, SOUND_CLOCK/4)     /* 2.5 MHz */
646656   MDRV_CPU_PROGRAM_MAP(audio_map,0)
647657   MDRV_CPU_IO_MAP(audio_io_map,0)
648658   MDRV_CPU_VBLANK_INT(irq0_line_hold,1)
649659
650660   /* video hardware */
651661   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
652   MDRV_VIDEO_START(thepit)
653   MDRV_VIDEO_UPDATE(thepit)
662   MDRV_GFXDECODE(thepit_gfxdecodeinfo)
654663   MDRV_PALETTE_LENGTH(32+8)
655   MDRV_PALETTE_INIT(thepit)
656   MDRV_GFXDECODE(thepit_gfxdecodeinfo)
657   MDRV_COLORTABLE_LENGTH(32+32)
658664
659665   MDRV_SCREEN_ADD("main", 0)
660666   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
661   MDRV_SCREEN_SIZE(32*8, 32*8)
662   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
663   MDRV_SCREEN_REFRESH_RATE(60)
664   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION       /* frames per second, vblank duration */)
667   MDRV_SCREEN_RAW_PARAMS(PIXEL_CLOCK, HTOTAL, HBEND, HBSTART, VTOTAL, VBEND, VBSTART)
665668
669   MDRV_PALETTE_INIT(thepit)
670   MDRV_VIDEO_START(thepit)
671   MDRV_VIDEO_UPDATE(thepit)
672
666673   /* sound hardware */
667674   MDRV_SPEAKER_STANDARD_MONO("mono")
668675
669   MDRV_SOUND_ADD(AY8910, 18432000/12)
676   MDRV_SOUND_ADD(AY8910, PIXEL_CLOCK/4)
670677   MDRV_SOUND_CONFIG(ay8910_interface)
671678   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
672679
673   MDRV_SOUND_ADD(AY8910, 18432000/12)
680   MDRV_SOUND_ADD(AY8910, PIXEL_CLOCK/4)
674681   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
675682MACHINE_DRIVER_END
676683
r936r937
683690   MDRV_CPU_PROGRAM_MAP(intrepid_main_map,0)
684691
685692   /* video hardware */
686   MDRV_VIDEO_START(intrepid)
687693   MDRV_GFXDECODE(intrepid_gfxdecodeinfo)
688694MACHINE_DRIVER_END
689695
r936r937
694700   MDRV_IMPORT_FROM(intrepid)
695701
696702   /* video hardware */
697   MDRV_VIDEO_START(suprmous)
698703   MDRV_PALETTE_INIT(suprmous)
699704   MDRV_GFXDECODE(suprmous_gfxdecodeinfo)
700   MDRV_COLORTABLE_LENGTH(32+64)
701705MACHINE_DRIVER_END
702706
703707
r936r937
968972   ROM_LOAD( "mm7.3d",       0x2000, 0x1000, CRC(a6f60ed2) SHA1(7ce12a10546144ce529d41159b593f1bac9b900b) )
969973
970974   ROM_REGION( 0x0040, REGION_PROMS, 0 )
971   ROM_LOAD( "mmouse2.clr",  0x0000, 0x0020, NO_DUMP )
972   ROM_LOAD( "mmouse1.clr",  0x0020, 0x0020, NO_DUMP )
975   ROM_LOAD( "mm-pr1.1",  0x0000, 0x0020, CRC(e4babc1f) SHA1(a41991baafbb3696ea2724a58c31929882341109) )
976   ROM_LOAD( "mm-pr2.2",  0x0020, 0x0020, CRC(9a4919ed) SHA1(09d59b3943a52868fceef9571ca48b7b2e3b24a4) )
973977ROM_END
974978
975979ROM_START( rtriv )
r936r937
10531057GAME( 1982, portman,  dockman,  intrepid, dockman,  0,     ROT90, "Nova Games Ltd.", "Port Man", 0 )
10541058GAME( 1982, funnymou, 0,        suprmous, suprmous, 0,     ROT90, "Chuo Co. Ltd", "Funny Mouse", 0 )
10551059GAME( 1982, suprmous, funnymou, suprmous, suprmous, 0,     ROT90, "Taito Corporation", "Super Mouse", 0 )
1056GAME( 1982, machomou, 0,        suprmous, suprmous, 0,     ROT90, "Techstar", "Macho Mouse", GAME_WRONG_COLORS )
1060GAME( 1982, machomou, 0,        suprmous, suprmous, 0,     ROT90, "Techstar", "Macho Mouse", 0 )
10571061GAME( 1983, intrepid, 0,        intrepid, intrepid, 0,     ROT90, "Nova Games Ltd.", "Intrepid (set 1)", 0 )
10581062GAME( 1983, intrepi2, intrepid, intrepid, intrepid, 0,     ROT90, "Nova Games Ltd.", "Intrepid (set 2)", 0 )
10591063GAME( 1984, zaryavos, 0,        intrepid, intrepid, 0,     ROT90, "Nova Games of Canada", "Zarya Vostoka", GAME_NOT_WORKING )
src/mame/drivers/royalmah.c
r936r937
1212Sound:  AY-3-8910
1313OSC:    18.432MHz and 8MHz
1414
15-------------------------------------------------------------------------------------------
16Year + Game                 Board           Company             Notes
17-------------------------------------------------------------------------------------------
1882 Royal Mahjong            FRM-03          Falcon
1986 Don Den Mahjong          D039198L-0      Dyna Electronics
2086 Watashiha Suzumechan                     Dyna Electronics
2187 Mahjong Diplomat         D0706088L1-0    Dynax
2287 Mahjong Studio 101       D1708228L1      Dynax
2387 Tonton                   D0908288L1-0    Dynax
2488 Mahjong Almond Pinky     D1401128L-0     Dynax
2589 Mahjong Derringer        D2203018L       Dynax               Larger palette
2690 Mahjong If..?            D29?            Dynax               Larger palette, TLCS-90 CPU
2795 Mahjong Tensinhai        D10010318L1     Dynax               Real Time Clock, TLCS-90 CPU
2896 Janputer '96                             Dynax               Real Time Clock
29-------------------------------------------------------------------------------------------
15----------------------------------------------------------------------------------------------------------
16Year + Game                 Board           CPU        Company             Notes
17----------------------------------------------------------------------------------------------------------
1882 Royal Mahjong            FRM-03          Z80        Falcon
1986 Don Den Mahjong          D039198L-0      Z80        Dyna Electronics
2086 Watashiha Suzumechan                     Z80        Dyna Electronics
2187 Mahjong Diplomat         D0706088L1-0    Z80        Dynax
2287 Mahjong Studio 101       D1708228L1      Z80        Dynax
2387 Tonton                   D0908288L1-0    Z80        Dynax
2488 Mahjong Almond Pinky     D1401128L-0     Z80        Dynax
2589 Mahjong Derringer        D2203018L       Z80        Dynax               Larger palette
2690 Mahjong If..?            D29?            TLCS-90    Dynax               Larger palette
2792 Mahjong Cafe Time        D6310128L1-1    TLCS-90    Dynax               Larger palette, Real Time Clock
2895 Mahjong Tensinhai        D10010318L1     TLCS-90    Dynax               Larger palette, Real Time Clock
2996 Janputer '96                             Z80        Dynax               Larger palette, Real Time Clock
30----------------------------------------------------------------------------------------------------------
3031
3132TODO:
3233
33- dip switches and inputs in dondenmj, suzume, mjapinky, mjderngr...
34- dip switches and inputs in dondenmj, suzume, mjderngr...
3435
3536- there's something fishy with the bank switching in tontonb/mjdiplob
3637
r936r937
7576- janptr96: in service mode press in sequence N,Ron,Ron,N to access some
7677  hidden options. (thanks bnathan)
7778
78
79*** Notes by Roberto Fresca ***
80
81 - Added Mahjong Almond Pinky (Dynax, 1988).
82   Sub board: D1401128L-0
83
84   - Mapped all read/writes, but some ones need to be figured out..
85   - Updated technical notes.
86
87
8879****************************************************************************/
8980
9081#include "driver.h"
r936r937
9384#include "sound/ay8910.h"
9485
9586
87static UINT8 input_port_select, dsw_select, rombank;
9688static int palette_base;
9789
9890
99static void royalmah_get_pens(pen_t *pens)
91static PALETTE_INIT( royalmah )
10092{
10193   offs_t i;
10294
r936r937
124116      bit2 = (data >> 7) & 0x01;
125117      b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
126118
127      pens[i] = MAKE_RGB(r, g, b);
119      palette_set_color_rgb(machine,i, r,g,b);
128120   }
129121}
130122
131123
132static void mjderngr_get_pens(pen_t *pens)
124static PALETTE_INIT( mjderngr )
133125{
134126   offs_t i;
135127
r936r937
142134      UINT8 g = BITSWAP8((data >>  5) & 0x1f,7,6,5,0,1,2,3,4 );
143135      UINT8 b = BITSWAP8((data >> 10) & 0x1f,7,6,5,0,1,2,3,4 );
144136
145      pens[i] = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
137      palette_set_color_rgb(machine,i, pal5bit(r), pal5bit(g), pal5bit(b));
146138   }
147139}
148140
r936r937
174166}
175167
176168
177static int video_update_common(mame_bitmap *bitmap, const rectangle *cliprect, pen_t *pens)
169static VIDEO_UPDATE( royalmah )
178170{
171
179172   offs_t offs;
180173
181174   for (offs = 0; offs < 0x4000; offs++)
r936r937
190183
191184      for (i = 0; i < 4; i++)
192185      {
193         UINT8 color = ((data2 >> 1) & 0x08) | ((data2 << 2) & 0x04) | ((data1 >> 3) & 0x02) | ((data1 >> 0) & 0x01);
186         UINT8 pen = ((data2 >> 1) & 0x08) | ((data2 << 2) & 0x04) | ((data1 >> 3) & 0x02) | ((data1 >> 0) & 0x01);
194187
195         *BITMAP_ADDR32(bitmap, y, x) = pens[(palette_base << 4) | color];
188         *BITMAP_ADDR16(bitmap, y, x) = (palette_base << 4) | pen;
196189
197190         x = x - 1;
198191         data1 = data1 >> 1;
r936r937
204197}
205198
206199
207static VIDEO_UPDATE( royalmah )
208{
209   pen_t pens[0x400];
210   royalmah_get_pens(pens);
211200
212   return video_update_common(bitmap, cliprect, pens);
213}
214201
215202
216static VIDEO_UPDATE( mjderngr )
217{
218   pen_t pens[0x400];
219   mjderngr_get_pens(pens);
220
221   return video_update_common(bitmap, cliprect, pens);
222}
223
224
225
226203static WRITE8_HANDLER( royalmah_rom_w )
227204{
228205   /* using this handler will avoid all the entries in the error log that are the result of
r936r937
230207}
231208
232209
233static int royalmah_input_port_select;
234static int majs101b_dsw_select;
235
236static WRITE8_HANDLER( royalmah_input_port_select_w )
210static WRITE8_HANDLER( input_port_select_w )
237211{
238   royalmah_input_port_select = data;
212   input_port_select = data;
239213}
240214
241215static READ8_HANDLER( royalmah_player_1_port_r )
242216{
243217   int ret = (input_port_0_r(offset) & 0xc0) | 0x3f;
244218
245   if ((royalmah_input_port_select & 0x01) == 0)  ret &= input_port_0_r(offset);
246   if ((royalmah_input_port_select & 0x02) == 0)  ret &= input_port_1_r(offset);
247   if ((royalmah_input_port_select & 0x04) == 0)  ret &= input_port_2_r(offset);
248   if ((royalmah_input_port_select & 0x08) == 0)  ret &= input_port_3_r(offset);
249   if ((royalmah_input_port_select & 0x10) == 0)  ret &= input_port_4_r(offset);
219   if ((input_port_select & 0x01) == 0)  ret &= input_port_0_r(offset);
220   if ((input_port_select & 0x02) == 0)  ret &= input_port_1_r(offset);
221   if ((input_port_select & 0x04) == 0)  ret &= input_port_2_r(offset);
222   if ((input_port_select & 0x08) == 0)  ret &= input_port_3_r(offset);
223   if ((input_port_select & 0x10) == 0)  ret &= input_port_4_r(offset);
250224
251225   return ret;
252226}
r936r937
255229{
256230   int ret = (input_port_5_r(offset) & 0xc0) | 0x3f;
257231
258   if ((royalmah_input_port_select & 0x01) == 0)  ret &= input_port_5_r(offset);
259   if ((royalmah_input_port_select & 0x02) == 0)  ret &= input_port_6_r(offset);
260   if ((royalmah_input_port_select & 0x04) == 0)  ret &= input_port_7_r(offset);
261   if ((royalmah_input_port_select & 0x08) == 0)  ret &= input_port_8_r(offset);
262   if ((royalmah_input_port_select & 0x10) == 0)  ret &= input_port_9_r(offset);
232   if ((input_port_select & 0x01) == 0)  ret &= input_port_5_r(offset);
233   if ((input_port_select & 0x02) == 0)  ret &= input_port_6_r(offset);
234   if ((input_port_select & 0x04) == 0)  ret &= input_port_7_r(offset);
235   if ((input_port_select & 0x08) == 0)  ret &= input_port_8_r(offset);
236   if ((input_port_select & 0x10) == 0)  ret &= input_port_9_r(offset);
263237
264238   return ret;
265239}
r936r937
268242
269243static READ8_HANDLER ( majs101b_dsw_r )
270244{
271   switch (majs101b_dsw_select)
245   switch (dsw_select)
272246   {
273247      case 0x00: return readinputport(13);   /* DSW3 */
274248      case 0x20: return readinputport(14);   /* DSW4 */
r936r937
314288}
315289
316290
291static WRITE8_HANDLER ( mjapinky_bank_w )
292{
293   UINT8 *ROM = memory_region(REGION_CPU1);
294   rombank = data;
295   memory_set_bankptr(1,ROM + 0x10000 + 0x8000 * data);
296}
297
298static WRITE8_HANDLER( mjapinky_palbank_w )
299{
300   flip_screen_set(~data & 4);
301   palette_base = (data >> 3) & 0x01;
302   coin_counter_w(0,data & 2);   // in
303   coin_counter_w(1,data & 1);   // out
304}
305
306static READ8_HANDLER( mjapinky_dsw_r )
307{
308   if (rombank == 0x0e)   return readinputport(13);
309   else               return *(memory_region(REGION_CPU1) + 0x10000 + 0x8000 * rombank);
310}
311
317312static WRITE8_HANDLER ( tontonb_bank_w )
318313{
319314   UINT8 *rom = memory_region(REGION_CPU1);
r936r937
339334
340335//logerror("%04x: bank %02x\n",activecpu_get_pc(),data);
341336
342   majs101b_dsw_select = data & 0x60;
337   dsw_select = data & 0x60;
343338
344339   data &= 0x1f;
345340
r936r937
352347
353348
354349
355static ADDRESS_MAP_START( readmem, ADDRESS_SPACE_PROGRAM, 8 )
356   AM_RANGE(0x0000, 0x6fff) AM_READ(MRA8_ROM)
357   AM_RANGE(0x7000, 0x7fff) AM_READ(MRA8_RAM)
358   AM_RANGE(0x8000, 0xffff) AM_READ(MRA8_BANK1)   // banked ROMs not present in royalmah
350static ADDRESS_MAP_START( royalmah_map, ADDRESS_SPACE_PROGRAM, 8 )
351   AM_RANGE( 0x0000, 0x6fff ) AM_READWRITE( MRA8_ROM, royalmah_rom_w )
352   AM_RANGE( 0x7000, 0x7fff ) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
353   AM_RANGE( 0x8000, 0xffff ) AM_READ( MRA8_BANK1 )   // banked ROMs not present in royalmah
354   AM_RANGE( 0x8000, 0xffff ) AM_WRITE( MWA8_RAM ) AM_BASE(&videoram)
359355ADDRESS_MAP_END
360static ADDRESS_MAP_START( writemem, ADDRESS_SPACE_PROGRAM, 8 )
361   AM_RANGE(0x0000, 0x6fff) AM_WRITE(royalmah_rom_w)
362   AM_RANGE(0x7000, 0x7fff) AM_WRITE(MWA8_RAM) AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
363   AM_RANGE(0x8000, 0xffff) AM_WRITE(MWA8_RAM) AM_BASE(&videoram)
364ADDRESS_MAP_END
365356
366357
367
368static ADDRESS_MAP_START( royalmah_readport, ADDRESS_SPACE_IO, 8 )
369   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
370   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
371   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
372   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
358static ADDRESS_MAP_START( mjapinky_map, ADDRESS_SPACE_PROGRAM, 8 )
359   AM_RANGE( 0x0000, 0x6fff ) AM_READWRITE( MRA8_ROM, royalmah_rom_w )
360   AM_RANGE( 0x7000, 0x77ff ) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
361   AM_RANGE( 0x7800, 0x7fff ) AM_RAM
362   AM_RANGE( 0x8000, 0x8000 ) AM_READ( mjapinky_dsw_r )
363   AM_RANGE( 0x8000, 0xffff ) AM_READ( MRA8_BANK1 )
364   AM_RANGE( 0x8000, 0xffff ) AM_WRITE( MWA8_RAM ) AM_BASE(&videoram)
373365ADDRESS_MAP_END
374366
375static ADDRESS_MAP_START( royalmah_writeport, ADDRESS_SPACE_IO, 8 )
376   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
377   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
378   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
379   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
380   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
381ADDRESS_MAP_END
382367
383static ADDRESS_MAP_START( suzume_readport, ADDRESS_SPACE_IO, 8 )
384   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
385   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
386   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
387   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
388   AM_RANGE(0x80, 0x80) AM_READ(suzume_dsw_r)
389ADDRESS_MAP_END
390368
391static ADDRESS_MAP_START( suzume_writeport, ADDRESS_SPACE_IO, 8 )
392   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
393   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
394   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
395   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
396   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
397   AM_RANGE(0x81, 0x81) AM_WRITE(suzume_bank_w)
398ADDRESS_MAP_END
399369
400static ADDRESS_MAP_START( dondenmj_readport, ADDRESS_SPACE_IO, 8 )
370static ADDRESS_MAP_START( royalmah_iomap, ADDRESS_SPACE_IO, 8 )
401371   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
402   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
403   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
404   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
405   AM_RANGE(0x85, 0x85) AM_READ(input_port_12_r)   // DSW2
406   AM_RANGE(0x86, 0x86) AM_READ(input_port_13_r)   // DSW3
372   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
373   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
374   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
375   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
376   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
407377ADDRESS_MAP_END
408378
409static ADDRESS_MAP_START( dondenmj_writeport, ADDRESS_SPACE_IO, 8 )
379static ADDRESS_MAP_START( suzume_iomap, ADDRESS_SPACE_IO, 8 )
410380   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
411   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
412   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
413   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
414   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
415   AM_RANGE(0x87, 0x87) AM_WRITE(dynax_bank_w)
381   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
382   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
383   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
384   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
385   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
386   AM_RANGE( 0x80, 0x80 ) AM_READ( suzume_dsw_r )
387   AM_RANGE( 0x81, 0x81 ) AM_WRITE( suzume_bank_w )
416388ADDRESS_MAP_END
417389
418static ADDRESS_MAP_START( mjdiplob_readport, ADDRESS_SPACE_IO, 8 )
390static ADDRESS_MAP_START( dondenmj_iomap, ADDRESS_SPACE_IO, 8 )
419391   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
420   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
421   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
422   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
423   AM_RANGE(0x62, 0x62) AM_READ(input_port_12_r)   // DSW2
424   AM_RANGE(0x63, 0x63) AM_READ(input_port_13_r)   // DSW3
392   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
393   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
394   AM_RANGE( 0x03, 0x03 ) AM_WRITE(AY8910_control_port_0_w)
395   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
396   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
397   AM_RANGE( 0x85, 0x85 ) AM_READ( input_port_12_r )   // DSW2
398   AM_RANGE( 0x86, 0x86 ) AM_READ( input_port_13_r )   // DSW3
399   AM_RANGE( 0x87, 0x87 ) AM_WRITE( dynax_bank_w )
425400ADDRESS_MAP_END
426401
427static ADDRESS_MAP_START( mjdiplob_writeport, ADDRESS_SPACE_IO, 8 )
402static ADDRESS_MAP_START( mjdiplob_iomap, ADDRESS_SPACE_IO, 8 )
428403   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
429   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
430   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
431   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
432   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
433   AM_RANGE(0x61, 0x61) AM_WRITE(tontonb_bank_w)
404   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
405   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
406   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
407   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
408   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
409   AM_RANGE( 0x61, 0x61 ) AM_WRITE(tontonb_bank_w)
410   AM_RANGE( 0x62, 0x62 ) AM_READ( input_port_12_r )   // DSW2
411   AM_RANGE( 0x63, 0x63 ) AM_READ( input_port_13_r )   // DSW3
434412ADDRESS_MAP_END
435413
436static ADDRESS_MAP_START( tontonb_readport, ADDRESS_SPACE_IO, 8 )
414static ADDRESS_MAP_START( tontonb_iomap, ADDRESS_SPACE_IO, 8 )
437415   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
438   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
439   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
440   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
441   AM_RANGE(0x46, 0x46) AM_READ(input_port_13_r)   // DSW2
442   AM_RANGE(0x47, 0x47) AM_READ(input_port_12_r)   // DSW3
416   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
417   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
418   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
419   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
420   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
421   AM_RANGE( 0x44, 0x44 ) AM_WRITE( tontonb_bank_w )
422   AM_RANGE( 0x46, 0x46 ) AM_READ( input_port_13_r )   // DSW2
423   AM_RANGE( 0x47, 0x47 ) AM_READ( input_port_12_r )   // DSW3
443424ADDRESS_MAP_END
444425
445static ADDRESS_MAP_START( tontonb_writeport, ADDRESS_SPACE_IO, 8 )
426static ADDRESS_MAP_START( majs101b_iomap, ADDRESS_SPACE_IO, 8 )
446427   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
447   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
448   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
449   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
450   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
451   AM_RANGE(0x44, 0x44) AM_WRITE(tontonb_bank_w)
428   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
429   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
430   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
431   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, royalmah_palbank_w )
432   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
433   AM_RANGE( 0x00, 0x00 ) AM_READWRITE( majs101b_dsw_r, dynax_bank_w )
452434ADDRESS_MAP_END
453435
454static ADDRESS_MAP_START( majs101b_readport, ADDRESS_SPACE_IO, 8 )
436static ADDRESS_MAP_START( mjderngr_iomap, ADDRESS_SPACE_IO, 8 )
455437   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
456   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
457   AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
458   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
459   AM_RANGE(0x00, 0x00) AM_READ(majs101b_dsw_r)
438   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
439   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
440   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
441//  AM_RANGE( 0x10, 0x10 ) AM_READ( input_port_11_r )
442   AM_RANGE( 0x10, 0x10 ) AM_WRITE( mjderngr_coin_w )   // palette bank is set separately
443   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
444   AM_RANGE( 0x20, 0x20 ) AM_WRITE( dynax_bank_w )
445   AM_RANGE( 0x40, 0x40 ) AM_READ( input_port_13_r )   // DSW2
446   AM_RANGE( 0x4c, 0x4c ) AM_READ( input_port_12_r )   // DSW3
447   AM_RANGE( 0x60, 0x60 ) AM_WRITE( mjderngr_palbank_w )
460448ADDRESS_MAP_END
461449
462static ADDRESS_MAP_START( majs101b_writeport, ADDRESS_SPACE_IO, 8 )
450static ADDRESS_MAP_START( mjapinky_iomap, ADDRESS_SPACE_IO, 8 )
463451   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
464   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
465   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
466   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
467   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
468   AM_RANGE(0x00, 0x00) AM_WRITE(dynax_bank_w)
452   AM_RANGE( 0x00, 0x00 ) AM_WRITE( mjapinky_bank_w )
453   AM_RANGE( 0x01, 0x01 ) AM_READ( AY8910_read_port_0_r )
454   AM_RANGE( 0x02, 0x02 ) AM_WRITE( AY8910_write_port_0_w )
455   AM_RANGE( 0x03, 0x03 ) AM_WRITE( AY8910_control_port_0_w )
456   AM_RANGE( 0x04, 0x04 ) AM_READ( input_port_12_r )
457   AM_RANGE( 0x10, 0x10 ) AM_READWRITE( input_port_11_r, mjapinky_palbank_w )
458   AM_RANGE( 0x11, 0x11 ) AM_READWRITE( input_port_10_r, input_port_select_w )
469459ADDRESS_MAP_END
470460
471static ADDRESS_MAP_START( mjapinky_readport, ADDRESS_SPACE_IO, 8 )
472   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
473   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
474   AM_RANGE(0x04, 0x04) AM_READNOP // input port?
475   AM_RANGE(0x10, 0x10) AM_READNOP // input port
476   AM_RANGE(0x11, 0x11) AM_READNOP // input port
477   AM_RANGE(0x00, 0x00) AM_READNOP // dsw?
478ADDRESS_MAP_END
479
480static ADDRESS_MAP_START( mjapinky_writeport, ADDRESS_SPACE_IO, 8 )
481   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
482   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
483   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
484   AM_RANGE(0x10, 0x10) AM_WRITE(royalmah_palbank_w)
485   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
486   AM_RANGE(0x00, 0x00) AM_WRITE(dynax_bank_w)
487ADDRESS_MAP_END
488
489static ADDRESS_MAP_START( mjderngr_readport, ADDRESS_SPACE_IO, 8 )
490   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
491   AM_RANGE(0x01, 0x01) AM_READ(AY8910_read_port_0_r)
492//  AM_RANGE(0x10, 0x10) AM_READ(input_port_11_r)
493   AM_RANGE(0x11, 0x11) AM_READ(input_port_10_r)
494   AM_RANGE(0x40, 0x40) AM_READ(input_port_13_r)   // DSW2
495   AM_RANGE(0x4c, 0x4c) AM_READ(input_port_12_r)   // DSW3
496ADDRESS_MAP_END
497
498static ADDRESS_MAP_START( mjderngr_writeport, ADDRESS_SPACE_IO, 8 )
499   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
500   AM_RANGE(0x02, 0x02) AM_WRITE(AY8910_write_port_0_w)
501   AM_RANGE(0x03, 0x03) AM_WRITE(AY8910_control_port_0_w)
502   AM_RANGE(0x10, 0x10) AM_WRITE(mjderngr_coin_w)   // palette bank is set separately
503   AM_RANGE(0x11, 0x11) AM_WRITE(royalmah_input_port_select_w)
504   AM_RANGE(0x20, 0x20) AM_WRITE(dynax_bank_w)
505   AM_RANGE(0x60, 0x60) AM_WRITE(mjderngr_palbank_w)
506ADDRESS_MAP_END
507
508
509461/****************************************************************************
510462                                Janputer '96
511463****************************************************************************/
512464
513static ADDRESS_MAP_START( janptr96_readmem, ADDRESS_SPACE_PROGRAM, 8 )
514   AM_RANGE(0x0000, 0x5fff) AM_READ(MRA8_ROM)
515   AM_RANGE(0x6000, 0x6fff) AM_READ(MRA8_BANK3)
516   AM_RANGE(0x7000, 0x7fff) AM_READ(MRA8_BANK2)
517   AM_RANGE(0x8000, 0xffff) AM_READ(MRA8_BANK1)
465static ADDRESS_MAP_START( janptr96_map, ADDRESS_SPACE_PROGRAM, 8 )
466   AM_RANGE( 0x0000, 0x5fff) AM_ROM
467   AM_RANGE( 0x6000, 0x6fff ) AM_RAMBANK(3)   // nvram
468   AM_RANGE( 0x7000, 0x7fff ) AM_RAMBANK(2)   // banked nvram
469   AM_RANGE( 0x8000, 0xffff ) AM_READ(MRA8_BANK1)
470   AM_RANGE( 0x8000, 0xffff ) AM_WRITE(MWA8_RAM) AM_BASE(&videoram)
518471ADDRESS_MAP_END
519static ADDRESS_MAP_START( janptr96_writemem, ADDRESS_SPACE_PROGRAM, 8 )
520   AM_RANGE(0x0000, 0x5fff) AM_WRITE(MWA8_ROM)
521   AM_RANGE(0x6000, 0x6fff) AM_WRITE(MWA8_BANK3)   // nvram
522   AM_RANGE(0x7000, 0x7fff) AM_WRITE(MWA8_BANK2)   // banked nvram
523   AM_RANGE(0x8000, 0xffff) AM_WRITE(MWA8_RAM) AM_BASE(&videoram)
524ADDRESS_MAP_END
525472
526473static WRITE8_HANDLER( janptr96_dswsel_w )
527474{
528475   // 0x20 = 0 -> hopper on
529476   // 0x40 ?
530   majs101b_dsw_select = data;
477   dsw_select = data;
531478}
532479
533480static READ8_HANDLER( janptr96_dswsel_r )
534481{
535   return majs101b_dsw_select;
482   return dsw_select;
536483}
537484
538485static READ8_HANDLER( janptr96_dsw_r )
539486{
540   if (~majs101b_dsw_select & 0x01) return readinputportbytag("DSW4");
541   if (~majs101b_dsw_select & 0x02) return readinputportbytag("DSW3");
542   if (~majs101b_dsw_select & 0x04) return readinputportbytag("DSW2");
543   if (~majs101b_dsw_select & 0x08) return readinputportbytag("DSW1");
544   if (~majs101b_dsw_select & 0x10) return readinputportbytag("DSWTOP");
487   if (~dsw_select & 0x01) return readinputportbytag("DSW4");
488   if (~dsw_select & 0x02) return readinputportbytag("DSW3");
489   if (~dsw_select & 0x04) return readinputportbytag("DSW2");
490   if (~dsw_select & 0x08) return readinputportbytag("DSW1");
491   if (~dsw_select & 0x10) return readinputportbytag("DSWTOP");
545492   return 0xff;
546493}
547494
r936r937
569516   coin_counter_w(1,data & 1);   // out
570517}
571518
572static ADDRESS_MAP_START( janptr96_readport, ADDRESS_SPACE_IO, 8 )
519static ADDRESS_MAP_START( janptr96_iomap, ADDRESS_SPACE_IO, 8 )
573520   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
574   AM_RANGE(0x1e, 0x1e) AM_READ(janptr96_dswsel_r      )
575   AM_RANGE(0x1c, 0x1c) AM_READ(janptr96_dsw_r         )
576   AM_RANGE(0x20, 0x20) AM_READ(janptr96_unknown_r      )   // ?
577   AM_RANGE(0x60, 0x6f) AM_READ(msm6242_r            )   // 6242RTC
578   AM_RANGE(0x81, 0x81) AM_READ(AY8910_read_port_0_r   )
579   AM_RANGE(0xd9, 0xd9) AM_READ(input_port_10_r)
521   AM_RANGE( 0x00, 0x00 ) AM_WRITE( janptr96_rombank_w )   // BANK ROM Select
522   AM_RANGE( 0x1e, 0x1e ) AM_READWRITE( janptr96_dswsel_r, janptr96_dswsel_w )
523   AM_RANGE( 0x1c, 0x1c ) AM_READ( janptr96_dsw_r )
524   AM_RANGE( 0x20, 0x20 ) AM_READWRITE( janptr96_unknown_r, janptr96_rambank_w )
525   AM_RANGE( 0x50, 0x50 ) AM_WRITE( mjderngr_palbank_w )
526   AM_RANGE( 0x60, 0x6f ) AM_READWRITE( msm6242_r, msm6242_w )
527   AM_RANGE( 0x81, 0x81 ) AM_READ( AY8910_read_port_0_r )
528   AM_RANGE( 0x82, 0x82 ) AM_WRITE( AY8910_write_port_0_w )
529   AM_RANGE( 0x83, 0x83 ) AM_WRITE( AY8910_control_port_0_w )
530   AM_RANGE( 0x93, 0x93 ) AM_WRITE( input_port_select_w )
531   AM_RANGE( 0xd8, 0xd8 ) AM_WRITE( janptr96_coin_counter_w )
532   AM_RANGE( 0xd9, 0xd9 ) AM_READ( input_port_10_r )
580533ADDRESS_MAP_END
581534
582static ADDRESS_MAP_START( janptr96_writeport, ADDRESS_SPACE_IO, 8 )
583   ADDRESS_MAP_FLAGS( AMEF_ABITS(8) )
584   AM_RANGE(0x00, 0x00) AM_WRITE(janptr96_rombank_w      )   // BANK ROM Select
585   AM_RANGE(0x1e, 0x1e) AM_WRITE(janptr96_dswsel_w         )
586   AM_RANGE(0x20, 0x20) AM_WRITE(janptr96_rambank_w      )   // BANK RAM Select
587   AM_RANGE(0x50, 0x50) AM_WRITE(mjderngr_palbank_w      )
588   AM_RANGE(0x60, 0x6f) AM_WRITE(msm6242_w               )   // 6242RTC
589   AM_RANGE(0x82, 0x82) AM_WRITE(AY8910_write_port_0_w      )   // AY8910
590   AM_RANGE(0x83, 0x83) AM_WRITE(AY8910_control_port_0_w   )   //
591   AM_RANGE(0x93, 0x93) AM_WRITE(royalmah_input_port_select_w)
592   AM_RANGE(0xd8, 0xd8) AM_WRITE(janptr96_coin_counter_w)
593ADDRESS_MAP_END
594
595535/****************************************************************************
596536                                Mahjong If
597537****************************************************************************/
598538
599static UINT8 rombank;
600539static UINT8 mjifb_rom_enable;
601540
602541static WRITE8_HANDLER( mjifb_coin_counter_w )
r936r937
643582      case 0x9010:
644583         mjifb_coin_counter_w(0,data);
645584         return;
646      case 0x9011:   royalmah_input_port_select_w(0,data);   return;
585      case 0x9011:   input_port_select_w(0,data);   return;
647586      case 0x9013:
648587//          if (data)   popmessage("%02x",data);
649588         return;
r936r937
740679   AM_RANGE( 0x6fc2, 0x6fc2 ) AM_WRITE( AY8910_write_port_0_w )
741680   AM_RANGE( 0x6fc3, 0x6fc3 ) AM_WRITE( AY8910_control_port_0_w )
742681   AM_RANGE( 0x6fd0, 0x6fd0 ) AM_WRITE( janptr96_coin_counter_w )
743   AM_RANGE( 0x6fd1, 0x6fd1 ) AM_READWRITE( input_port_10_r, royalmah_input_port_select_w )
682   AM_RANGE( 0x6fd1, 0x6fd1 ) AM_READWRITE( input_port_10_r, input_port_select_w )
744683   AM_RANGE( 0x6fe0, 0x6fef ) AM_READWRITE( msm6242_r, msm6242_w )
745684   AM_RANGE( 0x6ff0, 0x6ff0 ) AM_READWRITE( janptr96_dsw_r, janptr96_dswsel_w )
746685   AM_RANGE( 0x6ff1, 0x6ff1 ) AM_WRITE( mjderngr_palbank_w )
r936r937
756695ADDRESS_MAP_END
757696
758697
698/****************************************************************************
699                                Mahjong Cafe Time
700****************************************************************************/
759701
702static void cafetime_update_rombank(void)
703{
704   memory_set_bankptr( 1, memory_region(REGION_CPU1) + 0x10000 + rombank * 0x8000 );
705}
706static WRITE8_HANDLER( cafetime_p4_w )
707{
708   rombank = (rombank & 0xf0) | (data & 0x0f);
709   cafetime_update_rombank();
710}
711static WRITE8_HANDLER( cafetime_p3_w )
712{
713   rombank = (rombank & 0x0f) | ((data & 0x0c) << 2);
714   cafetime_update_rombank();
715}
760716
717static WRITE8_HANDLER( cafetime_dsw_w )
718{
719   dsw_select = data;
720}
721static READ8_HANDLER( cafetime_dsw_r )
722{
723   switch( dsw_select )
724   {
725      case 0x00: return readinputportbytag("DSW1");
726      case 0x01: return readinputportbytag("DSW2");
727      case 0x02: return readinputportbytag("DSW3");
728      case 0x03: return readinputportbytag("DSW4");
729      case 0x04: return readinputportbytag("DSWTOP");
730   }
731   logerror("%04X: unmapped dsw read %02X\n", activecpu_get_pc(), dsw_select);
732   return 0xff;
733}
734
735static READ8_HANDLER( cafetime_7fe4_r )
736{
737   return 0xff;
738}
739static WRITE8_HANDLER( cafetime_7fe3_w )
740{
741//  popmessage("%02x",data);
742}
743
744static ADDRESS_MAP_START( cafetime_map, ADDRESS_SPACE_PROGRAM, 8 )
745   AM_RANGE( 0x0000, 0x5fff ) AM_ROM
746   AM_RANGE( 0x6000, 0x7eff ) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
747   AM_RANGE( 0x7fc1, 0x7fc1 ) AM_READ( AY8910_read_port_0_r )
748   AM_RANGE( 0x7fc2, 0x7fc2 ) AM_WRITE( AY8910_write_port_0_w )
749   AM_RANGE( 0x7fc3, 0x7fc3 ) AM_WRITE( AY8910_control_port_0_w )
750   AM_RANGE( 0x7fd0, 0x7fd0 ) AM_WRITE( janptr96_coin_counter_w )
751   AM_RANGE( 0x7fd1, 0x7fd1 ) AM_READWRITE( input_port_10_r, MWA8_NOP )
752   AM_RANGE( 0x7fd3, 0x7fd3 ) AM_WRITE( input_port_select_w )
753   AM_RANGE( 0x7fe0, 0x7fe0 ) AM_READ( cafetime_dsw_r )
754   AM_RANGE( 0x7fe1, 0x7fe1 ) AM_WRITE( cafetime_dsw_w )
755   AM_RANGE( 0x7fe2, 0x7fe2 ) AM_WRITE( mjderngr_palbank_w )
756   AM_RANGE( 0x7fe3, 0x7fe3 ) AM_WRITE( cafetime_7fe3_w )
757   AM_RANGE( 0x7fe4, 0x7fe4 ) AM_READ( cafetime_7fe4_r )
758   AM_RANGE( 0x7ff0, 0x7fff ) AM_READWRITE( msm6242_r, msm6242_w )
759   AM_RANGE( 0x8000, 0xffff ) AM_READ( MRA8_BANK1 )
760   AM_RANGE( 0x8000, 0xffff ) AM_WRITE( MWA8_RAM ) AM_BASE(&videoram)
761ADDRESS_MAP_END
762
763
764static ADDRESS_MAP_START( cafetime_iomap, ADDRESS_SPACE_IO, 8 )
765   AM_RANGE( T90_P3, T90_P3 ) AM_WRITE( cafetime_p3_w )
766   AM_RANGE( T90_P4, T90_P4 ) AM_WRITE( cafetime_p4_w )
767ADDRESS_MAP_END
768
769
761770static INPUT_PORTS_START( royalmah )
762771   PORT_START   /* P1 IN0 */
763772   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_A )
r936r937
16311640INPUT_PORTS_END
16321641
16331642static INPUT_PORTS_START( mjapinky )
1643   PORT_START   /* P1 IN0 */
1644   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_A )
1645   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_E )
1646   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_I )
1647   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_M )
1648   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
1649   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
1650   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Payout") PORT_CODE(KEYCODE_7)
1651   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
1652
1653   PORT_START   /* P1 IN1 */
1654   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_B )
1655   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_F )
1656   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_J )
1657   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_N )
1658   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
1659   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_BET )
1660   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
1661
1662   PORT_START   /* P1 IN2 */
1663   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_C )
1664   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_G )
1665   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_K )
1666   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
1667   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
1668   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
1669
1670   PORT_START   /* P1 IN3 */
1671   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_D )
1672   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_H )
1673   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_L )
1674   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
1675   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
1676
1677   PORT_START   /* P1 IN4 */
1678   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_LAST_CHANCE )
1679   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_SCORE )
1680   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_DOUBLE_UP )
1681   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
1682   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_BIG )
1683   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_SMALL )
1684   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
1685
1686   PORT_START   /* P2 IN0 */
1687   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_A )PORT_PLAYER(2)
1688   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_E )PORT_PLAYER(2)
1689   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_I )PORT_PLAYER(2)
1690   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_M )PORT_PLAYER(2)
1691   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )PORT_PLAYER(2)
1692   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
1693   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
1694   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
1695
1696   PORT_START   /* P2 IN1 */
1697   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_B )PORT_PLAYER(2)
1698   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_F )PORT_PLAYER(2)
1699   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_J )PORT_PLAYER(2)
1700   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_N )PORT_PLAYER(2)
1701   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )PORT_PLAYER(2)
1702   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_BET )PORT_PLAYER(2) PORT_CODE(KEYCODE_4)
1703   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
1704
1705   PORT_START   /* P2 IN2 */
1706   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_C )PORT_PLAYER(2)
1707   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_G )PORT_PLAYER(2)
1708   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_K )PORT_PLAYER(2)
1709   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )PORT_PLAYER(2)
1710   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_RON )PORT_PLAYER(2)
1711   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
1712
1713   PORT_START   /* P2 IN3 */
1714   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_D )PORT_PLAYER(2)
1715   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_H )PORT_PLAYER(2)
1716   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_L )PORT_PLAYER(2)
1717   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_PON )PORT_PLAYER(2)
1718   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
1719
1720   PORT_START   /* P2 IN4 */
1721   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_LAST_CHANCE )PORT_PLAYER(2)
1722   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_SCORE )PORT_PLAYER(2)
1723   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_DOUBLE_UP )PORT_PLAYER(2)
1724   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )PORT_PLAYER(2)
1725   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_BIG )PORT_PLAYER(2)
1726   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_SMALL )PORT_PLAYER(2)
1727   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
1728
1729   PORT_START   /* IN10 */
1730   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SERVICE1 )   /* "Note" ("Paper Money") = 10 Credits */
1731   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE3 )   /* Memory Reset */
1732   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SERVICE2 )   /* Analizer (Statistics) */
1733   PORT_SERVICE( 0x08, IP_ACTIVE_HIGH )
1734   PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNUSED )
1735
1736   PORT_START_TAG("DSW1")   /* IN11 */
1737   PORT_DIPNAME( 0x01, 0x01, "Unknown 1-0" )
1738   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1739   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1740   PORT_DIPNAME( 0x02, 0x02, "Unknown 1-1" )
1741   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1742   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1743   PORT_DIPNAME( 0x04, 0x04, "Unknown 1-2" )
1744   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1745   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1746   PORT_DIPNAME( 0x08, 0x08, "Unknown 1-3" )
1747   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1748   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1749   PORT_DIPNAME( 0x30, 0x30, "Maximum Bet" )
1750   PORT_DIPSETTING(    0x30, "1" )
1751   PORT_DIPSETTING(    0x20, "5" )
1752   PORT_DIPSETTING(    0x10, "10" )
1753   PORT_DIPSETTING(    0x00, "20" )
1754   PORT_DIPNAME( 0x40, 0x00, "Background" )
1755   PORT_DIPSETTING(    0x40, "Black" )
1756   PORT_DIPSETTING(    0x00, "Green" )
1757   PORT_DIPNAME( 0x80, 0x80, "Unknown 1-7" )
1758   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1759   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1760
1761   PORT_START_TAG("DSW2")   /* IN12 */
1762   PORT_DIPNAME( 0x03, 0x03, "Unknown 2-0&1" )
1763   PORT_DIPSETTING(    0x03, "0" )
1764   PORT_DIPSETTING(    0x02, "1" )
1765   PORT_DIPSETTING(    0x01, "2" )
1766   PORT_DIPSETTING(    0x00, "3" )
1767   PORT_DIPNAME( 0x04, 0x04, "Unknown 2-2" )
1768   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1769   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1770   PORT_DIPNAME( 0x08, 0x08, "Unknown 2-3" )
1771   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1772   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1773   PORT_DIPNAME( 0x30, 0x30, "Unknown 2-4&5" )
1774   PORT_DIPSETTING(    0x30, "0" )
1775   PORT_DIPSETTING(    0x20, "1" )
1776   PORT_DIPSETTING(    0x10, "2" )
1777   PORT_DIPSETTING(    0x00, "3" )
1778   PORT_DIPNAME( 0xc0, 0xc0, "Unknown 2-6&7" )
1779   PORT_DIPSETTING(    0xc0, "0" )
1780   PORT_DIPSETTING(    0x80, "1" )
1781   PORT_DIPSETTING(    0x40, "2" )
1782   PORT_DIPSETTING(    0x00, "3" )
1783
1784   PORT_START_TAG("DSW3")   /* IN13 */
1785   PORT_DIPNAME( 0x01, 0x01, "Unknown 3-0" )
1786   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1787   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1788   PORT_DIPNAME( 0x02, 0x02, "Unknown 3-1" )
1789   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1790   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1791   PORT_DIPNAME( 0x04, 0x04, "Unknown 3-2" )
1792   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1793   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1794   PORT_DIPNAME( 0x08, 0x08, "Unknown 3-3" )
1795   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1796   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1797   PORT_DIPNAME( 0x10, 0x10, "Unknown 3-4" )
1798   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
1799   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1800   PORT_DIPNAME( 0x20, 0x20, "Unknown 3-5" )
1801   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1802   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1803   PORT_DIPNAME( 0x40, 0x40, "Unknown 3-6" )
1804   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
1805   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1806   PORT_DIPNAME( 0x80, 0x80, "Full Test" )
1807   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1808   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
16341809INPUT_PORTS_END
16351810
16361811static INPUT_PORTS_START( janptr96 )
r936r937
22802455   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
22812456INPUT_PORTS_END
22822457
2458static INPUT_PORTS_START( cafetime )
2459   PORT_START   /* P1 IN0 */
2460   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_A )
2461   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_E )
2462   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_I )
2463   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_M )
2464   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
2465   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
2466   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Payout") PORT_CODE(KEYCODE_7)
2467   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2468
2469   PORT_START   /* P1 IN1 */
2470   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_B )
2471   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_F )
2472   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_J )
2473   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_N )
2474   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
2475   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_BET )
2476   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
2477
2478   PORT_START   /* P1 IN2 */
2479   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_C )
2480   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_G )
2481   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_K )
2482   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
2483   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
2484   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
2485
2486   PORT_START   /* P1 IN3 */
2487   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_D )
2488   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_H )
2489   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_L )
2490   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
2491   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
2492
2493   PORT_START   /* P1 IN4 */
2494   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_LAST_CHANCE )
2495   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_SCORE )
2496   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_DOUBLE_UP )
2497   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
2498   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_BIG )
2499   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_SMALL )
2500   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
2501
2502   PORT_START   /* P2 IN0 */
2503   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_A )PORT_PLAYER(2)
2504   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_E )PORT_PLAYER(2)
2505   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_I )PORT_PLAYER(2)
2506   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_M )PORT_PLAYER(2)
2507   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )PORT_PLAYER(2)
2508   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
2509   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
2510   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2511
2512   PORT_START   /* P2 IN1 */
2513   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_B )PORT_PLAYER(2)
2514   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_F )PORT_PLAYER(2)
2515   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_J )PORT_PLAYER(2)
2516   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_N )PORT_PLAYER(2)
2517   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )PORT_PLAYER(2)
2518   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_BET )PORT_PLAYER(2) PORT_CODE(KEYCODE_4)
2519   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
2520
2521   PORT_START   /* P2 IN2 */
2522   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_C )PORT_PLAYER(2)
2523   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_G )PORT_PLAYER(2)
2524   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_K )PORT_PLAYER(2)
2525   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )PORT_PLAYER(2)
2526   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_RON )PORT_PLAYER(2)
2527   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
2528
2529   PORT_START   /* P2 IN3 */
2530   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_D )PORT_PLAYER(2)
2531   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_H )PORT_PLAYER(2)
2532   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_L )PORT_PLAYER(2)
2533   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_PON )PORT_PLAYER(2)
2534   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
2535
2536   PORT_START   /* P2 IN4 */
2537   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_MAHJONG_LAST_CHANCE )PORT_PLAYER(2)
2538   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_MAHJONG_SCORE )PORT_PLAYER(2)
2539   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_MAHJONG_DOUBLE_UP )PORT_PLAYER(2)
2540   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )PORT_PLAYER(2)
2541   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_MAHJONG_BIG )PORT_PLAYER(2)
2542   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_MAHJONG_SMALL )PORT_PLAYER(2)
2543   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
2544
2545   PORT_START   /* IN10 */
2546   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SERVICE1 )   /* "Note" ("Paper Money") = 10 Credits */
2547   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE3 )   /* Memory Reset */
2548   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SERVICE2 )   /* Analizer (Statistics) */
2549   PORT_SERVICE( 0x08, IP_ACTIVE_HIGH )
2550   PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNUSED )
2551
2552   PORT_START_TAG("DSW1")   /* IN11 */
2553   PORT_DIPNAME( 0x0f, 0x07, "Pay Out Rate" )
2554   PORT_DIPSETTING(    0x0f, "96%" )
2555   PORT_DIPSETTING(    0x0e, "93%" )
2556   PORT_DIPSETTING(    0x0d, "90%" )
2557   PORT_DIPSETTING(    0x0c, "87%" )
2558   PORT_DIPSETTING(    0x0b, "84%" )
2559   PORT_DIPSETTING(    0x0a, "81%" )
2560   PORT_DIPSETTING(    0x09, "78%" )
2561   PORT_DIPSETTING(    0x08, "75%" )
2562   PORT_DIPSETTING(    0x07, "71%" )
2563   PORT_DIPSETTING(    0x06, "68%" )
2564   PORT_DIPSETTING(    0x05, "65%" )
2565   PORT_DIPSETTING(    0x04, "62%" )
2566   PORT_DIPSETTING(    0x03, "59%" )
2567   PORT_DIPSETTING(    0x02, "56%" )
2568   PORT_DIPSETTING(    0x01, "53%" )
2569   PORT_DIPSETTING(    0x00, "50%" )
2570   PORT_DIPNAME( 0x30, 0x00, "Maximum Bet" )
2571   PORT_DIPSETTING(    0x30, "1" )
2572   PORT_DIPSETTING(    0x20, "5" )
2573   PORT_DIPSETTING(    0x10, "10" )
2574   PORT_DIPSETTING(    0x00, "20" )
2575   PORT_DIPNAME( 0xc0, 0xc0, "Unknown 1-6&7" )
2576   PORT_DIPSETTING(    0xc0, "1" )
2577   PORT_DIPSETTING(    0x80, "2" )
2578   PORT_DIPSETTING(    0x40, "3" )
2579   PORT_DIPSETTING(    0x00, "4" )
2580
2581   PORT_START_TAG("DSW2")   /* IN12 */
2582   PORT_DIPNAME( 0x03, 0x03, "Winnings" )
2583   PORT_DIPSETTING(    0x03, "32 24 16 12 8 4 2 1" )
2584   PORT_DIPSETTING(    0x00, "50 30 15 8 5 3 2 1" )
2585   PORT_DIPSETTING(    0x01, "100 50 25 10 5 3 2 1" )
2586   PORT_DIPSETTING(    0x02, "200 100 50 10 5 3 2 1" )
2587   PORT_DIPNAME( 0x0c, 0x0c, "Unknown 2-2&3" )
2588   PORT_DIPSETTING(    0x0c, "1" )
2589   PORT_DIPSETTING(    0x08, "2" )
2590   PORT_DIPSETTING(    0x04, "3" )
2591   PORT_DIPSETTING(    0x00, "5" )
2592   PORT_DIPNAME( 0x70, 0x70, "Unknown 2-4&5&6" )
2593   PORT_DIPSETTING(    0x70, "0" )
2594   PORT_DIPSETTING(    0x60, "1" )
2595   PORT_DIPSETTING(    0x50, "2" )
2596   PORT_DIPSETTING(    0x40, "3" )
2597   PORT_DIPSETTING(    0x30, "4" )
2598   PORT_DIPSETTING(    0x20, "5" )
2599   PORT_DIPSETTING(    0x10, "6" )
2600   PORT_DIPSETTING(    0x00, "7" )
2601   PORT_DIPNAME( 0x80, 0x80, "Unknown 2-7" )
2602   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2603   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2604
2605   PORT_START_TAG("DSW3")   /* IN13 */
2606   PORT_DIPNAME( 0x01, 0x01, "Unknown 3-0" )
2607   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2608   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2609   PORT_DIPNAME( 0x02, 0x02, "Unknown 3-1" )
2610   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2611   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2612   PORT_DIPNAME( 0x04, 0x04, "Unknown 3-2" )
2613   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2614   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2615   PORT_DIPNAME( 0x08, 0x08, "Unknown 3-3" )
2616   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2617   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2618   PORT_DIPNAME( 0x10, 0x10, "Unknown 3-4" )
2619   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2620   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2621   PORT_DIPNAME( 0x20, 0x20, "Unknown 3-5" )
2622   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2623   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2624   PORT_DIPNAME( 0x40, 0x40, "Unknown 3-6" )
2625   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2626   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2627   PORT_DIPNAME( 0x80, 0x80, "Unknown 3-7" )
2628   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2629   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2630
2631   PORT_START_TAG("DSW4")   /* IN14 */
2632   PORT_DIPNAME( 0x01, 0x01, "Unknown 4-0" )
2633   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2634   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2635   PORT_DIPNAME( 0x02, 0x02, "Unknown 4-1" )
2636   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2637   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2638   PORT_DIPNAME( 0x04, 0x04, "Unknown 4-2" )
2639   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2640   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2641   PORT_DIPNAME( 0x08, 0x08, "Unknown 4-3" )
2642   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2643   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2644   PORT_DIPNAME( 0x10, 0x00, "Full Test" )
2645   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2646   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2647   PORT_DIPNAME( 0x20, 0x00, "Background" )
2648   PORT_DIPSETTING(    0x20, "Black" )
2649   PORT_DIPSETTING(    0x00, "Green" )
2650   PORT_DIPNAME( 0x40, 0x40, "Unknown 4-6" )
2651   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2652   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2653   PORT_DIPNAME( 0x80, 0x80, "Unknown 4-7" )
2654   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2655   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2656
2657   PORT_START_TAG("DSWTOP")   /* IN15 */
2658   PORT_DIPNAME( 0x01, 0x01, "Credits Per Note" )
2659   PORT_DIPSETTING(    0x01, "5" )
2660   PORT_DIPSETTING(    0x00, "10" )
2661   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
2662   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2663   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2664   PORT_DIPNAME( 0x04, 0x04, "Unknown 2-8" )
2665   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2666   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2667   PORT_DIPNAME( 0x08, 0x08, "Unknown 2-9" )
2668   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2669   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2670   PORT_DIPNAME( 0x30, 0x30, "Unknown 3-8&9" )
2671   PORT_DIPSETTING(    0x30, "0" )
2672   PORT_DIPSETTING(    0x20, "1" )
2673   PORT_DIPSETTING(    0x10, "2" )
2674   PORT_DIPSETTING(    0x00, "3" )
2675   PORT_DIPNAME( 0x40, 0x40, "Unknown 4-8" )
2676   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2677   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2678   PORT_DIPNAME( 0x80, 0x80, "Unknown 4-9" )
2679   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2680   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2681INPUT_PORTS_END
2682
2683
22832684static struct AY8910interface ay8910_interface =
22842685{
22852686   royalmah_player_1_port_r,
22862687   royalmah_player_2_port_r
22872688};
22882689
2289
2290
22912690static MACHINE_DRIVER_START( royalmah )
22922691
22932692   /* basic machine hardware */
2294   MDRV_CPU_ADD(Z80, 3000000)        /* 3.00 MHz ? */
2295   MDRV_CPU_PROGRAM_MAP(readmem,writemem)
2296   MDRV_CPU_IO_MAP(royalmah_readport,royalmah_writeport)
2693   MDRV_CPU_ADD_TAG("main", Z80, 3000000)        /* 3.00 MHz ? */
2694   MDRV_CPU_PROGRAM_MAP(royalmah_map,0)
2695   MDRV_CPU_IO_MAP(royalmah_iomap,0)
22972696   MDRV_CPU_VBLANK_INT(irq0_line_hold,1)
22982697
22992698   MDRV_NVRAM_HANDLER(generic_0fill)
r936r937
23012700   /* video hardware */
23022701   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
23032702   MDRV_VIDEO_UPDATE(royalmah)
2703   MDRV_PALETTE_LENGTH(16*2)
2704   MDRV_PALETTE_INIT(royalmah)
23042705
23052706   MDRV_SCREEN_ADD("main", 0)
2306   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
2707   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
23072708   MDRV_SCREEN_SIZE(256, 256)
23082709   MDRV_SCREEN_VISIBLE_AREA(0, 255, 0, 255)
23092710   MDRV_SCREEN_REFRESH_RATE(60)
r936r937
23192720
23202721
23212722static MACHINE_DRIVER_START( dondenmj )
2322
2323   /* basic machine hardware */
2324   MDRV_CPU_ADD_TAG("main", Z80, 8000000/2)   /* 4 MHz ? */
2325   MDRV_CPU_PROGRAM_MAP(readmem,writemem)
2326   MDRV_CPU_IO_MAP(dondenmj_readport,dondenmj_writeport)
2327   MDRV_CPU_VBLANK_INT(irq0_line_hold,1)
2328
2329   MDRV_NVRAM_HANDLER(generic_0fill)
2330
2331   /* video hardware */
2332   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
2333   MDRV_VIDEO_UPDATE(royalmah)
2334
2335   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
2336   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
2337   MDRV_SCREEN_SIZE(256, 256)
2338   MDRV_SCREEN_VISIBLE_AREA(0, 255, 0, 255)
2339   MDRV_SCREEN_REFRESH_RATE(60)
2340   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
2341
2342   /* sound hardware */
2343   MDRV_SPEAKER_STANDARD_MONO("mono")
2344
2345   MDRV_SOUND_ADD(AY8910, 18432000/12)
2346   MDRV_SOUND_CONFIG(ay8910_interface)
2347   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.33)
2723   MDRV_IMPORT_FROM(royalmah)
2724   MDRV_CPU_REPLACE("main", Z80, 8000000/2)   /* 4 MHz ? */
2725   MDRV_CPU_IO_MAP(dondenmj_iomap,0)
23482726MACHINE_DRIVER_END
23492727
23502728static void suzume_irq(void)
23512729{
2352   cpunum_set_input_line_and_vector(0, 0, HOLD_LINE, 0xcd1216);
2730   if ( suzume_bank & 0x40 )
2731      cpunum_set_input_line(0, INPUT_LINE_NMI, PULSE_LINE);
23532732}
23542733
23552734static MACHINE_DRIVER_START( suzume )
2356   /* basic machine hardware */
23572735   MDRV_IMPORT_FROM(dondenmj)
23582736   MDRV_CPU_MODIFY("main")
2359   MDRV_CPU_IO_MAP(suzume_readport,suzume_writeport)
2737   MDRV_CPU_IO_MAP(suzume_iomap,0)
23602738   MDRV_CPU_VBLANK_INT(suzume_irq,1)
23612739MACHINE_DRIVER_END
23622740
23632741static MACHINE_DRIVER_START( tontonb )
2364   /* basic machine hardware */
23652742   MDRV_IMPORT_FROM(dondenmj)
23662743   MDRV_CPU_MODIFY("main")
2367   MDRV_CPU_IO_MAP(tontonb_readport,tontonb_writeport)
2744   MDRV_CPU_IO_MAP(tontonb_iomap,0)
23682745MACHINE_DRIVER_END
23692746
23702747static MACHINE_DRIVER_START( mjdiplob )
2371   /* basic machine hardware */
23722748   MDRV_IMPORT_FROM(dondenmj)
23732749   MDRV_CPU_MODIFY("main")
2374   MDRV_CPU_IO_MAP(mjdiplob_readport,mjdiplob_writeport)
2750   MDRV_CPU_IO_MAP(mjdiplob_iomap,0)
23752751MACHINE_DRIVER_END
23762752
23772753static MACHINE_DRIVER_START( majs101b )
2378   /* basic machine hardware */
23792754   MDRV_IMPORT_FROM(dondenmj)
23802755   MDRV_CPU_MODIFY("main")
2381   MDRV_CPU_IO_MAP(majs101b_readport,majs101b_writeport)
2756   MDRV_CPU_IO_MAP(majs101b_iomap,0)
23822757MACHINE_DRIVER_END
23832758
2759static MACHINE_DRIVER_START( mjapinky )
2760   MDRV_IMPORT_FROM(dondenmj)
2761   MDRV_CPU_MODIFY("main")
2762   MDRV_CPU_PROGRAM_MAP(mjapinky_map,0)
2763   MDRV_CPU_IO_MAP(mjapinky_iomap,0)
2764MACHINE_DRIVER_END
2765
23842766static MACHINE_DRIVER_START( mjderngr )
2385   /* basic machine hardware */
23862767   MDRV_IMPORT_FROM(dondenmj)
23872768   MDRV_CPU_MODIFY("main")
2388   MDRV_CPU_IO_MAP(mjderngr_readport,mjderngr_writeport)
2769   MDRV_CPU_IO_MAP(mjderngr_iomap,0)
23892770
23902771   /* video hardware */
2391   MDRV_VIDEO_UPDATE(mjderngr)
2772   MDRV_PALETTE_LENGTH(16*32)
2773   MDRV_PALETTE_INIT(mjderngr)
23922774MACHINE_DRIVER_END
23932775
2394
23952776/* It runs in IM 2, thus needs a vector on the data bus */
2396static INTERRUPT_GEN( janptr96_vblank_interrupt )
2777static INTERRUPT_GEN( janptr96_interrupt )
23972778{
23982779   switch(cpu_getiloops())
23992780   {
r936r937
24042785}
24052786
24062787static MACHINE_DRIVER_START( janptr96 )
2407
2408   /* basic machine hardware */
24092788   MDRV_IMPORT_FROM(mjderngr)
2410
24112789   MDRV_CPU_REPLACE("main",Z80,24000000/4)   /* 6 MHz? */
2412   MDRV_CPU_PROGRAM_MAP(janptr96_readmem,janptr96_writemem)
2413   MDRV_CPU_IO_MAP(janptr96_readport,janptr96_writeport)
2414   MDRV_CPU_VBLANK_INT(janptr96_vblank_interrupt,3)   /* IM 2 needs a vector on the data bus */
2790   MDRV_CPU_PROGRAM_MAP(janptr96_map,0)
2791   MDRV_CPU_IO_MAP(janptr96_iomap,0)
2792   MDRV_CPU_VBLANK_INT(janptr96_interrupt,3)   /* IM 2 needs a vector on the data bus */
24152793
24162794   MDRV_SCREEN_VISIBLE_AREA(0, 255, 9, 255-8)
24172795MACHINE_DRIVER_END
24182796
24192797
24202798static MACHINE_DRIVER_START( mjifb )
2421
2422   /* basic machine hardware */
24232799   MDRV_IMPORT_FROM(mjderngr)
24242800   MDRV_CPU_REPLACE("main",TMP90841, 8000000)   /* ? */
24252801   MDRV_CPU_PROGRAM_MAP(mjifb_map,0)
r936r937
24292805   MDRV_SCREEN_VISIBLE_AREA(0, 255, 8, 255-8)
24302806MACHINE_DRIVER_END
24312807
2432static INTERRUPT_GEN( mjtensin_vblank_interrupt )
2808static INTERRUPT_GEN( mjtensin_interrupt )
24332809{
24342810   switch(cpu_getiloops())
24352811   {
r936r937
24392815}
24402816
24412817static MACHINE_DRIVER_START( mjtensin )
2442
2443   /* basic machine hardware */
24442818   MDRV_IMPORT_FROM(mjderngr)
24452819   MDRV_CPU_REPLACE("main",TMP90841, 12000000)   /* ? */
24462820   MDRV_CPU_PROGRAM_MAP(mjtensin_map,0)
24472821   MDRV_CPU_IO_MAP(mjtensin_iomap,0)
2448   MDRV_CPU_VBLANK_INT( mjtensin_vblank_interrupt,2 )
2822   MDRV_CPU_VBLANK_INT( mjtensin_interrupt,2 )
24492823
24502824   MDRV_SCREEN_VISIBLE_AREA(0, 255, 8, 255-8)
24512825MACHINE_DRIVER_END
24522826
2453static MACHINE_DRIVER_START( mjapinky )
2454   /* basic machine hardware */
2455   MDRV_IMPORT_FROM(dondenmj)
2456   MDRV_CPU_MODIFY("main")
2457   MDRV_CPU_IO_MAP(mjapinky_readport,mjapinky_writeport)
2827static MACHINE_DRIVER_START( cafetime )
2828   MDRV_IMPORT_FROM(mjderngr)
2829   MDRV_CPU_REPLACE("main",TMP90841, 12000000)   /* ? */
2830   MDRV_CPU_PROGRAM_MAP(cafetime_map,0)
2831   MDRV_CPU_IO_MAP(cafetime_iomap,0)
2832   MDRV_CPU_VBLANK_INT(mjtensin_interrupt,2)
2833
2834   MDRV_SCREEN_VISIBLE_AREA(0, 255, 8, 255-8)
24582835MACHINE_DRIVER_END
24592836
2460
24612837/***************************************************************************
24622838
24632839  Game driver(s)
r936r937
27603136   ROM_LOAD( "18s030n.clr",   0x0000, 0x0020, CRC(5736d0aa) SHA1(298b51340d2697347842cfaa5921f31c7b7f9748) )
27613137ROM_END
27623138
3139
3140/***************************************************************************
3141
3142Mahjong Cafe Time
3143(c)1992 Dynax
3144Modified Royal Mahjong PCB
3145D6310128L1-1 (Sub PCB)
3146
3147CPU: Z80
3148Sound: AY-3-8910
3149
3150ROMs:
31516301.2E      [1fc10e7c]
31526302.3E      [02bbdf78]
31536303.5E      [0e71eea8]
31546304.6E      [53c581d6]
3155
3156D63-1.7F     [e7410136] MB7124H
3157D63-2.8F     [af735b42] /
3158
3159***************************************************************************/
3160
3161ROM_START( cafetime )
3162   ROM_REGION( 0x210000, REGION_CPU1, 0 )
3163   ROM_LOAD( "6301.2e", 0x000000, 0x40000, CRC(1fc10e7c) SHA1(0ed6bfd4cc6fc64bbf55bd3c6bde2d8ba9da2afb) )
3164   /* bank switched ROMs follow */
3165   ROM_RELOAD(          0x010000, 0x40000 )
3166   ROM_RELOAD(          0x050000, 0x40000 )
3167   ROM_LOAD( "6302.3e", 0x090000, 0x80000, CRC(02bbdf78) SHA1(e1e107541236ed92854fac4e12c9b300dbac9822) )
3168   ROM_LOAD( "6303.5e", 0x110000, 0x80000, CRC(0e71eea8) SHA1(f95c3b7acee6deabff4aca83b490e255648e2f19) )
3169   ROM_LOAD( "6304.6e", 0x190000, 0x80000, CRC(53c581d6) SHA1(d9cfda63a8f2e92873f69c673d3efe5c22cfa0de) )
3170
3171   ROM_REGION( 0x400, REGION_PROMS, 0 )
3172   ROM_LOAD( "d63-2.8f", 0x000, 0x200, CRC(af735b42) SHA1(deddde3e276d5b9de72e267f65399d80783c6244) )
3173   ROM_LOAD( "d63-1.7f", 0x200, 0x200, CRC(e7410136) SHA1(54d3aec0d11485d4f419e76f9c4071ab9b817937) )
3174ROM_END
3175
3176
27633177static DRIVER_INIT( janptr96 )
27643178{
27653179   generic_nvram_size = 0x1000 * 9;
r936r937
27693183}
27703184
27713185
2772
27733186GAME( 1982, royalmah, 0, royalmah, royalmah, 0,        ROT0, "Falcon",           "Royal Mahjong (Japan)",              0 )
27743187GAME( 1986, dondenmj, 0, dondenmj, majs101b, 0,        ROT0, "Dyna Electronics", "Don Den Mahjong [BET] (Japan)",      0 )
27753188GAME( 1986, suzume,   0, suzume,   suzume,   0,        ROT0, "Dyna Electronics", "Watashiha Suzumechan (Japan)",       0 )
27763189GAME( 1987, mjdiplob, 0, mjdiplob, mjdiplob, 0,        ROT0, "Dynax",            "Mahjong Diplomat [BET] (Japan)",     0 )
27773190GAME( 1987, tontonb,  0, tontonb,  tontonb,  0,        ROT0, "Dynax",            "Tonton [BET] (Japan)",               0 )
27783191GAME( 1988, majs101b, 0, majs101b, majs101b, 0,        ROT0, "Dynax",            "Mahjong Studio 101 [BET] (Japan)",   0 )
2779GAME( 1988, mjapinky, 0, mjapinky, mjapinky, 0,        ROT0, "Dynax",            "Mahjong Almond Pinky [BET] (Japan)", GAME_NOT_WORKING )
3192GAME( 1988, mjapinky, 0, mjapinky, mjapinky, 0,        ROT0, "Dynax",            "Almond Pinky [BET] (Japan)",        0)
27803193GAME( 1989, mjderngr, 0, mjderngr, majs101b, 0,        ROT0, "Dynax",            "Mahjong Derringer (Japan)",          0 )
27813194GAME( 1990, mjifb,    0, mjifb,    mjifb,    0,        ROT0, "Dynax",            "Mahjong If...? [BET]",               0 )
3195GAME( 1992, cafetime, 0, cafetime, cafetime, 0,        ROT0, "Dynax",            "Mahjong Cafe Time",                  0 )
27823196GAME( 1995, mjtensin, 0, mjtensin, mjtensin, 0,        ROT0, "Dynax",            "Mahjong Tensinhai (Japan)",          GAME_NOT_WORKING )
27833197GAME( 1996, janptr96, 0, janptr96, janptr96, janptr96, ROT0, "Dynax",            "Janputer '96 (Japan)",               0 )
src/tools/chdman.c
r936r937
88***************************************************************************/
99
1010#include "osdcore.h"
11#include "corefile.h"
1112#include "chdcd.h"
1213#include "aviio.h"
1314#include "bitmap.h"
r936r937
5253static chd_error chdman_compress_file(chd_file *chd, const char *rawfile, UINT32 offset);
5354static chd_error chdman_compress_chd(chd_file *chd, chd_file *source, UINT32 totalhunks);
5455
55static chd_interface_file *chdman_open(const char *filename, const char *mode);
56static void chdman_close(chd_interface_file *file);
57static UINT32 chdman_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
58static UINT32 chdman_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
59static UINT64 chdman_length(chd_interface_file *file);
6056
6157
62
6358/***************************************************************************
6459    GLOBAL VARIABLES
6560***************************************************************************/
6661
67static chd_interface chdman_interface =
68{
69   chdman_open,
70   chdman_close,
71   chdman_read,
72   chdman_write,
73   chdman_length
74};
75
7662static const char *error_strings[] =
7763{
7864   "no error",
r936r937
216202   printf("   or: chdman -merge parent.chd diff.chd output.chd\n");
217203   printf("   or: chdman -diff parent.chd compare.chd diff.chd\n");
218204   printf("   or: chdman -setchs inout.chd cylinders heads sectors\n");
219   printf("   or: chdman -split input.chd output.chd length\n");
220205   return 1;
221206}
222207
r936r937
456441   UINT32 hunksize = CD_FRAME_SIZE * CD_FRAMES_PER_HUNK;
457442   UINT32 sectorsize = CD_FRAME_SIZE;
458443   const char *inputfile, *outputfile;
459   chd_interface_file *srcfile = NULL;
444   core_file *srcfile = NULL;
460445   UINT32 origtotalsectors;
461446   chd_file *chd = NULL;
462447   UINT8 *cache = NULL;
463448   UINT32 totalsectors;
464449   double ratio = 1.0;
465450   UINT32 totalhunks;
451   file_error filerr;
466452   chd_error err;
467453   int i;
468454
r936r937
557543      int curhunk;
558544
559545      /* open the input file for this track */
560      srcfile = chdman_open(track_info.fname[i], "rb");
561      if (srcfile == NULL)
546      filerr = core_fopen(track_info.fname[i], OPEN_FLAG_READ, &srcfile);
547      if (filerr != FILERR_NONE)
562548      {
563549         fprintf(stderr, "Unable to open file: %s\n", track_info.fname[i]);
564550         err = CHDERR_FILE_NOT_FOUND;
r936r937
582568         {
583569            if (frames < toc.tracks[i].frames)
584570            {
585               chdman_read(srcfile, sourcefileoffset, bytespersector, &cache[secnum * CD_FRAME_SIZE]);
571               core_fseek(srcfile, sourcefileoffset, SEEK_SET);
572               core_fread(srcfile, &cache[secnum * CD_FRAME_SIZE], bytespersector);
586573
587574               if (track_info.swap[i])
588575               {
r936r937
613600      }
614601
615602      /* close the file */
616      chdman_close(srcfile);
603      core_fclose(srcfile);
617604      srcfile = NULL;
618605   }
619606
r936r937
628615   if (cache != NULL)
629616      free(cache);
630617   if (srcfile != NULL)
631      chdman_close(srcfile);
618      core_fclose(srcfile);
632619   if (chd != NULL)
633620      chd_close(chd);
634621   if (err != CHDERR_NONE)
r936r937
11301117static int do_extract(int argc, char *argv[], int param)
11311118{
11321119   const char *inputfile, *outputfile;
1133   chd_interface_file *outfile = NULL;
1120   core_file *outfile = NULL;
11341121   chd_file *infile = NULL;
11351122   const chd_header *header;
11361123   UINT64 bytesremaining;
11371124   void *hunk = NULL;
1125   file_error filerr;
11381126   chd_error err;
11391127   int hunknum;
11401128
r936r937
11691157   }
11701158
11711159   /* create the output file */
1172   outfile = chdman_open(outputfile, "wb");
1173   if (outfile == NULL)
1160   filerr = core_fopen(outputfile, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
1161   if (filerr != FILERR_NONE)
11741162   {
11751163      fprintf(stderr, "Error opening output file '%s'\n", outputfile);
11761164      err = CHDERR_CANT_CREATE_FILE;
r936r937
11961184
11971185      /* write the hunk to the file */
11981186       bytes_to_write = MIN(bytesremaining, header->hunkbytes);
1199      byteswritten = chdman_write(outfile, (UINT64)hunknum * (UINT64)header->hunkbytes, bytes_to_write, hunk);
1187      core_fseek(outfile, (UINT64)hunknum * (UINT64)header->hunkbytes, SEEK_SET);
1188      byteswritten = core_fwrite(outfile, hunk, bytes_to_write);
12001189      if (byteswritten != bytes_to_write)
12011190      {
12021191         fprintf(stderr, "Error writing hunk %d to output file: %s\n", hunknum, error_string(CHDERR_WRITE_ERROR));
r936r937
12091198cleanup:
12101199   /* clean up our mess */
12111200   if (outfile != NULL)
1212      (*chdman_interface.close)(outfile);
1201      core_fclose(outfile);
12131202   if (hunk != NULL)
12141203      free(hunk);
12151204   if (infile != NULL)
r936r937
12281217static int do_extractcd(int argc, char *argv[], int param)
12291218{
12301219   const char *inputfile, *outputfile, *outputfile2;
1231   chd_interface_file *outfile2 = NULL;
1220   core_file *outfile2 = NULL;
12321221   chd_file *inputchd = NULL;
12331222   cdrom_file *cdrom = NULL;
12341223   FILE *outfile = NULL;
12351224   const cdrom_toc *toc;
12361225   UINT64 out2offs;
1226   file_error filerr;
12371227   chd_error err;
12381228   int track;
12391229
r936r937
12801270   }
12811271   fprintf(outfile, "CD_ROM\n\n\n");
12821272
1283   outfile2 = chdman_open(outputfile2, "wb");
1284   if (outfile2 == NULL)
1273   filerr = core_fopen(outputfile2, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile2);
1274   if (filerr != FILERR_NONE)
12851275   {
12861276      fprintf(stderr, "Error opening output file '%s'\n", outputfile2);
12871277      err = CHDERR_CANT_CREATE_FILE;
r936r937
13521342         cdrom_read_data(cdrom, cdrom_get_track_start(cdrom, track) + frame, sector, toc->tracks[track].trktype);
13531343
13541344         /* write it out */
1355         byteswritten = chdman_write(outfile2, out2offs, toc->tracks[track].datasize, sector);
1345         core_fseek(outfile2, out2offs, SEEK_SET);
1346         byteswritten = core_fwrite(outfile2, sector, toc->tracks[track].datasize);
13561347         if (byteswritten != toc->tracks[track].datasize)
13571348         {
13581349            fprintf(stderr, "Error writing frame %d to output file: %s\n", frame, error_string(CHDERR_WRITE_ERROR));
r936r937
13651356         cdrom_read_subcode(cdrom, cdrom_get_track_start(cdrom, track) + frame, sector);
13661357
13671358         /* write it out */
1368         byteswritten = chdman_write(outfile2, out2offs, toc->tracks[track].subsize, sector);
1359         core_fseek(outfile2, out2offs, SEEK_SET);
1360         byteswritten = core_fwrite(outfile2, sector, toc->tracks[track].subsize);
13691361         if (byteswritten != toc->tracks[track].subsize)
13701362         {
13711363            fprintf(stderr, "Error writing frame %d to output file: %s\n", frame, error_string(CHDERR_WRITE_ERROR));
r936r937
13831375   if (outfile != NULL)
13841376      fclose(outfile);
13851377   if (outfile2 != NULL)
1386      chdman_close(outfile2);
1378      core_fclose(outfile2);
13871379   if (cdrom != NULL)
13881380      cdrom_close(cdrom);
13891381   if (inputchd != NULL)
r936r937
23522344
23532345
23542346/*-------------------------------------------------
2355    do_split - split a CHD file into multiple
2356    parts
2357-------------------------------------------------*/
2358
2359static int do_split(int argc, char *argv[], int param)
2360{
2361   const char *infilename, *outfilename;
2362   UINT64 size, srcsize, curoffs = 0;
2363   chd_interface_file *outfile = NULL;
2364   chd_interface_file *infile = NULL;
2365   chd_error err = CHDERR_NONE;
2366   char *curfilename = NULL;
2367   UINT32 numfiles = 0;
2368   UINT32 index;
2369
2370   /* require 5 args total */
2371   if (argc != 5)
2372      return usage();
2373
2374   /* extract the data */
2375   infilename = argv[2];
2376   outfilename = argv[3];
2377   size = (UINT64)atoi(argv[4]) * 1024 * 1024;
2378
2379   /* print some info */
2380   printf("Input file:   %s\n", infilename);
2381   printf("Output file:  %s\n", outfilename);
2382   printf("Split size:   %d MB\n", (UINT32)(size / (1024 * 1024)));
2383
2384   /* open the input file read-only */
2385   infile = chdman_open(infilename, "rb");
2386   if (infile == NULL)
2387   {
2388      fprintf(stderr, "Error opening input file '%s' read-only\n", infilename);
2389      err = CHDERR_FILE_NOT_FOUND;
2390      goto cleanup;
2391   }
2392   srcsize = chdman_length(infile);
2393   numfiles = (srcsize + size - 1) / size;
2394   if (numfiles <= 1)
2395   {
2396      printf("No need to split this file; it is smaller than the split size\n");
2397      return 0;
2398   }
2399
2400   /* allocate a buffer to hold our names */
2401   curfilename = malloc(strlen(outfilename) + 1 + 4);
2402   if (curfilename == NULL)
2403   {
2404      fprintf(stderr, "Unable to allocate temporary filename\n");
2405      err = CHDERR_OUT_OF_MEMORY;
2406      goto cleanup;
2407   }
2408
2409   /* loop until we copy all of the source */
2410   for (index = 0; index < numfiles; index++)
2411   {
2412      UINT64 targetsize = MIN(size, srcsize - curoffs);
2413      UINT64 remaining = targetsize;
2414      UINT64 outoffs = 0;
2415
2416      /* open the appropriate output file */
2417      if (index == 0)
2418         outfile = chdman_open(outfilename, "wb");
2419      else
2420      {
2421         chd_multi_filename(outfilename, curfilename, index - 1);
2422         outfile = chdman_open(curfilename, "wb");
2423      }
2424
2425      /* if we fail, bail */
2426      if (outfile == NULL)
2427      {
2428         fprintf(stderr, "Error opening output file '%s'\n", (index == 0) ? outfilename : curfilename);
2429         err = CHDERR_CANT_CREATE_FILE;
2430         goto cleanup;
2431      }
2432
2433      /* loop until we've copied everything */
2434      while (remaining > 0)
2435      {
2436         UINT8 buffer[16384];
2437         UINT32 bytes_to_copy = MIN(sizeof(buffer), remaining);
2438         UINT32 bytes_read, bytes_written;
2439
2440         /* progress */
2441         progress(FALSE, "Writing file %d/%d ... %d%%    \r",
2442                (UINT32)index + 1, (UINT32)((srcsize + size - 1) / size),
2443                100 - (UINT32)(remaining * 100 / targetsize));
2444
2445         /* read a chunk */
2446         bytes_read = chdman_read(infile, curoffs, bytes_to_copy, buffer);
2447         if (bytes_read != bytes_to_copy)
2448         {
2449            fprintf(stderr, "Error reading %d bytes from offset %08X%08X\n", bytes_to_copy, (UINT32)(curoffs >> 32), (UINT32)curoffs);
2450            err = CHDERR_READ_ERROR;
2451            goto cleanup;
2452         }
2453
2454         /* write a chunk */
2455         bytes_written = chdman_write(outfile, outoffs, bytes_to_copy, buffer);
2456         if (bytes_written != bytes_to_copy)
2457         {
2458            fprintf(stderr, "Error writing %d bytes to offset %08X%08X\n", bytes_to_copy, (UINT32)(outoffs >> 32), (UINT32)outoffs);
2459            err = CHDERR_WRITE_ERROR;
2460            goto cleanup;
2461         }
2462
2463         /* advance our counters */
2464         curoffs += bytes_read;
2465         outoffs += bytes_written;
2466         remaining -= bytes_read;
2467      }
2468
2469      /* all done; close the file */
2470      chdman_close(outfile);
2471      outfile = NULL;
2472   }
2473   progress(TRUE, "File successfully split              \n");
2474
2475cleanup:
2476   if (infile != NULL)
2477      chdman_close(infile);
2478   if (outfile != NULL)
2479      chdman_close(outfile);
2480   if (curfilename != NULL)
2481      free(curfilename);
2482   if (err != CHDERR_NONE)
2483      for (index = 0; index < numfiles; index++)
2484      {
2485         if (index == 0)
2486            osd_rmfile(outfilename);
2487         else
2488         {
2489            chd_multi_filename(outfilename, curfilename, index - 1);
2490            osd_rmfile(curfilename);
2491         }
2492      }
2493   return (err != CHDERR_NONE);
2494}
2495
2496
2497/*-------------------------------------------------
24982347    chdman_compress_file - compress a regular
24992348    file via the compression interfaces
25002349-------------------------------------------------*/
25012350
25022351static chd_error chdman_compress_file(chd_file *chd, const char *rawfile, UINT32 offset)
25032352{
2504   chd_interface_file *sourcefile;
2353   core_file *sourcefile;
25052354   const chd_header *header;
25062355   UINT64 sourceoffset = 0;
25072356   UINT8 *cache = NULL;
25082357   double ratio = 1.0;
2358   file_error filerr;
25092359   chd_error err;
25102360   int hunknum;
25112361
25122362   /* open the raw file */
2513   sourcefile = chdman_open(rawfile, "rb");
2514   if (sourcefile == NULL)
2363   filerr = core_fopen(rawfile, OPEN_FLAG_READ, &sourcefile);
2364   if (filerr != FILERR_NONE)
25152365   {
25162366      err = CHDERR_FILE_NOT_FOUND;
25172367      goto cleanup;
r936r937
25402390      progress(hunknum == 0, "Compressing hunk %d/%d... (ratio=%d%%)  \r", hunknum, header->totalhunks, (int)(100.0 * ratio));
25412391
25422392      /* read the data */
2543      bytesread = chdman_read(sourcefile, sourceoffset + offset, header->hunkbytes, cache);
2393      core_fseek(sourcefile, sourceoffset + offset, SEEK_SET);
2394      bytesread = core_fread(sourcefile, cache, header->hunkbytes);
25442395      if (bytesread < header->hunkbytes)
25452396         memset(&cache[bytesread], 0, header->hunkbytes - bytesread);
25462397
r936r937
25632414
25642415cleanup:
25652416   if (sourcefile != NULL)
2566      chdman_close(sourcefile);
2417      core_fclose(sourcefile);
25672418   if (cache != NULL)
25682419      free(cache);
25692420   return err;
r936r937
27292580
27302581
27312582/*-------------------------------------------------
2732    chdman_open - open file
2733-------------------------------------------------*/
2734
2735static chd_interface_file *chdman_open(const char *filename, const char *mode)
2736{
2737   file_error filerr;
2738   chd_interface_file *file;
2739   UINT32 openflags = 0;
2740   int open_or_create = 0;
2741
2742   switch(*mode++)
2743   {
2744      case 'r':
2745         openflags |= OPEN_FLAG_READ;
2746         if (*mode == 'b')
2747            mode++;
2748         if (*mode == '+')
2749         {
2750            openflags |= OPEN_FLAG_WRITE;
2751            open_or_create = 1;
2752         }
2753         break;
2754
2755      case 'w':
2756         openflags |= OPEN_FLAG_WRITE | OPEN_FLAG_CREATE;
2757         if (*mode == 'b')
2758            mode++;
2759         if (*mode == '+')
2760            openflags |= OPEN_FLAG_READ;
2761         break;
2762
2763      default:
2764         return NULL;
2765   }
2766
2767   file = malloc(sizeof(*file));
2768   if (!file)
2769      goto error;
2770
2771   /* first try to open without creating */
2772   filerr = osd_open(filename, openflags, &file->file, &file->length);
2773   if (filerr != FILERR_NONE)
2774   {
2775      if (open_or_create)
2776         filerr = osd_open(filename, openflags | OPEN_FLAG_CREATE, &file->file, &file->length);
2777      if (filerr != FILERR_NONE)
2778         goto error;
2779   }
2780
2781   return file;
2782error:
2783   if (file)
2784      free(file);
2785   return NULL;
2786}
2787
2788
2789/*-------------------------------------------------
2790    chdman_close - close file
2791-------------------------------------------------*/
2792
2793static void chdman_close(chd_interface_file *file)
2794{
2795   osd_close(file->file);
2796   free(file);
2797}
2798
2799
2800/*-------------------------------------------------
2801    chdman_read - read from an offset
2802-------------------------------------------------*/
2803
2804static UINT32 chdman_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
2805{
2806   UINT32 actual;
2807   osd_read(file->file, buffer, offset, count, &actual);
2808   return actual;
2809}
2810
2811
2812/*-------------------------------------------------
2813    chdman_write - write to an offset
2814-------------------------------------------------*/
2815
2816static UINT32 chdman_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
2817{
2818   UINT32 actual;
2819   osd_write(file->file, buffer, offset, count, &actual);
2820   return actual;
2821}
2822
2823
2824/*-------------------------------------------------
2825    chdman_length - return the current EOF
2826-------------------------------------------------*/
2827
2828static UINT64 chdman_length(chd_interface_file *file)
2829{
2830   return file->length;
2831}
2832
2833
2834/*-------------------------------------------------
28352583    main - entry point
28362584-------------------------------------------------*/
28372585
r936r937
28602608      { "-info",         do_info, 0 },
28612609      { "-merge",         do_merge_update_chomp, OPERATION_MERGE },
28622610      { "-diff",         do_diff, 0 },
2863      { "-setchs",      do_setchs, 0 },
2864      { "-split",         do_split, 0 },
2611      { "-setchs",      do_setchs, 0 }
28652612   };
28662613   extern char build_version[];
28672614   int i;
r936r937
28732620   if (argc < 2)
28742621      return usage();
28752622
2876   /* set the interface for everyone */
2877   chd_set_interface(&chdman_interface);
2878
28792623   /* handle the appropriate command */
28802624   for (i = 0; i < ARRAY_LENGTH(option_list); i++)
28812625      if (strcmp(argv[1], option_list[i].option) == 0)
src/osd/windows/windows.mak
r936r937
140140# Windows-specific debug objects and flags
141141#-------------------------------------------------
142142
143# define the x64 ABI to be Windows
144DEFS += -DX64_WINDOWS_ABI
145
143146# map all instances of "main" to "utf8_main"
144147DEFS += -Dmain=utf8_main
145148
r936r937
265268
266269ledutil$(EXE): $(WINOBJ)/ledutil.o $(LIBOCORE)
267270   @echo Linking $@...
268   $(LD) $(LDFLAGS) $(OSDBGLDFLAGS) $^ $(LIBS) -o $@
271   $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
269272
270273TOOLS += ledutil$(EXE)
271274
r936r937
277280
278281VERINFO = $(WINOBJ)/verinfo$(EXE)
279282
280$(VERINFO): $(WINOBJ)/verinfo.o $(VERSIONOBJ) $(LIBOCORE)
283$(VERINFO): $(WINOBJ)/verinfo.o $(LIBOCORE)
281284   @echo Linking $@...
282   $(LD) $(LDFLAGS) $(OSDBGLDFLAGS) $^ $(LIBS) -o $@
285   $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
283286
284287BUILD += $(VERINFO)
285288
r936r937
299302# rules for resource file
300303#-------------------------------------------------
301304
302$(WINOBJ)/mame.res: $(WINSRC)/mame.rc $(WINOBJ)/mamevers.rc
305$(RESFILE): $(WINSRC)/mame.rc $(WINOBJ)/mamevers.rc
303306
304$(WINOBJ)/mamevers.rc: $(VERINFO)
307$(WINOBJ)/mamevers.rc: $(VERINFO) $(SRC)/version.c
305308   @echo Emitting $@...
306   @$(VERINFO) > $@
309   @$(VERINFO) $(SRC)/version.c > $@
src/osd/windows/drawdd.c
r936r937
303303static const render_primitive_list *drawdd_window_get_primitives(win_window_info *window)
304304{
305305   dd_info *dd = window->drawdata;
306
306307   compute_blit_surface_size(window);
307308   render_target_set_bounds(window->target, dd->blitwidth, dd->blitheight, 0);
309   render_target_set_max_update_rate(window->target, (dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh);
310
308311   return render_target_get_primitives(window->target);
309312}
310313
src/osd/windows/drawd3d.c
r936r937
532532
533533static const render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
534534{
535   d3d_info *d3d = window->drawdata;
535536   RECT client;
537
536538   GetClientRect(window->hwnd, &client);
537539   if (rect_width(&client) > 0 && rect_height(&client) > 0)
540   {
538541      render_target_set_bounds(window->target, rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor));
542      render_target_set_max_update_rate(window->target, (d3d->refresh == 0) ? d3d->origmode.RefreshRate : d3d->refresh);
543   }
539544   return render_target_get_primitives(window->target);
540545}
541546
src/emu/romload.h
r936r937
282282***************************************************************************/
283283
284284/* disk handling */
285chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, chd_file **image);
285chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd);
286286chd_file *get_disk_handle(int diskindex);
287287
288288/* ROM processing */
src/emu/debug/express.c
r936r937
11611161   /* create a temporary token for holding intermediate number and memory values */
11621162   tempnum.type = TOK_NUMBER;
11631163   tempnum.offset = 0;
1164   tempnum.info = 0;
11641165   tempmem.type = TOK_MEMORY;
11651166   tempmem.offset = 0;
1167   tempmem.info = 0;
11661168
11671169   /* loop over the entire sequence */
11681170   for (tokindex = 0; expr->token[tokindex].type != TOK_END; tokindex++)
src/emu/cpu/h83002/h8disasm.c
r936r937
124124   UINT16 data16;
125125   INT16 sdata16;
126126   INT32 sdata32;
127   UINT16 ext16;
127128
128129   switch((opcode>>8)&0xf)
129130   {
r936r937
208209            size = 6;
209210            break;
210211         case 0x78:
211            // prefix for
212            // mov.l (@aa:x, rx), Rx
213            data16 = h8_mem_read16(4);
214            // 24 bit abs ?
215            if((data16 & 0x20 )==0x20)
212            // mov.l @(displ24 + Rs), rd
213            size = 10;
214            ext16 = h8_mem_read16(4);
215            sdata32 = h8_mem_read32(6) & 0xffffff;
216            if ( (data16 & 0x80) && ((ext16 & ~7) == 0x6ba0) )
216217            {
217               sdata32 = h8_mem_read32(6);
218               sdata32 &= 0xffffff;
219               size = 10;
218               sprintf(output, "%4.4x mov.l %s,@(%x, %s)", opcode, reg_names32[ext16&7], sdata32, reg_names32[(data16>>4)&7]);
220219            }
221            else
220            else if ( (!(data16 & 0x80)) && ((ext16 & ~7) == 0x6b20) )
222221            {
223               sdata16 = h8_mem_read16(6);
224               sdata32 = sdata16;
225               size = 8;
222               sprintf(output, "%4.4x mov.l @(%x, %s), %s", opcode, sdata32, reg_names32[(data16>>4)&7], reg_names32[ext16&7]);
226223            }
227            if((data16 & 0x80)== 0x80)
228            {
229               sprintf(output, "%4.4x %x mov.l %s, @%x", opcode, data16, reg_names32[data16&7], sdata32);
230            }
231224            else
232225            {
233               sprintf(output, "%4.4x %x mov.l @%x, %s", opcode, data16, sdata32, reg_names32[data16&7]);
226               sprintf(output, "%4.4x ? %x", opcode, data16);
234227            }
235228            break;
229
236230         default:
237231            sprintf(output, "%4.4x ? %x", opcode, data16);
238232            break;
r936r937
11451139      {
11461140         if(((data16>>4) & 0xf) == 0xa)
11471141         {
1148            sprintf(output, "%4.4x mov.w %s, @(%x, %s)", opcode, reg_names16[(data16 & 0xf)], data32, reg_names32[opcode&7]);
1142            sprintf(output, "%4.4x mov.w %s, @(%x, %s)", opcode, reg_names16[(data16 & 0xf)], data32, reg_names32[(opcode>>4)&7]);
11491143         }
11501144         else
11511145         {
src/emu/cpu/h83002/h83002.c
r936r937
121121static INT8 h8_neg8(INT8 src);
122122static INT16 h8_neg16(INT16 src);
123123
124static UINT16 h8_divxu8 (UINT16 dst, UINT8  src);
124125static UINT32 h8_divxu16(UINT32 dst, UINT16 src);
125126
126127static UINT8 h8_not8(UINT8 src);
r936r937
138139
139140static UINT8 h8_shll8(UINT8 src);
140141static UINT16 h8_shll16(UINT16 src);
142static UINT32 h8_shll32(UINT32 src);
143
141144static UINT8 h8_shlr8(UINT8 src);
142145static UINT16 h8_shlr16(UINT16 src);
143146static UINT32 h8_shlr32(UINT32 src);
r936r937
462465   {
463466      h8.ppc = h8.pc;
464467
468#ifdef MAME_DEBUG
465469      CALL_MAME_DEBUG;
466
470#endif
467471      opcode = cpu_readop16(h8.pc);
468472//      mame_printf_debug("[%06x]: %04x => %x\n", h8.pc, opcode, (opcode>>12)&0xf);
469473      h8.pc += 2;
r936r937
711715            address24 += sdata16;
712716            H8_IFETCH_TIMING(3);
713717            H8_WORD_TIMING(2, address24);
714            if(opcode & 0x80)
718            if(ext16 & 0x80)
715719            {
716720               udata32 = h8_getreg32(ext16 & 0x7);
717721               h8_mem_write32(address24, udata32);
r936r937
726730         case 0x78:
727731            // prefix for
728732            // mov.l (@aa:x, rx), Rx
733            //00000A10 010078606B2600201AC2 MOV.L   @($00201AC2,ER6),ER6
734            // mov.l @(displ24 + Rs), rd
735            srcreg = (ext16 >> 4) & 7;
729736
730            //00000A10 010078606B2600201AC2 MOV.L   @($00201AC2,ER6),ER6
731            if((ext16&0xf)==0)
737            // 6b20
738            udata16 = h8_mem_read16(h8.pc);
739            h8.pc += 2;
740            dstreg = udata16 & 7;
741
742            address24 = h8_mem_read32(h8.pc);
743            h8.pc += 4;
744            address24 += h8_getreg32(srcreg);
745            address24 &= 0xffffff;
746
747            if ( (ext16 & 0x80) && ((udata16 & ~7) == 0x6ba0) )
732748            {
733               address24 = h8_getreg32((ext16>>4) & 0x7);
734               ext16=h8_mem_read16(h8.pc);
735               h8.pc += 2;
736               if((ext16&0xfff0) == 0x6b20)
737               {
738                  udata32=h8_mem_read32(h8.pc);
739                  h8.pc += 4;
740                  udata32+=address24;
741                  udata32=h8_mem_read32(udata32);
742
743                  h8.h8zflag = (udata32==0)?1:0;
744                  h8.h8nflag = (udata32&0x80000000)?1:0;
745                  h8.h8vflag = 0;
746                  h8_setreg32(ext16 & 0x7, udata32);
747                  H8_IOP_TIMING(14);
748                  break;
749               }
749               udata32 = h8_getreg32(dstreg);
750               h8_mem_write32(address24, udata32);
750751            }
752            else if ( (!(ext16 & 0x80)) && ((udata16 & ~7) == 0x6b20) )
753            {
754               udata32 = h8_mem_read32(address24);
755               h8_setreg32(dstreg, udata32);
756            }
757            else
758            {
759               h8.h8err = 1;
760            }
751761
752            h8.h8err = 1;
762            h8_mov32(udata32);
753763
764            H8_IFETCH_TIMING(5);
765            H8_WORD_TIMING(2, address24);
766
754767            break;
755768         default:
756769            h8.h8err = 1;
r936r937
10561069         h8_setreg16(opcode & 0xf, udata16);
10571070         H8_IFETCH_TIMING(1);
10581071         break;
1072      case 0x3:
1073         // shal.l Rx
1074         udata32 = h8_getreg32(opcode & 0x7);
1075         udata32 = h8_shll32(udata32);
1076         h8_setreg32(opcode & 0x7, udata32);
1077         H8_IFETCH_TIMING(1);
1078         break;
1079
10591080      case 0x8:
10601081         // shal.b Rx
10611082         udata8 = h8_getreg8(opcode & 0xf);
r936r937
10701091         h8_setreg16(opcode & 0xf, udata16);
10711092         H8_IFETCH_TIMING(1);
10721093         break;
1073         // shal.l Rx
1094
10741095      default:
10751096         logerror("H8/3002: Unk. group 1 0 %x\n", opcode);
10761097         h8.h8err = 1;
r936r937
12371258         h8_setreg16(dstreg, udata16);
12381259         H8_IFETCH_TIMING(1);
12391260         break;
1261
1262      case 0x5:
1263         // extu.w Rx
1264         dstreg = opcode & 0xf;
1265         udata16 = h8_getreg16(dstreg) & 0x00ff;
1266         h8_setreg16(dstreg, udata16);
1267         h8.h8nflag = 0;
1268         h8.h8vflag = 0;
1269         h8.h8zflag = ((udata16 == 0) ? 1 : 0);
1270         H8_IFETCH_TIMING(1);
1271         break;
12401272      case 0x7:
12411273         // extu.l Rx
1242         dstreg = opcode & 0xf;
1243         h8_setreg32(dstreg, h8_getreg32(dstreg) & 0xffff);
1274         dstreg = opcode & 0x7;
1275         udata32 = h8_getreg32(dstreg) & 0x0000ffff;
1276         h8_setreg32(dstreg, udata32);
1277         h8.h8nflag = 0;
1278         h8.h8vflag = 0;
1279         h8.h8zflag = ((udata32 == 0) ? 1 : 0);
12441280         H8_IFETCH_TIMING(1);
12451281         break;
12461282      case 0x8:
r936r937
13761412         h8_setreg16(dstreg, udata16);
13771413         H8_IFETCH_TIMING(1);
13781414         break;
1415      case 0xf:   // dec.l #2, rN
1416         dstreg = opcode & 0x7;
1417         udata32 = h8_dec32(h8_getreg32(dstreg));
1418         if (h8.h8vflag)
1419         {
1420            udata32 = h8_dec32(udata32);
1421            h8.h8vflag = 1;
1422         }
1423         else
1424            udata32 = h8_dec32(udata32);
1425         h8_setreg32(dstreg, udata32);
1426         H8_IFETCH_TIMING(1);
1427         break;
1428
13791429      default:
13801430         logerror("H8/3002: Unk. group 1 B %x\n", opcode);
13811431         h8.h8err = 1;
r936r937
13921442      h8_cmp16(h8_getreg16((opcode>>4) &0xf), h8_getreg16(opcode & 0xf));
13931443      H8_IFETCH_TIMING(1);
13941444      break;
1445   case 0xe:
1446      // subx.b rx, ry
1447      dstreg = opcode & 0xf;
1448      udata8 = h8_subx8(h8_getreg8((opcode>>4) &0xf), h8_getreg8(dstreg));
1449      h8_setreg8(dstreg, udata8);
1450      H8_IFETCH_TIMING(1);
1451      break;
13951452   case 0xf:
13961453      if(opcode & 0x80)
13971454      {
r936r937
14351492      H8_IFETCH_TIMING(1);
14361493      H8_IOP_TIMING(12);
14371494      break;
1495   case 0x1:
14381496      // divxu.b
1497      udata8 = h8_getreg8((opcode>>4)&0xf);
1498      udata16 = h8_getreg16(opcode & 0x0f);
1499      udata16 = h8_divxu8(udata16,udata8);
1500      h8_setreg16(opcode & 0xf, udata16);
1501      H8_IFETCH_TIMING(1);
1502      H8_IOP_TIMING(12);
1503      break;
14391504   case 0x2:
14401505      // mulxu.w
14411506      udata16 = h8_getreg16((opcode>>4)&0xf);
r936r937
15721637      address24 &= 0xffffff;
15731638      // extended mode stack push!
15741639      h8_setreg32(H8_SP, h8_getreg32(H8_SP)-4);
1575      h8_mem_write32(h8_getreg32(H8_SP), h8.pc+2);
1640      h8_mem_write32(h8_getreg32(H8_SP), h8.pc);
15761641      h8.pc = address24;
15771642      change_pc(h8.pc);
15781643      H8_STACK_TIMING(2);
r936r937
19462011      }
19472012      break;
19482013   case 0x8:
1949      udata16 = h8_mem_read16(h8.pc);
2014      ext16 = h8_mem_read16(h8.pc);
19502015      h8.pc += 2;
19512016      udata32 = h8_mem_read32(h8.pc);
19522017      h8.pc += 4;
19532018
1954      if(((udata16>>8) & 0xf) == 0xa)
2019      if(((ext16>>8) & 0xf) == 0xa)
19552020      {
1956         if(((udata16>>4) & 0xf) == 0xa)
2021         if(((ext16>>4) & 0xf) == 0xa)
19572022         {
1958            udata8 = h8_getreg8(udata16 & 0xf);
2023            udata8 = h8_getreg8(ext16 & 0xf);
19592024            h8_mov8(udata8); // update flags !
19602025            udata32 += h8_getreg32((opcode >> 4) & 7);
19612026            h8_mem_write8(udata32, udata8);
r936r937
19652030            udata32 += h8_getreg32((opcode >> 4) & 7);
19662031            udata8 = h8_mem_read8(udata32);
19672032            h8_mov8(udata8); // update flags !
1968            h8_setreg8(udata16 & 0xf, udata8);
2033            h8_setreg8(ext16 & 0xf, udata8);
19692034         }
19702035         H8_BYTE_TIMING(1, udata32);
19712036         H8_IFETCH_TIMING(4);
19722037      }
1973      else if (((udata16>>8) & 0xff) == 0x6b) // mov.w @(24-bit direct, rN), rM
2038      else if ((ext16 & 0xfff0) == 0x6b20) // mov.w @(24-bit direct, rN), rM
19742039      {
19752040         udata32 += h8_getreg32((opcode >> 4) & 7);
19762041         udata16 = h8_mem_read16(udata32);
2042         h8_setreg16(ext16 & 0xf, udata16);
19772043         h8_mov16(udata16); // update flags !
1978         h8_setreg16(udata16 & 0xf, udata16);
1979
1980         H8_BYTE_TIMING(1, udata32);
2044         H8_WORD_TIMING(1, udata32);
19812045         H8_IFETCH_TIMING(4);
19822046      }
2047      else if ((ext16 & 0xfff0) == 0x6ba0) // mov.w rM, @(24-bit direct, rN)
2048      {
2049         udata32 += h8_getreg32((opcode >> 4) & 7);
2050         udata16 = h8_getreg16(ext16 & 0xf);
2051         h8_mem_write16(udata32, udata16);
2052         h8_mov16(udata16); // update flags !
2053         H8_WORD_TIMING(1, udata32);
2054         H8_IFETCH_TIMING(4);
2055      }
19832056      else
19842057      {
19852058         logerror("H8/3002: Unk. group 7 8 %x\n", opcode);
19862059         h8.h8err = 1;
19872060      }
19882061      break;
2062
2063
19892064      // xxx.w #aa:16, rd
19902065   case 0x9:
19912066      if( ((opcode>>4) & 0xf) > 0x6)
r936r937
20732148      break;
20742149      // bxx.b #xx:3, @rd
20752150   case 0xc:
2151      {
2152         UINT8 bitnr;
2153
2154         address24 = h8_getreg32((opcode>>4) & 0x7);
2155         udata8 = h8_mem_read8(address24);
2156         H8_BYTE_TIMING(1, address24);
2157
2158         ext16 = h8_mem_read16(h8.pc);
2159         h8.pc += 2;
2160         H8_IFETCH_TIMING(2);
2161
2162         switch(ext16>>8)
2163         {
2164            // BTST Rn,@ERd
2165            case 0x63:
2166               srcreg = (ext16>>4)&0xf;
2167               bitnr = h8_getreg8(srcreg)&7;
2168               h8_btst8(bitnr, udata8);
2169               break;
2170            // btst.b #imm, @Rn
2171            case 0x73:
2172               bitnr = (ext16>>4)&7;
2173               h8_btst8(bitnr, udata8);
2174               break;
2175            default:
2176               h8.h8err=1;
2177         }
2178      }
2179      break;
20762180   case 0xd:
20772181      {
20782182         UINT8 bitnr;
r936r937
20882192            {
20892193               // bset.b #imm, @Rn
20902194               case 0x70: udata8 = h8_bset8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24); break;
2091               // bnot.b #imm, @Rn
2092               case 0x71: udata8 = h8_bnot8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24); break;
20932195               // bclr.b #imm, @Rn
20942196               case 0x72: udata8 = h8_bclr8(bitnr, udata8); h8_mem_write8(address24, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(2, address24); break;
2095               // btst.b #imm, @Rn
2096               case 0x73: h8_btst8(bitnr, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24); break;
2097               // bxor.b #imm, @Rn
2098               case 0x75: h8_bxor8(bitnr, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24); break;
2099               // bld.b #imm, @Rn
2100               case 0x77: h8_bld8(bitnr, udata8); H8_IFETCH_TIMING(2); H8_BYTE_TIMING(1, address24); break;
21012197               default:
21022198               h8.h8err=1;
21032199               logerror("H8/3002: Unk. group 7 cd-1 %x (%x)\n", opcode, (sdata16>>4)&7);
r936r937
30713167   return res;
30723168}
30733169
3170static UINT32 h8_shll32(UINT32 src)
3171{
3172   UINT32 res;
3173   h8.h8cflag = (src>>31) & 1;
3174   res = src<<1;
3175   // N and Z modified
3176   h8.h8nflag = (res>>31) & 1;
3177   h8.h8vflag = 0;
3178
3179   // zflag
3180   if(res==0)
3181   {
3182      h8.h8zflag = 1;
3183   }
3184   else
3185   {
3186      h8.h8zflag = 0;
3187   }
3188
3189   return res;
3190}
3191
30743192static UINT8 h8_shlr8(UINT8 src)
30753193{
30763194   UINT8 res;
r936r937
34733591
34743592}
34753593
3594static UINT16 h8_divxu8(UINT16 dst, UINT8 src)
3595{
3596   UINT8 remainder, quotient;
3597   UINT16 res = 0;
3598   // N and Z modified
3599   h8.h8nflag = (src>>7)&1;
3600   // zflag
3601   if(src==0)
3602   {
3603      h8.h8zflag = 1;
3604      // dont do anything on division by zero !
3605   }
3606   else
3607   {
3608      h8.h8zflag = 0;
3609      quotient = dst / src;
3610      remainder = dst % src;
3611      res = (remainder << 8) | quotient;
3612   }
3613   return res;
3614}
3615
34763616static UINT32 h8_divxu16(UINT32 dst, UINT16 src)
34773617{
34783618   UINT16 remainder, quotient;
r936r937
36493789   // Interface functions and variables
36503790   case CPUINFO_PTR_SET_INFO:               info->setinfo     = h8_set_info;            break;
36513791   case CPUINFO_PTR_GET_CONTEXT:            info->getcontext  = h8_get_context;            break;
3652   case CPUINFO_PTR_SET_CONTEXT:            info->setcontext  = h8_set_context;            break;
3792   case CPUINFO_PTR_SET_CONTEXT:            info->setcontext= h8_set_context;            break;
36533793   case CPUINFO_PTR_INIT:                  info->init        = h8_init;               break;
36543794   case CPUINFO_PTR_RESET:                  info->reset       = h8_reset;               break;
36553795   case CPUINFO_PTR_EXIT:                  info->exit        = 0;                     break;
r936r937
37073847   case CPUINFO_STR_REGISTER + H8_PC:         sprintf(info->s, "PC   :%08x", h8.pc);         break;
37083848   case CPUINFO_STR_REGISTER + H8_CCR:         sprintf(info->s, "CCR  :%08x", h8_get_ccr());   break;
37093849
3710   case CPUINFO_STR_REGISTER + H8_E0:         sprintf(info->s, "E0   :%08x", h8.regs[0]);      break;
3711   case CPUINFO_STR_REGISTER + H8_E1:         sprintf(info->s, "E1   :%08x", h8.regs[1]);      break;
3712   case CPUINFO_STR_REGISTER + H8_E2:         sprintf(info->s, "E2   :%08x", h8.regs[2]);      break;
3713   case CPUINFO_STR_REGISTER + H8_E3:         sprintf(info->s, "E3   :%08x", h8.regs[3]);      break;
3714   case CPUINFO_STR_REGISTER + H8_E4:         sprintf(info->s, "E4   :%08x", h8.regs[4]);      break;
3715   case CPUINFO_STR_REGISTER + H8_E5:         sprintf(info->s, "E5   :%08x", h8.regs[5]);      break;
3716   case CPUINFO_STR_REGISTER + H8_E6:         sprintf(info->s, "E6   :%08x", h8.regs[6]);      break;
3717   case CPUINFO_STR_REGISTER + H8_E7:         sprintf(info->s, "SP   :%08x", h8.regs[7]);      break;
3850   case CPUINFO_STR_REGISTER + H8_E0:         sprintf(info->s, "ER0  :%08x", h8.regs[0]);      break;
3851   case CPUINFO_STR_REGISTER + H8_E1:         sprintf(info->s, "ER1  :%08x", h8.regs[1]);      break;
3852   case CPUINFO_STR_REGISTER + H8_E2:         sprintf(info->s, "ER2  :%08x", h8.regs[2]);      break;
3853   case CPUINFO_STR_REGISTER + H8_E3:         sprintf(info->s, "ER3  :%08x", h8.regs[3]);      break;
3854   case CPUINFO_STR_REGISTER + H8_E4:         sprintf(info->s, "ER4  :%08x", h8.regs[4]);      break;
3855   case CPUINFO_STR_REGISTER + H8_E5:         sprintf(info->s, "ER5  :%08x", h8.regs[5]);      break;
3856   case CPUINFO_STR_REGISTER + H8_E6:         sprintf(info->s, "ER6  :%08x", h8.regs[6]);      break;
3857   case CPUINFO_STR_REGISTER + H8_E7:         sprintf(info->s, " SP  :%08x", h8.regs[7]);      break;
37183858   }
37193859}
src/emu/cpu/cpu.mak
r936r937
1818# Dynamic recompiler objects
1919#-------------------------------------------------
2020
21ifdef PTR64
22
23DRCOBJ = $(CPUOBJ)/x64drc.o
24
25DRCDEPS =    $(CPUSRC)/x86emit.h \
26         $(CPUSRC)/x64drc.c \
27         $(CPUSRC)/x64drc.h \
28
29$(DRCOBJ): $(DRCDEPS)
30
31else
32
2133DRCOBJ = $(CPUOBJ)/x86drc.o
2234
2335DRCDEPS =    $(CPUSRC)/x86drc.c \
r936r937
2537
2638$(DRCOBJ): $(DRCDEPS)
2739
40endif
2841
2942
3043#-------------------------------------------------
r936r937
10641077#-------------------------------------------------
10651078
10661079CPUDEFS += -DHAS_PPC403=$(if $(filter PPC403,$(CPUS)),1,0)
1080CPUDEFS += -DHAS_PPC601=$(if $(filter PPC601,$(CPUS)),1,0)
10671081CPUDEFS += -DHAS_PPC602=$(if $(filter PPC602,$(CPUS)),1,0)
10681082CPUDEFS += -DHAS_PPC603=$(if $(filter PPC603,$(CPUS)),1,0)
10691083CPUDEFS += -DHAS_MPC8240=$(if $(filter MPC8240,$(CPUS)),1,0)
10701084
1071ifneq ($(filter PPC403 PPC602 PPC603 MPC8240,$(CPUS)),)
1085ifneq ($(filter PPC403 PPC601 PPC602 PPC603 MPC8240,$(CPUS)),)
10721086OBJDIRS += $(CPUOBJ)/powerpc
10731087DBGOBJS += $(CPUOBJ)/powerpc/ppc_dasm.o
10741088
src/emu/cpu/powerpc/ppc.c
r936r937
44#include "ppc.h"
55#include "debugger.h"
66
7#if (HAS_PPC603)
7#if (HAS_PPC603 || HAS_PPC601)
88void ppc603_exception(int exception);
99#endif
1010#if (HAS_PPC602)
r936r937
247247   FPR   fpr[32];
248248   UINT32 sr[16];
249249
250#if HAS_PPC603
250#if HAS_PPC603 || HAS_PPC601
251251   int is603;
252252#endif
253253#if HAS_PPC602
r936r937
315315
316316INLINE int IS_PPC603(void)
317317{
318#if HAS_PPC603
318#if HAS_PPC603 || HAS_PPC601
319319   return ppc.is603;
320320#else
321321   return 0;
r936r937
478478      case SPR_PVR:      return;
479479   }
480480
481#if (HAS_PPC603 || HAS_PPC602)
481#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601)
482482   if(IS_PPC602() || IS_PPC603()) {
483483      switch(spr)
484484      {
r936r937
490490               if (IS_PPC602())
491491                  ppc602_exception(EXCEPTION_DECREMENTER);
492492#endif
493#if HAS_PPC603
493#if HAS_PPC603 || HAS_PPC601
494494               if (IS_PPC603())
495495                  ppc603_exception(EXCEPTION_DECREMENTER);
496496#endif
r936r937
689689   }
690690#endif
691691
692#if (HAS_PPC603 || HAS_PPC602)
692#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601)
693693   if (IS_PPC603() || IS_PPC602())
694694   {
695695      switch (spr)
r936r937
831831#include "ppc602.c"
832832#endif
833833
834#if (HAS_PPC603)
834#if (HAS_PPC603 || HAS_PPC601)
835835#include "ppc603.c"
836836#endif
837837
r936r937
13621362}
13631363#endif
13641364
1365
1366#if (HAS_PPC601)
1367static void ppc601_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1368{
1369   const ppc_config *config = _config;
1370   int pll_config = 0;
1371   float multiplier;
1372   int i ;
1373
1374   ppc_init() ;
1375
1376   optable[48] = ppc_lfs;
1377   optable[49] = ppc_lfsu;
1378   optable[50] = ppc_lfd;
1379   optable[51] = ppc_lfdu;
1380   optable[52] = ppc_stfs;
1381   optable[53] = ppc_stfsu;
1382   optable[54] = ppc_stfd;
1383   optable[55] = ppc_stfdu;
1384   optable31[631] = ppc_lfdux;
1385   optable31[599] = ppc_lfdx;
1386   optable31[567] = ppc_lfsux;
1387   optable31[535] = ppc_lfsx;
1388   optable31[595] = ppc_mfsr;
1389   optable31[659] = ppc_mfsrin;
1390   optable31[371] = ppc_mftb;
1391   optable31[210] = ppc_mtsr;
1392   optable31[242] = ppc_mtsrin;
1393   optable31[758] = ppc_dcba;
1394   optable31[759] = ppc_stfdux;
1395   optable31[727] = ppc_stfdx;
1396   optable31[983] = ppc_stfiwx;
1397   optable31[695] = ppc_stfsux;
1398   optable31[663] = ppc_stfsx;
1399   optable31[370] = ppc_tlbia;
1400   optable31[306] = ppc_tlbie;
1401   optable31[566] = ppc_tlbsync;
1402   optable31[310] = ppc_eciwx;
1403   optable31[438] = ppc_ecowx;
1404
1405   optable63[264] = ppc_fabsx;
1406   optable63[21] = ppc_faddx;
1407   optable63[32] = ppc_fcmpo;
1408   optable63[0] = ppc_fcmpu;
1409   optable63[14] = ppc_fctiwx;
1410   optable63[15] = ppc_fctiwzx;
1411   optable63[18] = ppc_fdivx;
1412   optable63[72] = ppc_fmrx;
1413   optable63[136] = ppc_fnabsx;
1414   optable63[40] = ppc_fnegx;
1415   optable63[12] = ppc_frspx;
1416   optable63[26] = ppc_frsqrtex;
1417   optable63[22] = ppc_fsqrtx;
1418   optable63[20] = ppc_fsubx;
1419   optable63[583] = ppc_mffsx;
1420   optable63[70] = ppc_mtfsb0x;
1421   optable63[38] = ppc_mtfsb1x;
1422   optable63[711] = ppc_mtfsfx;
1423   optable63[134] = ppc_mtfsfix;
1424   optable63[64] = ppc_mcrfs;
1425
1426   optable59[21] = ppc_faddsx;
1427   optable59[18] = ppc_fdivsx;
1428   optable59[24] = ppc_fresx;
1429   optable59[22] = ppc_fsqrtsx;
1430   optable59[20] = ppc_fsubsx;
1431
1432   for(i = 0; i < 32; i++)
1433   {
1434      optable63[i * 32 | 29] = ppc_fmaddx;
1435      optable63[i * 32 | 28] = ppc_fmsubx;
1436      optable63[i * 32 | 25] = ppc_fmulx;
1437      optable63[i * 32 | 31] = ppc_fnmaddx;
1438      optable63[i * 32 | 30] = ppc_fnmsubx;
1439      optable63[i * 32 | 23] = ppc_fselx;
1440
1441      optable59[i * 32 | 29] = ppc_fmaddsx;
1442      optable59[i * 32 | 28] = ppc_fmsubsx;
1443      optable59[i * 32 | 25] = ppc_fmulsx;
1444      optable59[i * 32 | 31] = ppc_fnmaddsx;
1445      optable59[i * 32 | 30] = ppc_fnmsubsx;
1446   }
1447
1448   for(i = 0; i < 256; i++)
1449   {
1450      ppc_field_xlat[i] =
1451         ((i & 0x80) ? 0xF0000000 : 0) |
1452         ((i & 0x40) ? 0x0F000000 : 0) |
1453         ((i & 0x20) ? 0x00F00000 : 0) |
1454         ((i & 0x10) ? 0x000F0000 : 0) |
1455         ((i & 0x08) ? 0x0000F000 : 0) |
1456         ((i & 0x04) ? 0x00000F00 : 0) |
1457         ((i & 0x02) ? 0x000000F0 : 0) |
1458         ((i & 0x01) ? 0x0000000F : 0);
1459   }
1460
1461   ppc.is603 = 1;
1462
1463   ppc.read8 = program_read_byte_64be;
1464   ppc.read16 = program_read_word_64be;
1465   ppc.read32 = program_read_dword_64be;
1466   ppc.read64 = program_read_qword_64be;
1467   ppc.write8 = program_write_byte_64be;
1468   ppc.write16 = program_write_word_64be;
1469   ppc.write32 = program_write_dword_64be;
1470   ppc.write64 = program_write_qword_64be;
1471   ppc.read16_unaligned = ppc_read16_unaligned;
1472   ppc.read32_unaligned = ppc_read32_unaligned;
1473   ppc.read64_unaligned = ppc_read64_unaligned;
1474   ppc.write16_unaligned = ppc_write16_unaligned;
1475   ppc.write32_unaligned = ppc_write32_unaligned;
1476   ppc.write64_unaligned = ppc_write64_unaligned;
1477
1478   ppc.irq_callback = irqcallback;
1479
1480   ppc.pvr = config->pvr;
1481
1482   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1483             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1484   bus_freq_multiplier = (int)(multiplier * 2);
1485
1486   ppc.hid1 = 0;
1487}
1488
1489static void ppc601_exit(void)
1490{
1491
1492}
1493#endif
1494
1495
1496
13651497static void ppc_get_context(void *dst)
13661498{
13671499   /* copy the context */
r936r937
17571889   }
17581890}
17591891#endif
1892
1893/* PPC601 */
1894
1895#if (HAS_PPC601)
1896static void ppc601_set_info(UINT32 state, cpuinfo *info)
1897{
1898   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
1899   {
1900      ppc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
1901      return;
1902   }
1903   switch(state)
1904   {
1905      default:                              ppc_set_info(state, info);            break;
1906   }
1907}
1908
1909void ppc601_get_info(UINT32 state, cpuinfo *info)
1910{
1911   switch(state)
1912   {
1913      /* --- the following bits of info are returned as 64-bit signed integers --- */
1914      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
1915      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
1916
1917      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
1918      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
1919
1920      /* --- the following bits of info are returned as pointers to data or functions --- */
1921      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc601_set_info;      break;
1922      case CPUINFO_PTR_INIT:                     info->init = ppc601_init;            break;
1923      case CPUINFO_PTR_RESET:                     info->reset = ppc603_reset;            break;
1924      case CPUINFO_PTR_EXIT:                     info->exit = ppc601_exit;            break;
1925      case CPUINFO_PTR_EXECUTE:                  info->execute = ppc603_execute;         break;
1926      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
1927      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
1928      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
1929
1930      /* --- the following bits of info are returned as NULL-terminated strings --- */
1931      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC601");            break;
1932
1933      default:                              ppc_get_info(state, info);            break;
1934   }
1935}
1936#endif
src/emu/cpu/powerpc/ppc_ops.c
r936r937
10551055#ifndef PPC_DRC
10561056static void ppc_sc(UINT32 op)
10571057{
1058#if (HAS_PPC603)
1058#if (HAS_PPC603 || HAS_PPC601)
10591059   if (ppc.is603) {
10601060      ppc603_exception(EXCEPTION_SYSTEM_CALL);
10611061   }
r936r937
15251525   }
15261526
15271527   if (exception) {
1528#if (HAS_PPC603)
1528#if (HAS_PPC603 || HAS_PPC601)
15291529      if (ppc.is603) {
15301530         ppc603_exception(EXCEPTION_TRAP);
15311531      }
r936r937
15691569   }
15701570
15711571   if (exception) {
1572#if (HAS_PPC603)
1572#if (HAS_PPC603 || HAS_PPC601)
15731573      if (ppc.is603) {
15741574         ppc603_exception(EXCEPTION_TRAP);
15751575      }
src/emu/cpu/powerpc/ppc.h
r936r937
357357void mpc8240_get_info(UINT32 state, cpuinfo *info);
358358#endif
359359
360#if (HAS_PPC601)
361void ppc601_get_info(UINT32 state, cpuinfo *info);
362#endif
363
360364#ifdef MAME_DEBUG
361365extern offs_t ppc_dasm_one(char *buffer, offs_t pc, UINT32 op);
362366#endif
src/emu/cpu/powerpc/ppcdrc.c
r936r937
1616#define MAX_INSTRUCTIONS   512
1717
1818
19#if (HAS_PPC603)
19#if (HAS_PPC603 || HAS_PPC601)
2020static void ppcdrc603_init(int index, int clock, const void *_config, int (*irqcallback)(int));
2121static void ppcdrc603_exit(void);
2222#endif
r936r937
510510      case SPR_PVR:      return;
511511   }
512512
513#if (HAS_PPC603 || HAS_PPC602)
513#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601)
514514   if(ppc.is603 || ppc.is602) {
515515      switch(spr)
516516      {
r936r937
723723   }
724724#endif
725725
726#if (HAS_PPC603 || HAS_PPC602)
726#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601)
727727   if (ppc.is603 || ppc.is602)
728728   {
729729      switch (spr)
r936r937
15861586}
15871587#endif
15881588
1589
1590#if (HAS_PPC601)
1591static void ppc601drc_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1592{
1593   int pll_config = 0;
1594   float multiplier;
1595   const ppc_config *config = _config;
1596   int i;
1597
1598   ppc_init();
1599   ppcdrc_init();
1600
1601   optable[48] = recompile_lfs;
1602   optable[49] = recompile_lfsu;
1603   optable[50] = recompile_lfd;
1604   optable[51] = recompile_lfdu;
1605   optable[52] = recompile_stfs;
1606   optable[53] = recompile_stfsu;
1607   optable[54] = recompile_stfd;
1608   optable[55] = recompile_stfdu;
1609   optable31[631] = recompile_lfdux;
1610   optable31[599] = recompile_lfdx;
1611   optable31[567] = recompile_lfsux;
1612   optable31[535] = recompile_lfsx;
1613   optable31[595] = recompile_mfsr;
1614   optable31[659] = recompile_mfsrin;
1615   optable31[371] = recompile_mftb;
1616   optable31[210] = recompile_mtsr;
1617   optable31[242] = recompile_mtsrin;
1618   optable31[758] = recompile_dcba;
1619   optable31[759] = recompile_stfdux;
1620   optable31[727] = recompile_stfdx;
1621   optable31[983] = recompile_stfiwx;
1622   optable31[695] = recompile_stfsux;
1623   optable31[663] = recompile_stfsx;
1624   optable31[370] = recompile_tlbia;
1625   optable31[306] = recompile_tlbie;
1626   optable31[566] = recompile_tlbsync;
1627   optable31[310] = recompile_eciwx;
1628   optable31[438] = recompile_ecowx;
1629
1630   optable63[264] = recompile_fabsx;
1631   optable63[21] = recompile_faddx;
1632   optable63[32] = recompile_fcmpo;
1633   optable63[0] = recompile_fcmpu;
1634   optable63[14] = recompile_fctiwx;
1635   optable63[15] = recompile_fctiwzx;
1636   optable63[18] = recompile_fdivx;
1637   optable63[72] = recompile_fmrx;
1638   optable63[136] = recompile_fnabsx;
1639   optable63[40] = recompile_fnegx;
1640   optable63[12] = recompile_frspx;
1641   optable63[26] = recompile_frsqrtex;
1642   optable63[22] = recompile_fsqrtx;
1643   optable63[20] = recompile_fsubx;
1644   optable63[583] = recompile_mffsx;
1645   optable63[70] = recompile_mtfsb0x;
1646   optable63[38] = recompile_mtfsb1x;
1647   optable63[711] = recompile_mtfsfx;
1648   optable63[134] = recompile_mtfsfix;
1649   optable63[64] = recompile_mcrfs;
1650
1651   optable59[21] = recompile_faddsx;
1652   optable59[18] = recompile_fdivsx;
1653   optable59[24] = recompile_fresx;
1654   optable59[22] = recompile_fsqrtsx;
1655   optable59[20] = recompile_fsubsx;
1656
1657   for(i = 0; i < 32; i++)
1658   {
1659      optable63[i * 32 | 29] = recompile_fmaddx;
1660      optable63[i * 32 | 28] = recompile_fmsubx;
1661      optable63[i * 32 | 25] = recompile_fmulx;
1662      optable63[i * 32 | 31] = recompile_fnmaddx;
1663      optable63[i * 32 | 30] = recompile_fnmsubx;
1664      optable63[i * 32 | 23] = recompile_fselx;
1665
1666      optable59[i * 32 | 29] = recompile_fmaddsx;
1667      optable59[i * 32 | 28] = recompile_fmsubsx;
1668      optable59[i * 32 | 25] = recompile_fmulsx;
1669      optable59[i * 32 | 31] = recompile_fnmaddsx;
1670      optable59[i * 32 | 30] = recompile_fnmsubsx;
1671   }
1672
1673   for(i = 0; i < 256; i++)
1674   {
1675      ppc_field_xlat[i] =
1676         ((i & 0x80) ? 0xF0000000 : 0) |
1677         ((i & 0x40) ? 0x0F000000 : 0) |
1678         ((i & 0x20) ? 0x00F00000 : 0) |
1679         ((i & 0x10) ? 0x000F0000 : 0) |
1680         ((i & 0x08) ? 0x0000F000 : 0) |
1681         ((i & 0x04) ? 0x00000F00 : 0) |
1682         ((i & 0x02) ? 0x000000F0 : 0) |
1683         ((i & 0x01) ? 0x0000000F : 0);
1684   }
1685
1686   ppc.is603 = 1;
1687
1688   ppc.read8 = program_read_byte_64be;
1689   ppc.read16 = program_read_word_64be;
1690   ppc.read32 = program_read_dword_64be;
1691   ppc.read64 = program_read_qword_64be;
1692   ppc.write8 = program_write_byte_64be;
1693   ppc.write16 = program_write_word_64be;
1694   ppc.write32 = program_write_dword_64be;
1695   ppc.write64 = program_write_qword_64be;
1696   ppc.read16_unaligned = ppc_read16_unaligned;
1697   ppc.read32_unaligned = ppc_read32_unaligned;
1698   ppc.read64_unaligned = ppc_read64_unaligned;
1699   ppc.write16_unaligned = ppc_write16_unaligned;
1700   ppc.write32_unaligned = ppc_write32_unaligned;
1701   ppc.write64_unaligned = ppc_write64_unaligned;
1702
1703   ppc.irq_callback = irqcallback;
1704
1705   ppc.pvr = config->pvr;
1706
1707   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1708             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1709   bus_freq_multiplier = (int)(multiplier * 2);
1710
1711   switch(config->pvr)
1712   {
1713      case PPC_MODEL_603E:   pll_config = mpc603e_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1714      case PPC_MODEL_603EV:   pll_config = mpc603ev_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1715      case PPC_MODEL_603R:   pll_config = mpc603r_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1716      default: break;
1717   }
1718
1719   if (pll_config == -1)
1720   {
1721      fatalerror("PPC: Invalid bus/multiplier combination (bus frequency = %d, multiplier = %1.1f)", config->bus_frequency, multiplier);
1722   }
1723
1724   ppc.hid1 = pll_config << 28;
1725}
1726
1727static void ppc601drc_exit(void)
1728{
1729#if LOG_CODE
1730   //if (symfile) fclose(symfile);
1731#endif
1732   drc_exit(ppc.drc);
1733}
1734#endif
1735
1736
15891737static void ppc_get_context(void *dst)
15901738{
15911739   /* copy the context */
r936r937
19742122   }
19752123}
19762124#endif
2125
2126
2127/* PPC601 */
2128
2129#if (HAS_PPC601)
2130static void ppc601_set_info(UINT32 state, cpuinfo *info)
2131{
2132   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2133   {
2134      ppcdrc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2135      return;
2136   }
2137   switch(state)
2138   {
2139      default:                              ppc_set_info(state, info);            break;
2140   }
2141}
2142
2143void ppc601_get_info(UINT32 state, cpuinfo *info)
2144{
2145   switch(state)
2146   {
2147      /* --- the following bits of info are returned as 64-bit signed integers --- */
2148      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2149      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2150
2151      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2152      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2153
2154      /* --- the following bits of info are returned as pointers to data or functions --- */
2155      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc601_set_info;      break;
2156      case CPUINFO_PTR_INIT:                     info->init = ppc601drc_init;         break;
2157      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc603_reset;         break;
2158      case CPUINFO_PTR_EXIT:                     info->exit = ppc601drc_exit;         break;
2159      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc603_execute;      break;
2160      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2161      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2162      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2163
2164      /* --- the following bits of info are returned as NULL-terminated strings --- */
2165      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC601");            break;
2166
2167      default:                              ppc_get_info(state, info);            break;
2168   }
2169}
2170#endif
src/emu/cpu/nec/necdasm.c
r936r937
15201520   decode_opcode( buffer, &necv_opcode_table1[op], op );
15211521   return (pc-eip) | dasm_flags | DASMFLAG_SUPPORTED;
15221522}
1523/*
1524   NEC V-series Disassembler
1525
1526   Originally Written for i386 by Ville Linde
1527   Converted to NEC-V by Aaron Giles
1528*/
1529
1530#include "cpuintrf.h"
1531
1532enum {
1533   PARAM_REG8 = 1,      /* 8-bit register */
1534   PARAM_REG16,      /* 16-bit register */
1535   PARAM_REG2_8,      /* 8-bit register */
1536   PARAM_REG2_16,      /* 16-bit register */
1537   PARAM_RM8,         /* 8-bit memory or register */
1538   PARAM_RM16,         /* 16-bit memory or register */
1539   PARAM_I4,         /* 4-bit signed immediate */
1540   PARAM_I8,         /* 8-bit signed immediate */
1541   PARAM_I16,         /* 16-bit signed immediate */
1542   PARAM_UI8,         /* 8-bit unsigned immediate */
1543   PARAM_UI16,         /* 16-bit unsigned immediate */
1544   PARAM_IMM,         /* 16-bit immediate */
1545   PARAM_ADDR,         /* 16:16 address */
1546   PARAM_REL8,         /* 8-bit PC-relative displacement */
1547   PARAM_REL16,      /* 16-bit PC-relative displacement */
1548   PARAM_MEM_OFFS_B,   /* 8-bit mem offset */
1549   PARAM_MEM_OFFS_W,   /* 16-bit mem offset */
1550   PARAM_SREG,         /* segment register */
1551   PARAM_RBANK,      /* register bank (V25) */
1552   PARAM_1,         /* used by shift/rotate instructions */
1553   PARAM_AL,
1554   PARAM_CL,
1555   PARAM_DL,
1556   PARAM_BL,
1557   PARAM_AH,
1558   PARAM_CH,
1559   PARAM_DH,
1560   PARAM_BH,
1561   PARAM_AW,
1562   PARAM_CW,
1563   PARAM_DW,
1564   PARAM_BW,
1565   PARAM_SP,
1566   PARAM_BP,
1567   PARAM_IX,
1568   PARAM_IY
1569};
1570
1571enum {
1572   MODRM = 1,
1573   GROUP,
1574   FPU,
1575   TWO_BYTE,
1576   PREFIX,
1577   SEG_PS,
1578   SEG_DS0,
1579   SEG_DS1,
1580   SEG_SS
1581};
1582
1583typedef struct {
1584   char mnemonic[32];
1585   UINT32 flags;
1586   UINT32 param1;
1587   UINT32 param2;
1588   UINT32 param3;
1589   offs_t dasm_flags;
1590} I386_OPCODE;
1591
1592typedef struct {
1593   char mnemonic[32];
1594   const I386_OPCODE *opcode;
1595} GROUP_OP;
1596
1597static const UINT8 *opcode_ptr;
1598static const UINT8 *opcode_ptr_base;
1599
1600static const I386_OPCODE necv_opcode_table1[256] =
1601{
1602   // 0x00
1603   {"add",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1604   {"add",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1605   {"add",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1606   {"add",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1607   {"add",            0,            PARAM_AL,         PARAM_UI8,         0            },
1608   {"add",            0,            PARAM_AW,         PARAM_IMM,         0            },
1609   {"push    ds1",      0,            0,               0,               0            },
1610   {"pop     ds1",      0,            0,               0,               0            },
1611   {"or",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1612   {"or",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1613   {"or",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1614   {"or",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1615   {"or",            0,            PARAM_AL,         PARAM_UI8,         0            },
1616   {"or",            0,            PARAM_AW,         PARAM_IMM,         0            },
1617   {"push    ps",      0,            0,               0,               0            },
1618   {"two_byte",      TWO_BYTE,      0,               0,               0            },
1619   // 0x10
1620   {"addc",         MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1621   {"addc",         MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1622   {"addc",         MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1623   {"addc",         MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1624   {"addc",         0,            PARAM_AL,         PARAM_UI8,         0            },
1625   {"addc",         0,            PARAM_AW,         PARAM_IMM,         0            },
1626   {"push    ss",      0,            0,               0,               0            },
1627   {"pop     ss",      0,            0,               0,               0            },
1628   {"subc",         MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1629   {"subc",         MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1630   {"subc",         MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1631   {"subc",         MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1632   {"subc",         0,            PARAM_AL,         PARAM_UI8,         0            },
1633   {"subc",         0,            PARAM_AW,         PARAM_IMM,         0            },
1634   {"push    ds0",      0,            0,               0,               0            },
1635   {"pop     ds0",      0,            0,               0,               0            },
1636   // 0x20
1637   {"and",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1638   {"and",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1639   {"and",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1640   {"and",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1641   {"and",            0,            PARAM_AL,         PARAM_UI8,         0            },
1642   {"and",            0,            PARAM_AW,         PARAM_IMM,         0            },
1643   {"ds1:",         SEG_DS1,      0,               0,               0            },
1644   {"adj4a",         0,            0,               0,               0            },
1645   {"sub",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1646   {"sub",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1647   {"sub",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1648   {"sub",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1649   {"sub",            0,            PARAM_AL,         PARAM_I8,         0            },
1650   {"sub",            0,            PARAM_AW,         PARAM_IMM,         0            },
1651   {"ps:",            SEG_PS,         0,               0,               0            },
1652   {"adj4s",         0,            0,               0,               0            },
1653   // 0x30
1654   {"xor",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1655   {"xor",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1656   {"xor",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1657   {"xor",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1658   {"xor",            0,            PARAM_AL,         PARAM_UI8,         0            },
1659   {"xor",            0,            PARAM_AW,         PARAM_IMM,         0            },
1660   {"ss:",            SEG_SS,         0,               0,               0            },
1661   {"adjba",         0,            0,               0,               0            },
1662   {"cmp",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1663   {"cmp",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1664   {"cmp",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1665   {"cmp",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1666   {"cmp",            0,            PARAM_AL,         PARAM_UI8,         0            },
1667   {"cmp",            0,            PARAM_AW,         PARAM_IMM,         0            },
1668   {"ds0:",         SEG_DS0,      0,               0,               0            },
1669   {"adjbs",         0,            0,               0,               0            },
1670   // 0x40
1671   {"inc",            0,            PARAM_AW,         0,               0            },
1672   {"inc",            0,            PARAM_CW,         0,               0            },
1673   {"inc",            0,            PARAM_DW,         0,               0            },
1674   {"inc",            0,            PARAM_BW,         0,               0            },
1675   {"inc",            0,            PARAM_SP,         0,               0            },
1676   {"inc",            0,            PARAM_BP,         0,               0            },
1677   {"inc",            0,            PARAM_IX,         0,               0            },
1678   {"inc",            0,            PARAM_IY,         0,               0            },
1679   {"dec",            0,            PARAM_AW,         0,               0            },
1680   {"dec",            0,            PARAM_CW,         0,               0            },
1681   {"dec",            0,            PARAM_DW,         0,               0            },
1682   {"dec",            0,            PARAM_BW,         0,               0            },
1683   {"dec",            0,            PARAM_SP,         0,               0            },
1684   {"dec",            0,            PARAM_BP,         0,               0            },
1685   {"dec",            0,            PARAM_IX,         0,               0            },
1686   {"dec",            0,            PARAM_IY,         0,               0            },
1687   // 0x50
1688   {"push",         0,            PARAM_AW,         0,               0            },
1689   {"push",         0,            PARAM_CW,         0,               0            },
1690   {"push",         0,            PARAM_DW,         0,               0            },
1691   {"push",         0,            PARAM_BW,         0,               0            },
1692   {"push",         0,            PARAM_SP,         0,               0            },
1693   {"push",         0,            PARAM_BP,         0,               0            },
1694   {"push",         0,            PARAM_IX,         0,               0            },
1695   {"push",         0,            PARAM_IY,         0,               0            },
1696   {"pop",            0,            PARAM_AW,         0,               0            },
1697   {"pop",            0,            PARAM_CW,         0,               0            },
1698   {"pop",            0,            PARAM_DW,         0,               0            },
1699   {"pop",            0,            PARAM_BW,         0,               0            },
1700   {"pop",            0,            PARAM_SP,         0,               0            },
1701   {"pop",            0,            PARAM_BP,         0,               0            },
1702   {"pop",            0,            PARAM_IX,         0,               0            },
1703   {"pop",            0,            PARAM_IY,         0,               0            },
1704   // 0x60
1705   {"push    r",      0,            0,               0,               0            },
1706   {"pop     r",      0,            0,               0,               0            },
1707   {"chkind",         MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1708   {"brkn",         MODRM,         PARAM_RM16,         PARAM_REG16,      0            },   /* break into native */
1709   {"repnc",         PREFIX,         0,               0,               0            },
1710   {"repc",         PREFIX,         0,               0,               0            },
1711   {"fpo2    0",      0,/*OP_SIZE*/   0,               0,               0            },
1712   {"fpo2    1",      0,/*ADDR_SIZE*/   0,               0,               0            },
1713   {"push",         0,            PARAM_IMM,         0,               0            },
1714   {"mul",            MODRM,         PARAM_REG16,      PARAM_RM16,         PARAM_IMM      },
1715   {"push",         0,            PARAM_I8,         0,               0            },
1716   {"mul",            MODRM,         PARAM_REG16,      PARAM_RM16,         PARAM_I8      },
1717   {"inmb",         0,            0,               0,               0            },
1718   {"inmw",         0,            0,               0,               0            },
1719   {"outmb",         0,            0,               0,               0            },
1720   {"outmw",         0,            0,               0,               0            },
1721   // 0x70
1722   {"bv",            0,            PARAM_REL8,         0,               0            },
1723   {"bnv",            0,            PARAM_REL8,         0,               0            },
1724   {"bc",            0,            PARAM_REL8,         0,               0            },
1725   {"bnc",            0,            PARAM_REL8,         0,               0            },
1726   {"be",            0,            PARAM_REL8,         0,               0            },
1727   {"bne",            0,            PARAM_REL8,         0,               0            },
1728   {"bnh",            0,            PARAM_REL8,         0,               0            },
1729   {"bh",            0,            PARAM_REL8,         0,               0            },
1730   {"bn",            0,            PARAM_REL8,         0,               0            },
1731   {"bp",            0,            PARAM_REL8,         0,               0            },
1732   {"bpe",            0,            PARAM_REL8,         0,               0            },
1733   {"bpo",            0,            PARAM_REL8,         0,               0            },
1734   {"blt",            0,            PARAM_REL8,         0,               0            },
1735   {"bge",            0,            PARAM_REL8,         0,               0            },
1736   {"ble",            0,            PARAM_REL8,         0,               0            },
1737   {"bgt",            0,            PARAM_REL8,         0,               0            },
1738   // 0x80
1739   {"immb",         GROUP,         0,               0,               0            },
1740   {"immw",         GROUP,         0,               0,               0            },
1741   {"immb",         GROUP,         0,               0,               0            },
1742   {"immws",         GROUP,         0,               0,               0            },
1743   {"test",         MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1744   {"test",         MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1745   {"xch",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1746   {"xch",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1747   {"mov",            MODRM,         PARAM_RM8,         PARAM_REG8,         0            },
1748   {"mov",            MODRM,         PARAM_RM16,         PARAM_REG16,      0            },
1749   {"mov",            MODRM,         PARAM_REG8,         PARAM_RM8,         0            },
1750   {"mov",            MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1751   {"mov",            MODRM,         PARAM_RM16,         PARAM_SREG,         0            },
1752   {"ldea",         MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1753   {"mov",            MODRM,         PARAM_SREG,         PARAM_RM16,         0            },
1754   {"pop",            MODRM,         PARAM_RM16,         0,               0            },
1755   // 0x90
1756   {"nop",            0,            0,               0,               0            },
1757   {"xch",            0,            PARAM_AW,         PARAM_CW,         0            },
1758   {"xch",            0,            PARAM_AW,         PARAM_DW,         0            },
1759   {"xch",            0,            PARAM_AW,         PARAM_BW,         0            },
1760   {"xch",            0,            PARAM_AW,         PARAM_SP,         0            },
1761   {"xch",            0,            PARAM_AW,         PARAM_BP,         0            },
1762   {"xch",            0,            PARAM_AW,         PARAM_IX,         0            },
1763   {"xch",            0,            PARAM_AW,         PARAM_IY,         0            },
1764   {"cvtbw",         0,            0,               0,               0            },
1765   {"cvtwl",         0,            0,               0,               0            },
1766   {"call",         0,            PARAM_ADDR,         0,               0,            DASMFLAG_STEP_OVER},
1767   {"poll",         0,            0,               0,               0            },
1768   {"push    psw",      0,            0,               0,               0            },
1769   {"pop     psw",      0,            0,               0,               0            },
1770   {"mov     psw,ah",   0,            0,               0,               0            },
1771   {"mov     ah,psw",   0,            0,               0,               0            },
1772   // 0xa0
1773   {"mov",            0,            PARAM_AL,         PARAM_MEM_OFFS_W,   0            },
1774   {"mov",            0,            PARAM_AW,         PARAM_MEM_OFFS_W,   0            },
1775   {"mov",            0,            PARAM_MEM_OFFS_W,   PARAM_AL,         0            },
1776   {"mov",            0,            PARAM_MEM_OFFS_W,   PARAM_AW,         0            },
1777   {"movbkb",         0,            0,               0,               0            },
1778   {"movbkw",         0,            0,               0,               0            },
1779   {"cmpbkb",         0,            0,               0,               0            },
1780   {"cmpbkw",         0,            0,               0,               0            },
1781   {"test",         0,            PARAM_AL,         PARAM_UI8,         0            },
1782   {"test",         0,            PARAM_AW,         PARAM_IMM,         0            },
1783   {"stmb",         0,            0,               0,               0            },
1784   {"stmw",         0,            0,               0,               0            },
1785   {"ldmb",         0,            0,               0,               0            },
1786   {"ldmw",         0,            0,               0,               0            },
1787   {"cmpmb",         0,            0,               0,               0            },
1788   {"cmpmw",         0,            0,               0,               0            },
1789   // 0xb0
1790   {"mov",            0,            PARAM_AL,         PARAM_UI8,         0            },
1791   {"mov",            0,            PARAM_CL,         PARAM_UI8,         0            },
1792   {"mov",            0,            PARAM_DL,         PARAM_UI8,         0            },
1793   {"mov",            0,            PARAM_BL,         PARAM_UI8,         0            },
1794   {"mov",            0,            PARAM_AH,         PARAM_UI8,         0            },
1795   {"mov",            0,            PARAM_CH,         PARAM_UI8,         0            },
1796   {"mov",            0,            PARAM_DH,         PARAM_UI8,         0            },
1797   {"mov",            0,            PARAM_BH,         PARAM_UI8,         0            },
1798   {"mov",            0,            PARAM_AW,         PARAM_IMM,         0            },
1799   {"mov",            0,            PARAM_CW,         PARAM_IMM,         0            },
1800   {"mov",            0,            PARAM_DW,         PARAM_IMM,         0            },
1801   {"mov",            0,            PARAM_BW,         PARAM_IMM,         0            },
1802   {"mov",            0,            PARAM_SP,         PARAM_IMM,         0            },
1803   {"mov",            0,            PARAM_BP,         PARAM_IMM,         0            },
1804   {"mov",            0,            PARAM_IX,         PARAM_IMM,         0            },
1805   {"mov",            0,            PARAM_IY,         PARAM_IMM,         0            },
1806   // 0xc0
1807   {"shiftbi",         GROUP,         0,               0,               0            },
1808   {"shiftwi",         GROUP,         0,               0,               0            },
1809   {"ret",            0,            PARAM_I16,         0,               0,            DASMFLAG_STEP_OUT},
1810   {"ret",            0,            0,               0,               0,            DASMFLAG_STEP_OUT},
1811   {"mov     ds1,",   MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1812   {"mov     ds0,",   MODRM,         PARAM_REG16,      PARAM_RM16,         0            },
1813   {"mov",            MODRM,         PARAM_RM8,         PARAM_UI8,         0            },
1814   {"mov",            MODRM,         PARAM_RM16,         PARAM_IMM,         0            },
1815   {"prepare",         0,            PARAM_I16,         PARAM_UI8,         0            },
1816   {"dispose",         0,            0,               0,               0            },
1817   {"retf",         0,            PARAM_I16,         0,               0,            DASMFLAG_STEP_OUT},
1818   {"retf",         0,            0,               0,               0,            DASMFLAG_STEP_OUT},
1819   {"brk     3",      0,            0,               0,               0,            DASMFLAG_STEP_OVER},
1820   {"brk",            0,            PARAM_UI8,         0,               0,            DASMFLAG_STEP_OVER},
1821   {"brkv",         0,            0,               0,               0            },
1822   {"reti",         0,            0,               0,               0,            DASMFLAG_STEP_OUT},
1823   // 0xd0
1824   {"shiftb",         GROUP,         0,               0,               0            },
1825   {"shiftw",         GROUP,         0,               0,               0            },
1826   {"shiftbv",         GROUP,         0,               0,               0            },
1827   {"shiftwv",         GROUP,         0,               0,               0            },
1828   {"cvtbd",         0,            PARAM_I8,         0,               0            },
1829   {"cvtdb",         0,            PARAM_I8,         0,               0            },
1830   {"???",            0,            0,               0,               0            },
1831   {"trans",         0,            0,               0,               0            },
1832   {"escape",         FPU,         0,               0,               0            },
1833   {"escape",         FPU,         0,               0,               0            },
1834   {"escape",         FPU,         0,               0,               0            },
1835   {"escape",         FPU,         0,               0,               0            },
1836   {"escape",         FPU,         0,               0,               0            },
1837   {"escape",         FPU,         0,               0,               0            },
1838   {"escape",         FPU,         0,               0,               0            },
1839   {"escape",         FPU,         0,               0,               0            },
1840   // 0xe0
1841   {"dbnzne",         0,            PARAM_REL8,         0,               0,            DASMFLAG_STEP_OVER},
1842   {"dbnze",         0,            PARAM_REL8,         0,               0,            DASMFLAG_STEP_OVER},
1843   {"dbnz",         0,            PARAM_REL8,         0,               0,            DASMFLAG_STEP_OVER},
1844   {"bcwz",         0,            PARAM_REL8,         0,               0            },
1845   {"in",            0,            PARAM_AL,         PARAM_UI8,         0            },
1846   {"in",            0,            PARAM_AW,         PARAM_UI8,         0            },
1847   {"out",            0,            PARAM_UI8,         PARAM_AL,         0            },
1848   {"out",            0,            PARAM_UI8,         PARAM_AW,         0            },
1849   {"call",         0,            PARAM_REL16,      0,               0,            DASMFLAG_STEP_OVER},
1850   {"br",            0,            PARAM_REL16,      0,               0            },
1851   {"br",            0,            PARAM_ADDR,         0,               0            },
1852   {"br",            0,            PARAM_REL8,         0,               0            },
1853   {"in",            0,            PARAM_AL,         PARAM_DW,         0            },
1854   {"in",            0,            PARAM_AW,         PARAM_DW,         0            },
1855   {"out",            0,            PARAM_DW,         PARAM_AL,         0            },
1856   {"out",            0,            PARAM_DW,         PARAM_AW,         0            },
1857   // 0xf0
1858   {"buslock",         PREFIX,         0,               0,               0            },
1859   {"brks",         0,            0,               0,               0            },   /* break into secure mode */
1860   {"repne",         PREFIX,         0,               0,               0            },
1861   {"rep",            PREFIX,         0,               0,               0            },
1862   {"halt",         0,            0,               0,               0            },
1863   {"not1    cy",      0,            0,               0,               0            },
1864   {"group1b",         GROUP,         0,               0,               0            },
1865   {"group1w",         GROUP,         0,               0,               0            },
1866   {"clr1    cy",      0,            0,               0,               0            },
1867   {"set1    cy",      0,            0,               0,               0            },
1868   {"di",            0,            0,               0,               0            },
1869   {"ei",            0,            0,               0,               0            },
1870   {"clr1    dir",      0,            0,               0,               0            },
1871   {"set1    dir",      0,            0,               0,               0            },
1872   {"group2b",         GROUP,         0,               0,               0            },
1873   {"group2w",         GROUP,         0,               0,               0            }
1874};
1875
1876static const I386_OPCODE necv_opcode_table2[256] =
1877{
1878   // 0x00
1879   {"???",            0,            0,               0,               0            },
1880   {"???",            0,            0,               0,               0            },
1881   {"???",            0,            0,               0,               0            },
1882   {"???",            0,            0,               0,               0            },
1883   {"???",            0,            0,               0,               0            },
1884   {"???",            0,            0,               0,               0            },
1885   {"???",            0,            0,               0,               0            },
1886   {"???",            0,            0,               0,               0            },
1887   {"???",            0,            0,               0,               0            },
1888   {"???",            0,            0,               0,               0            },
1889   {"???",            0,            0,               0,               0            },
1890   {"???",            0,            0,               0,               0            },
1891   {"???",            0,            0,               0,               0            },
1892   {"???",            0,            0,               0,               0            },
1893   {"???",            0,            0,               0,               0            },
1894   {"???",            0,            0,               0,               0            },
1895   // 0x10 - NEC V series only
1896   {"test1",         MODRM,         PARAM_RM8,         PARAM_1,         0            },
1897   {"test1",         MODRM,         PARAM_RM16,         PARAM_1,         0            },
1898   {"clr1",         MODRM,         PARAM_RM8,         PARAM_1,         0            },
1899   {"clr1",         MODRM,         PARAM_RM16,         PARAM_1,         0            },
1900   {"set1",         MODRM,         PARAM_RM8,         PARAM_1,         0            },
1901   {"set1",         MODRM,         PARAM_RM16,         PARAM_1,         0            },
1902   {"not1",         MODRM,         PARAM_RM8,         PARAM_1,         0            },
1903   {"not1",         MODRM,         PARAM_RM16,         PARAM_1,         0            },
1904   {"test1",         MODRM,         PARAM_RM8,         PARAM_I8,         0            },
1905   {"test1",         MODRM,         PARAM_RM16,         PARAM_I8,         0            },
1906   {"clr1",         MODRM,         PARAM_RM8,         PARAM_I8,         0            },
1907   {"clr1",         MODRM,         PARAM_RM16,         PARAM_I8,         0            },
1908   {"set1",         MODRM,         PARAM_RM8,         PARAM_I8,         0            },
1909   {"set1",         MODRM,         PARAM_RM16,         PARAM_I8,         0            },
1910   {"not1",         MODRM,         PARAM_RM8,         PARAM_I8,         0            },
1911   {"not1",         MODRM,         PARAM_RM16,         PARAM_I8,         0            },
1912   // 0x20
1913   {"add4s",         0,            0,               0,               0            },
1914   {"???",            0,            0,               0,               0            },
1915   {"sub4s",         0,            0,               0,               0            },
1916   {"???",            0,            0,               0,               0            },
1917   {"???",            0,            0,               0,               0            },
1918   {"movspa",         0,            0,               0,               0            },   /* V25/35 only */
1919   {"cmp4s",         0,            0,               0,               0            },
1920   {"???",            0,            0,               0,               0            },
1921   {"rol4",         MODRM,         PARAM_RM8,         0,               0            },
1922   {"???",            0,            0,               0,               0            },
1923   {"ror4",         MODRM,         PARAM_RM8,         0,               0            },
1924   {"???",            0,            0,               0,               0            },
1925   {"???",            0,            0,               0,               0            },
1926   {"brkcs",         MODRM,         PARAM_REG2_8,      0,               0            },   /* V25/35 only */
1927   {"???",            0,            0,               0,               0            },
1928   {"???",            0,            0,               0,               0            },
1929   // 0x30
1930   {"???",            0,            0,               0,               0            },
1931   {"ins",            MODRM,         PARAM_REG2_8,      PARAM_REG8,         0            },
1932   {"???",            0,            0,               0,               0            },
1933   {"ext",            MODRM,         PARAM_REG2_8,      PARAM_REG8,         0            },
1934   {"???",            0,            0,               0,               0            },
1935   {"???",            0,            0,               0,               0            },
1936   {"???",            0,            0,               0,               0            },
1937   {"???",            0,            0,               0,               0            },
1938   {"???",            0,            0,               0,               0            },
1939   {"ins",            MODRM,         PARAM_REG2_8,      PARAM_I4,         0            },
1940   {"???",            0,            0,               0,               0            },
1941   {"ext",            MODRM,         PARAM_REG2_8,      PARAM_I4,         0            },
1942   {"???",            0,            0,               0,               0            },
1943   {"???",            0,            0,               0,               0            },
1944   {"???",            0,            0,               0,               0            },
1945   {"???",            0,            0,               0,               0            },
1946   // 0x40
1947   {"???",            0,            0,               0,               0            },
1948   {"???",            0,            0,               0,               0            },
1949   {"???",            0,            0,               0,               0            },
1950   {"???",            0,            0,               0,               0            },
1951   {"???",            0,            0,               0,               0            },
1952   {"???",            0,            0,               0,               0            },
1953   {"???",            0,            0,               0,               0            },
1954   {"???",            0,            0,               0,               0            },
1955   {"???",            0,            0,               0,               0            },
1956   {"???",            0,            0,               0,               0            },
1957   {"???",            0,            0,               0,               0            },
1958   {"???",            0,            0,               0,               0            },
1959   {"???",            0,            0,               0,               0            },
1960   {"???",            0,            0,               0,               0            },
1961   {"???",            0,            0,               0,               0            },
1962   {"???",            0,            0,               0,               0            },
1963   // 0x50
1964   {"???",            0,            0,               0,               0            },
1965   {"???",            0,            0,               0,               0            },
1966   {"???",            0,            0,               0,               0            },
1967   {"???",            0,            0,               0,               0            },
1968   {"???",            0,            0,               0,               0            },
1969   {"???",            0,            0,               0,               0            },
1970   {"???",            0,            0,               0,               0            },
1971   {"???",            0,            0,               0,               0            },
1972   {"???",            0,            0,               0,               0            },
1973   {"???",            0,            0,               0,               0            },
1974   {"???",            0,            0,               0,               0            },
1975   {"???",            0,            0,               0,               0            },
1976   {"???",            0,            0,               0,               0            },
1977   {"???",            0,            0,               0,               0            },
1978   {"???",            0,            0,               0,               0            },
1979   {"???",            0,            0,               0,               0            },
1980   // 0x60
1981   {"???",            0,            0,               0,               0            },
1982   {"???",            0,            0,               0,               0            },
1983   {"???",            0,            0,               0,               0            },
1984   {"???",            0,            0,               0,               0            },
1985   {"???",            0,            0,               0,               0            },
1986   {"???",            0,            0,               0,               0            },
1987   {"???",            0,            0,               0,               0            },
1988   {"???",            0,            0,               0,               0            },
1989   {"???",            0,            0,               0,               0            },
1990   {"???",            0,            0,               0,               0            },
1991   {"???",            0,            0,               0,               0            },
1992   {"???",            0,            0,               0,               0            },
1993   {"???",            0,            0,               0,               0            },
1994   {"???",            0,            0,               0,               0            },
1995   {"???",            0,            0,               0,               0            },
1996   {"???",            0,            0,               0,               0            },
1997   // 0x70
1998   {"???",            0,            0,               0,               0            },
1999   {"???",            0,            0,               0,               0            },
2000   {"???",            0,            0,               0,               0            },
2001   {"???",            0,            0,               0,               0            },
2002   {"???",            0,            0,               0,               0            },
2003   {"???",            0,            0,               0,               0            },
2004   {"???",            0,            0,               0,               0            },
2005   {"???",            0,            0,               0,               0            },
2006   {"???",            0,            0,               0,               0            },
2007   {"???",            0,            0,               0,               0            },
2008   {"???",            0,            0,               0,               0            },
2009   {"???",            0,            0,               0,               0            },
2010   {"???",            0,            0,               0,               0            },
2011   {"???",            0,            0,               0,               0            },
2012   {"???",            0,            0,               0,               0            },
2013   {"???",            0,            0,               0,               0            },
2014   // 0x80
2015   {"???",            0,            0,               0,               0            },
2016   {"???",            0,            0,               0,               0            },
2017   {"???",            0,            0,               0,               0            },
2018   {"???",            0,            0,               0,               0            },
2019   {"???",            0,            0,               0,               0            },
2020   {"???",            0,            0,               0,               0            },
2021   {"???",            0,            0,               0,               0            },
2022   {"???",            0,            0,               0,               0            },
2023   {"???",            0,            0,               0,               0            },
2024   {"???",            0,            0,               0,               0            },
2025   {"???",            0,            0,               0,               0            },
2026   {"???",            0,            0,               0,               0            },
2027   {"???",            0,            0,               0,               0            },
2028   {"???",            0,            0,               0,               0            },
2029   {"???",            0,            0,               0,               0            },
2030   {"???",            0,            0,               0,               0            },
2031   // 0x90
2032   {"???",            0,            0,               0,               0            },
2033   {"retrbi",         0,            0,               0,               0            },   /* V25/35 only */
2034   {"fint",         0,            0,               0,               0            },   /* V25/35 only */
2035   {"???",            0,            0,               0,               0            },
2036   {"tsksw",         MODRM,         PARAM_REG2_8,      0,               0            },   /* V25/35 only */
2037   {"movspb",         0,            PARAM_RBANK,      0,               0            },   /* V25/35 only */
2038   {"???",            0,            0,               0,               0            },
2039   {"???",            0,            0,               0,               0            },
2040   {"???",            0,            0,               0,               0            },
2041   {"???",            0,            0,               0,               0            },
2042   {"???",            0,            0,               0,               0            },
2043   {"???",            0,            0,               0,               0            },
2044   {"btclr",         MODRM,         PARAM_REG2_8,      PARAM_I8,         PARAM_REL8      },   /* V25/35 only */
2045   {"???",            0,            0,               0,               0            },
2046   {"stop",         0,            0,               0,               0            },   /* V25/35 only */
2047   {"???",            0,            0,               0,               0            },
2048   // 0xa0
2049   {"???",            0,            0,               0,               0            },
2050   {"???",            0,            0,               0,               0            },
2051   {"???",            0,            0,               0,               0            },
2052   {"???",            0,            0,               0,               0            },
2053   {"???",            0,            0,               0,               0            },
2054   {"???",            0,            0,               0,               0            },
2055   {"???",            0,            0,               0,               0            },
2056   {"???",            0,            0,               0,               0            },
2057   {"???",            0,            0,               0,               0            },
2058   {"???",            0,            0,               0,               0            },
2059   {"???",            0,            0,               0,               0            },
2060   {"???",            0,            0,               0,               0            },
2061   {"???",            0,            0,               0,               0            },
2062   {"???",            0,            0,               0,               0            },
2063   {"???",            0,            0,               0,               0            },
2064   {"???",            0,            0,               0,               0            },
2065   // 0xb0
2066   {"???",            0,            0,               0,               0            },
2067   {"???",            0,            0,               0,               0            },
2068   {"???",            0,            0,               0,               0            },
2069   {"???",            0,            0,               0,               0            },
2070   {"???",            0,            0,               0,               0            },
2071   {"???",            0,            0,               0,               0            },
2072   {"???",            0,            0,               0,               0            },
2073   {"???",            0,            0,               0,               0            },
2074   {"???",            0,            0,               0,               0            },
2075   {"???",            0,            0,               0,               0            },
2076   {"???",            0,            0,               0,               0            },
2077   {"???",            0,            0,               0,               0            },
2078   {"???",            0,            0,               0,               0            },
2079   {"???",            0,            0,               0,               0            },
2080   {"???",            0,            0,               0,               0            },
2081   {"???",            0,            0,               0,               0            },
2082   // 0xc0
2083   {"???",            0,            0,               0,               0            },
2084   {"???",            0,            0,               0,               0            },
2085   {"???",            0,            0,               0,               0            },
2086   {"???",            0,            0,               0,               0            },
2087   {"???",            0,            0,               0,               0            },
2088   {"???",            0,            0,               0,               0            },
2089   {"???",            0,            0,               0,               0            },
2090   {"???",            0,            0,               0,               0            },
2091   {"???",            0,            0,               0,               0            },
2092   {"???",            0,            0,               0,               0            },
2093   {"???",            0,            0,               0,               0            },
2094   {"???",            0,            0,               0,               0            },
2095   {"???",            0,            0,               0,               0            },
2096   {"???",            0,            0,               0,               0            },
2097   {"???",            0,            0,               0,               0            },
2098   {"???",            0,            0,               0,               0            },
2099   // 0xd0
2100   {"???",            0,            0,               0,               0            },
2101   {"???",            0,            0,               0,               0            },
2102   {"???",            0,            0,               0,               0            },
2103   {"???",            0,            0,               0,               0            },
2104   {"???",            0,            0,               0,               0            },
2105   {"???",            0,            0,               0,               0            },
2106   {"???",            0,            0,               0,               0            },
2107   {"???",            0,            0,               0,               0            },
2108   {"???",            0,            0,               0,               0            },
2109   {"???",            0,            0,               0,               0            },
2110   {"???",            0,            0,               0,               0            },
2111   {"???",            0,            0,               0,               0            },
2112   {"???",            0,            0,               0,               0            },
2113   {"???",            0,            0,               0,               0            },
2114   {"???",            0,            0,               0,               0            },
2115   {"???",            0,            0,               0,               0            },
2116   // 0xe0
2117   {"brkxa",         0,            PARAM_UI8,         0,               0            },   /* V33,53 only */
2118   {"???",            0,            0,               0,               0            },
2119   {"???",            0,            0,               0,               0            },
2120   {"???",            0,            0,               0,               0            },
2121   {"???",            0,            0,               0,               0            },
2122   {"???",            0,            0,               0,               0            },
2123   {"???",            0,            0,               0,               0            },
2124   {"???",            0,            0,               0,               0            },
2125   {"???",            0,            0,               0,               0            },
2126   {"???",            0,            0,               0,               0            },
2127   {"???",            0,            0,               0,               0            },
2128   {"???",            0,            0,               0,               0            },
2129   {"???",            0,            0,               0,               0            },
2130   {"???",            0,            0,               0,               0            },
2131   {"???",            0,            0,               0,               0            },
2132   {"???",            0,            0,               0,               0            },
2133   // 0xf0
2134   {"retxa",         0,            PARAM_UI8,         0,               0            },   /* V33,53 only */
2135   {"???",            0,            0,               0,               0            },
2136   {"???",            0,            0,               0,               0            },
2137   {"???",            0,            0,               0,               0            },
2138   {"???",            0,            0,               0,               0            },
2139   {"???",            0,            0,               0,               0            },
2140   {"???",            0,            0,               0,               0            },
2141   {"???",            0,            0,               0,               0            },
2142   {"???",            0,            0,               0,               0            },
2143   {"???",            0,            0,               0,               0            },
2144   {"???",            0,            0,               0,               0            },
2145   {"???",            0,            0,               0,               0            },
2146   {"???",            0,            0,               0,               0            },
2147   {"???",            0,            0,               0,               0            },
2148   {"???",            0,            0,               0,               0            },
2149   {"brkem",         0,            PARAM_UI8,         0,               0            }   /* V20,30,40,50 only */
2150};
2151
2152static const I386_OPCODE immb_table[8] =
2153{
2154   {"add",            0,            PARAM_RM8,         PARAM_I8,         0            },
2155   {"or",            0,            PARAM_RM8,         PARAM_I8,         0            },
2156   {"addc",         0,            PARAM_RM8,         PARAM_I8,         0            },
2157   {"subc",         0,            PARAM_RM8,         PARAM_I8,         0            },
2158   {"and",            0,            PARAM_RM8,         PARAM_I8,         0            },
2159   {"sub",            0,            PARAM_RM8,         PARAM_I8,         0            },
2160   {"xor",            0,            PARAM_RM8,         PARAM_I8,         0            },
2161   {"cmp",            0,            PARAM_RM8,         PARAM_I8,         0            }
2162};
2163
2164static const I386_OPCODE immw_table[8] =
2165{
2166   {"add",            0,            PARAM_RM16,         PARAM_IMM,         0            },
2167   {"or",            0,            PARAM_RM16,         PARAM_IMM,         0            },
2168   {"addc",         0,            PARAM_RM16,         PARAM_IMM,         0            },
2169   {"subc",         0,            PARAM_RM16,         PARAM_IMM,         0            },
2170   {"and",            0,            PARAM_RM16,         PARAM_IMM,         0            },
2171   {"sub",            0,            PARAM_RM16,         PARAM_IMM,         0            },
2172   {"xor",            0,            PARAM_RM16,         PARAM_IMM,         0            },
2173   {"cmp",            0,            PARAM_RM16,         PARAM_IMM,         0            }
2174};
2175
2176static const I386_OPCODE immws_table[8] =
2177{
2178   {"add",            0,            PARAM_RM16,         PARAM_I8,         0            },
2179   {"or",            0,            PARAM_RM16,         PARAM_I8,         0            },
2180   {"addc",         0,            PARAM_RM16,         PARAM_I8,         0            },
2181   {"subc",         0,            PARAM_RM16,         PARAM_I8,         0            },
2182   {"and",            0,            PARAM_RM16,         PARAM_I8,         0            },
2183   {"sub",            0,            PARAM_RM16,         PARAM_I8,         0            },
2184   {"xor",            0,            PARAM_RM16,         PARAM_I8,         0            },
2185   {"cmp",            0,            PARAM_RM16,         PARAM_I8,         0            }
2186};
2187
2188static const I386_OPCODE shiftbi_table[8] =
2189{
2190   {"rol",            0,            PARAM_RM8,         PARAM_I8,         0            },
2191   {"ror",            0,            PARAM_RM8,         PARAM_I8,         0            },
2192   {"rolc",         0,            PARAM_RM8,         PARAM_I8,         0            },
2193   {"rorc",         0,            PARAM_RM8,         PARAM_I8,         0            },
2194   {"shl",            0,            PARAM_RM8,         PARAM_I8,         0            },
2195   {"shr",            0,            PARAM_RM8,         PARAM_I8,         0            },
2196   {"???",            0,            PARAM_RM8,         PARAM_I8,         0            },
2197   {"shra",         0,            PARAM_RM8,         PARAM_I8,         0            }
2198};
2199
2200static const I386_OPCODE shiftwi_table[8] =
2201{
2202   {"rol",            0,            PARAM_RM16,         PARAM_I8,         0            },
2203   {"ror",            0,            PARAM_RM16,         PARAM_I8,         0            },
2204   {"rolc",         0,            PARAM_RM16,         PARAM_I8,         0            },
2205   {"rorc",         0,            PARAM_RM16,         PARAM_I8,         0            },
2206   {"shl",            0,            PARAM_RM16,         PARAM_I8,         0            },
2207   {"shr",            0,            PARAM_RM16,         PARAM_I8,         0            },
2208   {"???",            0,            PARAM_RM16,         PARAM_I8,         0            },
2209   {"shra",         0,            PARAM_RM16,         PARAM_I8,         0            }
2210};
2211
2212static const I386_OPCODE shiftb_table[8] =
2213{
2214   {"rol",            0,            PARAM_RM8,         PARAM_1,         0            },
2215   {"ror",            0,            PARAM_RM8,         PARAM_1,         0            },
2216   {"rolc",         0,            PARAM_RM8,         PARAM_1,         0            },
2217   {"rorc",         0,            PARAM_RM8,         PARAM_1,         0            },
2218   {"shl",            0,            PARAM_RM8,         PARAM_1,         0            },
2219   {"shr",            0,            PARAM_RM8,         PARAM_1,         0            },
2220   {"???",            0,            PARAM_RM8,         PARAM_1,         0            },
2221   {"shra",         0,            PARAM_RM8,         PARAM_1,         0            }
2222};
2223
2224static const I386_OPCODE shiftw_table[8] =
2225{
2226   {"rol",            0,            PARAM_RM16,         PARAM_1,         0            },
2227   {"ror",            0,            PARAM_RM16,         PARAM_1,         0            },
2228   {"rolc",         0,            PARAM_RM16,         PARAM_1,         0            },
2229   {"rorc",         0,            PARAM_RM16,         PARAM_1,         0            },
2230   {"shl",            0,            PARAM_RM16,         PARAM_1,         0            },
2231   {"shr",            0,            PARAM_RM16,         PARAM_1,         0            },
2232   {"???",            0,            PARAM_RM16,         PARAM_1,         0            },
2233   {"shra",         0,            PARAM_RM16,         PARAM_1,         0            }
2234};
2235
2236static const I386_OPCODE shiftbv_table[8] =
2237{
2238   {"rol",            0,            PARAM_RM8,         PARAM_CL,         0            },
2239   {"ror",            0,            PARAM_RM8,         PARAM_CL,         0            },
2240   {"rolc",         0,            PARAM_RM8,         PARAM_CL,         0            },
2241   {"rorc",         0,            PARAM_RM8,         PARAM_CL,         0            },
2242   {"shl",            0,            PARAM_RM8,         PARAM_CL,         0            },
2243   {"shr",            0,            PARAM_RM8,         PARAM_CL,         0            },
2244   {"???",            0,            PARAM_RM8,         PARAM_CL,         0            },
2245   {"shra",         0,            PARAM_RM8,         PARAM_CL,         0            }
2246};
2247
2248static const I386_OPCODE shiftwv_table[8] =
2249{
2250   {"rol",            0,            PARAM_RM16,         PARAM_CL,         0            },
2251   {"ror",            0,            PARAM_RM16,         PARAM_CL,         0            },
2252   {"rolc",         0,            PARAM_RM16,         PARAM_CL,         0            },
2253   {"rorc",         0,            PARAM_RM16,         PARAM_CL,         0            },
2254   {"shl",            0,            PARAM_RM16,         PARAM_CL,         0            },
2255   {"shr",            0,            PARAM_RM16,         PARAM_CL,         0            },
2256   {"???",            0,            PARAM_RM16,         PARAM_CL,         0            },
2257   {"shra",         0,            PARAM_RM16,         PARAM_CL,         0            }
2258};
2259
2260static const I386_OPCODE group1b_table[8] =
2261{
2262   {"test",         0,            PARAM_RM8,         PARAM_I8,         0            },
2263   {"???",            0,            0,               0,               0            },
2264   {"not",            0,            PARAM_RM8,         0,               0            },
2265   {"neg",            0,            PARAM_RM8,         0,               0            },
2266   {"mulu",         0,            PARAM_RM8,         0,               0            },
2267   {"mul",            0,            PARAM_RM8,         0,               0            },
2268   {"divu",         0,            PARAM_RM8,         0,               0            },
2269   {"div",            0,            PARAM_RM8,         0,               0            }
2270};
2271
2272static const I386_OPCODE group1w_table[8] =
2273{
2274   {"test",         0,            PARAM_RM16,         PARAM_IMM,         0            },
2275   {"???",            0,            0,               0,               0            },
2276   {"not",            0,            PARAM_RM16,         0,               0            },
2277   {"neg",            0,            PARAM_RM16,         0,               0            },
2278   {"mulu",         0,            PARAM_RM16,         0,               0            },
2279   {"mul",            0,            PARAM_RM16,         0,               0            },
2280   {"divu",         0,            PARAM_RM16,         0,               0            },
2281   {"div",            0,            PARAM_RM16,         0,               0            }
2282};
2283
2284static const I386_OPCODE group2b_table[8] =
2285{
2286   {"inc",            0,            PARAM_RM8,         0,               0            },
2287   {"dec",            0,            PARAM_RM8,         0,               0            },
2288   {"???",            0,            0,               0,               0            },
2289   {"???",            0,            0,               0,               0            },
2290   {"???",            0,            0,               0,               0            },
2291   {"???",            0,            0,               0,               0            },
2292   {"???",            0,            0,               0,               0            },
2293   {"???",            0,            0,               0,               0            }
2294};
2295
2296static const I386_OPCODE group2w_table[8] =
2297{
2298   {"inc",            0,            PARAM_RM16,         0,               0            },
2299   {"dec",            0,            PARAM_RM16,         0,               0            },
2300   {"call",         0,            PARAM_RM16,         0,               0,            DASMFLAG_STEP_OVER},
2301   {"call    far ptr ",0,            PARAM_RM16,         0,               0,            DASMFLAG_STEP_OVER},
2302   {"br",            0,            PARAM_RM16,         0,               0            },
2303   {"br      far ptr ",0,            PARAM_RM16,         0,               0            },
2304   {"push",         0,            PARAM_RM16,         0,               0            },
2305   {"???",            0,            0,               0,               0            }
2306};
2307
2308static const GROUP_OP group_op_table[] =
2309{
2310   { "immb",            immb_table            },
2311   { "immw",            immw_table            },
2312   { "immws",            immws_table            },
2313   { "shiftbi",         shiftbi_table         },
2314   { "shiftwi",         shiftwi_table         },
2315   { "shiftb",            shiftb_table         },
2316   { "shiftw",            shiftw_table         },
2317   { "shiftbv",         shiftbv_table         },
2318   { "shiftwv",         shiftwv_table         },
2319   { "group1b",         group1b_table         },
2320   { "group1w",         group1w_table         },
2321   { "group2b",         group2b_table         },
2322   { "group2w",         group2w_table         }
2323};
2324
2325
2326
2327static const char *nec_reg[8] = { "aw",  "cw",  "dw",  "bw",  "sp",  "bp",  "ix",  "iy" };
2328static const char *neg_reg8[8] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
2329static const char *nec_sreg[8] = { "ds1", "ps", "ss", "ds0", "???", "???", "???", "???" };
2330
2331static UINT32 pc;
2332static UINT8 modrm;
2333static UINT32 segment;
2334static offs_t dasm_flags;
2335static char modrm_string[256];
2336
2337#define MODRM_REG1   ((modrm >> 3) & 0x7)
2338#define MODRM_REG2   (modrm & 0x7)
2339
2340INLINE UINT8 FETCH(void)
2341{
2342   if ((opcode_ptr - opcode_ptr_base) + 1 > 15)
2343      return 0xff;
2344   pc++;
2345   return *opcode_ptr++;
2346}
2347
2348INLINE UINT16 FETCH16(void)
2349{
2350   UINT16 d;
2351   if ((opcode_ptr - opcode_ptr_base) + 2 > 15)
2352      return 0xffff;
2353   d = opcode_ptr[0] | (opcode_ptr[1] << 8);
2354   opcode_ptr += 2;
2355   pc += 2;
2356   return d;
2357}
2358
2359INLINE UINT8 FETCHD(void)
2360{
2361   if ((opcode_ptr - opcode_ptr_base) + 1 > 15)
2362      return 0xff;
2363   pc++;
2364   return *opcode_ptr++;
2365}
2366
2367INLINE UINT16 FETCHD16(void)
2368{
2369   UINT16 d;
2370   if ((opcode_ptr - opcode_ptr_base) + 2 > 15)
2371      return 0xffff;
2372   d = opcode_ptr[0] | (opcode_ptr[1] << 8);
2373   opcode_ptr += 2;
2374   pc += 2;
2375   return d;
2376}
2377
2378static char *hexstring(UINT32 value, int digits)
2379{
2380   static char buffer[20];
2381   buffer[0] = '0';
2382   if (digits)
2383      sprintf(&buffer[1], "%0*Xh", digits, value);
2384   else
2385      sprintf(&buffer[1], "%Xh", value);
2386   return (buffer[1] >= '0' && buffer[1] <= '9') ? &buffer[1] : &buffer[0];
2387}
2388
2389static char *shexstring(UINT32 value, int digits, int always)
2390{
2391   static char buffer[20];
2392   if (value >= 0x80000000)
2393      sprintf(buffer, "-%s", hexstring(-value, digits));
2394   else if (always)
2395      sprintf(buffer, "+%s", hexstring(value, digits));
2396   else
2397      return hexstring(value, digits);
2398   return buffer;
2399}
2400
2401static void handle_modrm(char* s)
2402{
2403   INT8 disp8;
2404   INT16 disp16;
2405   UINT8 mod, rm;
2406
2407   modrm = FETCHD();
2408   mod = (modrm >> 6) & 0x3;
2409   rm = (modrm & 0x7);
2410
2411   if( modrm >= 0xc0 )
2412      return;
2413
2414   switch(segment)
2415   {
2416      case SEG_PS: s += sprintf( s, "ps:" ); break;
2417      case SEG_DS0: s += sprintf( s, "ds0:" ); break;
2418      case SEG_DS1: s += sprintf( s, "ds1:" ); break;
2419      case SEG_SS: s += sprintf( s, "ss:" ); break;
2420   }
2421
2422   s += sprintf( s, "[" );
2423   switch( rm )
2424   {
2425      case 0: s += sprintf( s, "bw+ix" ); break;
2426      case 1: s += sprintf( s, "bw+iy" ); break;
2427      case 2: s += sprintf( s, "bw+ix" ); break;
2428      case 3: s += sprintf( s, "bw+iy" ); break;
2429      case 4: s += sprintf( s, "ix" ); break;
2430      case 5: s += sprintf( s, "iy" ); break;
2431      case 6:
2432         if( mod == 0 ) {
2433            disp16 = FETCHD16();
2434            s += sprintf( s, "%s", hexstring((unsigned) (UINT16) disp16, 0) );
2435         } else {
2436            s += sprintf( s, "bp" );
2437         }
2438         break;
2439      case 7: s += sprintf( s, "bw" ); break;
2440   }
2441   if( mod == 1 ) {
2442      disp8 = FETCHD();
2443      s += sprintf( s, "%s", shexstring((INT32)disp8, 0, TRUE) );
2444   } else if( mod == 2 ) {
2445      disp16 = FETCHD16();
2446      s += sprintf( s, "%s", shexstring((INT32)disp16, 0, TRUE) );
2447   }
2448   s += sprintf( s, "]" );
2449}
2450
2451static char* handle_param(char* s, UINT32 param)
2452{
2453   UINT8 i8;
2454   UINT16 i16;
2455   UINT16 ptr;
2456   UINT32 addr;
2457   INT8 d8;
2458   INT16 d16;
2459
2460   switch(param)
2461   {
2462      case PARAM_REG8:
2463         s += sprintf( s, "%s", neg_reg8[MODRM_REG1] );
2464         break;
2465
2466      case PARAM_REG16:
2467         s += sprintf( s, "%s", nec_reg[MODRM_REG1] );
2468         break;
2469
2470      case PARAM_REG2_8:
2471         s += sprintf( s, "%s", neg_reg8[MODRM_REG2] );
2472         break;
2473
2474      case PARAM_REG2_16:
2475         s += sprintf( s, "%s", nec_reg[MODRM_REG2] );
2476         break;
2477
2478      case PARAM_RM8:
2479         if( modrm >= 0xc0 ) {
2480            s += sprintf( s, "%s", neg_reg8[MODRM_REG2] );
2481         } else {
2482            s += sprintf( s, "byte ptr " );
2483            s += sprintf( s, "%s", modrm_string );
2484         }
2485         break;
2486
2487      case PARAM_RM16:
2488         if( modrm >= 0xc0 ) {
2489            s += sprintf( s, "%s", nec_reg[MODRM_REG2] );
2490         } else {
2491            s += sprintf( s, "word ptr " );
2492            s += sprintf( s, "%s", modrm_string );
2493         }
2494         break;
2495
2496      case PARAM_I4:
2497         i8 = FETCHD();
2498         s += sprintf( s, "%d", i8 & 0x0f );
2499         break;
2500
2501      case PARAM_I8:
2502         i8 = FETCHD();
2503         s += sprintf( s, "%s", shexstring((INT8)i8, 0, FALSE) );
2504         break;
2505
2506      case PARAM_I16:
2507         i16 = FETCHD16();
2508         s += sprintf( s, "%s", shexstring((INT16)i16, 0, FALSE) );
2509         break;
2510
2511      case PARAM_UI8:
2512         i8 = FETCHD();
2513         s += sprintf( s, "%s", shexstring((UINT8)i8, 0, FALSE) );
2514         break;
2515
2516      case PARAM_UI16:
2517         i16 = FETCHD16();
2518         s += sprintf( s, "%s", shexstring((UINT16)i16, 0, FALSE) );
2519         break;
2520
2521      case PARAM_IMM:
2522         i16 = FETCHD16();
2523         s += sprintf( s, "%s", hexstring(i16, 0) );
2524         break;
2525
2526      case PARAM_ADDR:
2527         addr = FETCHD16();
2528         ptr = FETCHD16();
2529         s += sprintf( s, "%s:", hexstring(ptr, 4) );
2530         s += sprintf( s, "%s", hexstring(addr, 0) );
2531         break;
2532
2533      case PARAM_REL16:
2534         /* make sure to keep the relative offset within the segment */
2535         d16 = FETCHD16();
2536         s += sprintf( s, "%s", hexstring((pc & 0xFFFF0000) | ((pc + d16) & 0x0000FFFF), 0) );
2537         break;
2538
2539      case PARAM_REL8:
2540         d8 = FETCHD();
2541         s += sprintf( s, "%s", hexstring(pc + d8, 0) );
2542         break;
2543
2544      case PARAM_MEM_OFFS_B:
2545         d8 = FETCHD();
2546         s += sprintf( s, "[%s]", hexstring(d8, 0) );
2547         break;
2548
2549      case PARAM_MEM_OFFS_W:
2550         d16 = FETCHD16();
2551         s += sprintf( s, "[%s]", hexstring(d16, 0) );
2552         break;
2553
2554      case PARAM_SREG:
2555         s += sprintf( s, "%s", nec_sreg[MODRM_REG1] );
2556         break;
2557
2558      case PARAM_1:
2559         s += sprintf( s, "1" );
2560         break;
2561
2562      case PARAM_RBANK:
2563         s += sprintf( s, "%d", FETCHD() & 7 );
2564         break;
2565
2566      case PARAM_AL: s += sprintf( s, "al" ); break;
2567      case PARAM_CL: s += sprintf( s, "cl" ); break;
2568      case PARAM_DL: s += sprintf( s, "dl" ); break;
2569      case PARAM_BL: s += sprintf( s, "bl" ); break;
2570      case PARAM_AH: s += sprintf( s, "ah" ); break;
2571      case PARAM_CH: s += sprintf( s, "ch" ); break;
2572      case PARAM_DH: s += sprintf( s, "dh" ); break;
2573      case PARAM_BH: s += sprintf( s, "bh" ); break;
2574
2575      case PARAM_AW: s += sprintf( s, "aw" ); break;
2576      case PARAM_CW: s += sprintf( s, "cw" ); break;
2577      case PARAM_DW: s += sprintf( s, "dw" ); break;
2578      case PARAM_BW: s += sprintf( s, "bw" ); break;
2579      case PARAM_SP: s += sprintf( s, "sp" ); break;
2580      case PARAM_BP: s += sprintf( s, "bp" ); break;
2581      case PARAM_IX: s += sprintf( s, "ix" ); break;
2582      case PARAM_IY: s += sprintf( s, "iy" ); break;
2583   }
2584   return s;
2585}
2586
2587static void handle_fpu(char *s, UINT8 op1, UINT8 op2)
2588{
2589   switch (op1 & 0x7)
2590   {
2591      case 0:      // Group D8
2592      {
2593         if (op2 < 0xc0)
2594         {
2595            pc--;      // adjust fetch pointer, so modrm byte read again
2596            opcode_ptr--;
2597            handle_modrm( modrm_string );
2598            switch ((op2 >> 3) & 0x7)
2599            {
2600               case 0: sprintf(s, "fadd    dword ptr %s", modrm_string); break;
2601               case 1: sprintf(s, "fmul    dword ptr %s", modrm_string); break;
2602               case 2: sprintf(s, "fcom    dword ptr %s", modrm_string); break;
2603               case 3: sprintf(s, "fcomp   dword ptr %s", modrm_string); break;
2604               case 4: sprintf(s, "fsub    dword ptr %s", modrm_string); break;
2605               case 5: sprintf(s, "fsubr   dword ptr %s", modrm_string); break;
2606               case 6: sprintf(s, "fdiv    dword ptr %s", modrm_string); break;
2607               case 7: sprintf(s, "fdivr   dword ptr %s", modrm_string); break;
2608            }
2609         }
2610         else
2611         {
2612            switch ((op2 >> 3) & 0x7)
2613            {
2614               case 0: sprintf(s, "fadd    st(0),st(%d)", op2 & 0x7); break;
2615               case 1: sprintf(s, "fcom    st(0),st(%d)", op2 & 0x7); break;
2616               case 2: sprintf(s, "fsub    st(0),st(%d)", op2 & 0x7); break;
2617               case 3: sprintf(s, "fdiv    st(0),st(%d)", op2 & 0x7); break;
2618               case 4: sprintf(s, "fmul    st(0),st(%d)", op2 & 0x7); break;
2619               case 5: sprintf(s, "fcomp   st(0),st(%d)", op2 & 0x7); break;
2620               case 6: sprintf(s, "fsubr   st(0),st(%d)", op2 & 0x7); break;
2621               case 7: sprintf(s, "fdivr   st(0),st(%d)", op2 & 0x7); break;
2622            }
2623         }
2624         break;
2625      }
2626
2627      case 1:      // Group D9
2628      {
2629         if (op2 < 0xc0)
2630         {
2631            pc--;      // adjust fetch pointer, so modrm byte read again
2632            opcode_ptr--;
2633            handle_modrm( modrm_string );
2634            switch ((op2 >> 3) & 0x7)
2635            {
2636               case 0: sprintf(s, "fld     dword ptr %s", modrm_string); break;
2637               case 1: sprintf(s, "??? (FPU)"); break;
2638               case 2: sprintf(s, "fst     dword ptr %s", modrm_string); break;
2639               case 3: sprintf(s, "fstp    dword ptr %s", modrm_string); break;
2640               case 4: sprintf(s, "fldenv  word ptr %s", modrm_string); break;
2641               case 5: sprintf(s, "fldcw   word ptr %s", modrm_string); break;
2642               case 6: sprintf(s, "fstenv  word ptr %s", modrm_string); break;
2643               case 7: sprintf(s, "fstcw   word ptr %s", modrm_string); break;
2644            }
2645         }
2646         else
2647         {
2648            switch (op2 & 0x3f)
2649            {
2650               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2651                  sprintf(s, "fld     st(0),st(%d)", op2 & 0x7); break;
2652
2653               case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2654                  sprintf(s, "fxch    st(0),st(%d)", op2 & 0x7); break;
2655
2656               case 0x10: sprintf(s, "fnop"); break;
2657               case 0x20: sprintf(s, "fchs"); break;
2658               case 0x21: sprintf(s, "fabs"); break;
2659               case 0x24: sprintf(s, "ftst"); break;
2660               case 0x25: sprintf(s, "fxam"); break;
2661               case 0x28: sprintf(s, "fld1"); break;
2662               case 0x29: sprintf(s, "fldl2t"); break;
2663               case 0x2a: sprintf(s, "fldl2e"); break;
2664               case 0x2b: sprintf(s, "fldpi"); break;
2665               case 0x2c: sprintf(s, "fldlg2"); break;
2666               case 0x2d: sprintf(s, "fldln2"); break;
2667               case 0x2e: sprintf(s, "fldz"); break;
2668               case 0x30: sprintf(s, "f2xm1"); break;
2669               case 0x31: sprintf(s, "fyl2x"); break;
2670               case 0x32: sprintf(s, "fptan"); break;
2671               case 0x33: sprintf(s, "fpatan"); break;
2672               case 0x34: sprintf(s, "fxtract"); break;
2673               case 0x35: sprintf(s, "fprem1"); break;
2674               case 0x36: sprintf(s, "fdecstp"); break;
2675               case 0x37: sprintf(s, "fincstp"); break;
2676               case 0x38: sprintf(s, "fprem"); break;
2677               case 0x39: sprintf(s, "fyl2xp1"); break;
2678               case 0x3a: sprintf(s, "fsqrt"); break;
2679               case 0x3b: sprintf(s, "fsincos"); break;
2680               case 0x3c: sprintf(s, "frndint"); break;
2681               case 0x3d: sprintf(s, "fscale"); break;
2682               case 0x3e: sprintf(s, "fsin"); break;
2683               case 0x3f: sprintf(s, "fcos"); break;
2684
2685               default: sprintf(s, "??? (FPU)"); break;
2686            }
2687         }
2688         break;
2689      }
2690
2691      case 2:      // Group DA
2692      {
2693         if (op2 < 0xc0)
2694         {
2695            pc--;      // adjust fetch pointer, so modrm byte read again
2696            opcode_ptr--;
2697            handle_modrm( modrm_string );
2698            switch ((op2 >> 3) & 0x7)
2699            {
2700               case 0: sprintf(s, "fiadd   dword ptr %s", modrm_string); break;
2701               case 1: sprintf(s, "fimul   dword ptr %s", modrm_string); break;
2702               case 2: sprintf(s, "ficom   dword ptr %s", modrm_string); break;
2703               case 3: sprintf(s, "ficomp  dword ptr %s", modrm_string); break;
2704               case 4: sprintf(s, "fisub   dword ptr %s", modrm_string); break;
2705               case 5: sprintf(s, "fisubr  dword ptr %s", modrm_string); break;
2706               case 6: sprintf(s, "fidiv   dword ptr %s", modrm_string); break;
2707               case 7: sprintf(s, "fidivr  dword ptr %s", modrm_string); break;
2708            }
2709         }
2710         else
2711         {
2712            switch (op2 & 0x3f)
2713            {
2714               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2715                  sprintf(s, "fcmovb  st(0),st(%d)", op2 & 0x7); break;
2716
2717               case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2718                  sprintf(s, "fcmove  st(0),st(%d)", op2 & 0x7); break;
2719
2720               case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
2721                  sprintf(s, "fcmovbe st(0),st(%d)", op2 & 0x7); break;
2722
2723               case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
2724                  sprintf(s, "fcmovu  st(0),st(%d)", op2 & 0x7); break;
2725
2726               default: sprintf(s, "??? (FPU)"); break;
2727
2728            }
2729         }
2730         break;
2731      }
2732
2733      case 3:      // Group DB
2734      {
2735         if (op2 < 0xc0)
2736         {
2737            pc--;      // adjust fetch pointer, so modrm byte read again
2738            opcode_ptr--;
2739            handle_modrm( modrm_string );
2740            switch ((op2 >> 3) & 0x7)
2741            {
2742               case 0: sprintf(s, "fild    dword ptr %s", modrm_string); break;
2743               case 1: sprintf(s, "??? (FPU)"); break;
2744               case 2: sprintf(s, "fist    dword ptr %s", modrm_string); break;
2745               case 3: sprintf(s, "fistp   dword ptr %s", modrm_string); break;
2746               case 4: sprintf(s, "??? (FPU)"); break;
2747               case 5: sprintf(s, "fld     tword ptr %s", modrm_string); break;
2748               case 6: sprintf(s, "??? (FPU)"); break;
2749               case 7: sprintf(s, "fstp    tword ptr %s", modrm_string); break;
2750            }
2751         }
2752         else
2753         {
2754            switch (op2 & 0x3f)
2755            {
2756               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2757                  sprintf(s, "fcmovnb st(0),st(%d)", op2 & 0x7); break;
2758
2759               case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2760                  sprintf(s, "fcmovne st(0),st(%d)", op2 & 0x7); break;
2761
2762               case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
2763                  sprintf(s, "fcmovnbe st(0),st(%d)", op2 & 0x7); break;
2764
2765               case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
2766                  sprintf(s, "fcmovnu st(0),st(%d)", op2 & 0x7); break;
2767
2768               case 0x22: sprintf(s, "fclex"); break;
2769               case 0x23: sprintf(s, "finit"); break;
2770
2771               case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2772                  sprintf(s, "fucomi  st(0),st(%d)", op2 & 0x7); break;
2773
2774               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
2775                  sprintf(s, "fcomi   st(0),st(%d)", op2 & 0x7); break;
2776
2777               default: sprintf(s, "??? (FPU)"); break;
2778            }
2779         }
2780         break;
2781      }
2782
2783      case 4:      // Group DC
2784      {
2785         if (op2 < 0xc0)
2786         {
2787            pc--;      // adjust fetch pointer, so modrm byte read again
2788            opcode_ptr--;
2789            handle_modrm( modrm_string );
2790            switch ((op2 >> 3) & 0x7)
2791            {
2792               case 0: sprintf(s, "fadd    qword ptr %s", modrm_string); break;
2793               case 1: sprintf(s, "fmul    qword ptr %s", modrm_string); break;
2794               case 2: sprintf(s, "fcom    qword ptr %s", modrm_string); break;
2795               case 3: sprintf(s, "fcomp   qword ptr %s", modrm_string); break;
2796               case 4: sprintf(s, "fsub    qword ptr %s", modrm_string); break;
2797               case 5: sprintf(s, "fsubr   qword ptr %s", modrm_string); break;
2798               case 6: sprintf(s, "fdiv    qword ptr %s", modrm_string); break;
2799               case 7: sprintf(s, "fdivr   qword ptr %s", modrm_string); break;
2800            }
2801         }
2802         else
2803         {
2804            switch (op2 & 0x3f)
2805            {
2806               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2807                  sprintf(s, "fadd    st(%d),st(0)", op2 & 0x7); break;
2808
2809               case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2810                  sprintf(s, "fmul    st(%d),st(0)", op2 & 0x7); break;
2811
2812               case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
2813                  sprintf(s, "fsubr   st(%d),st(0)", op2 & 0x7); break;
2814
2815               case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2816                  sprintf(s, "fsub    st(%d),st(0)", op2 & 0x7); break;
2817
2818               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
2819                  sprintf(s, "fdivr   st(%d),st(0)", op2 & 0x7); break;
2820
2821               case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
2822                  sprintf(s, "fdiv    st(%d),st(0)", op2 & 0x7); break;
2823
2824               default: sprintf(s, "??? (FPU)"); break;
2825            }
2826         }
2827         break;
2828      }
2829
2830      case 5:      // Group DD
2831      {
2832         if (op2 < 0xc0)
2833         {
2834            pc--;      // adjust fetch pointer, so modrm byte read again
2835            opcode_ptr--;
2836            handle_modrm( modrm_string );
2837            switch ((op2 >> 3) & 0x7)
2838            {
2839               case 0: sprintf(s, "fld     qword ptr %s", modrm_string); break;
2840               case 1: sprintf(s, "??? (FPU)"); break;
2841               case 2: sprintf(s, "fst     qword ptr %s", modrm_string); break;
2842               case 3: sprintf(s, "fstp    qword ptr %s", modrm_string); break;
2843               case 4: sprintf(s, "frstor  %s", modrm_string); break;
2844               case 5: sprintf(s, "??? (FPU)"); break;
2845               case 6: sprintf(s, "fsave   %s", modrm_string); break;
2846               case 7: sprintf(s, "fstsw   word ptr %s", modrm_string); break;
2847            }
2848         }
2849         else
2850         {
2851            switch (op2 & 0x3f)
2852            {
2853               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2854                  sprintf(s, "ffree   st(%d)", op2 & 0x7); break;
2855
2856               case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
2857                  sprintf(s, "fst     st(%d)", op2 & 0x7); break;
2858
2859               case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
2860                  sprintf(s, "fstp    st(%d)", op2 & 0x7); break;
2861
2862               case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
2863                  sprintf(s, "fucom   st(%d), st(0)", op2 & 0x7); break;
2864
2865               case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2866                  sprintf(s, "fucomp  st(%d)", op2 & 0x7); break;
2867
2868               default: sprintf(s, "??? (FPU)"); break;
2869            }
2870         }
2871         break;
2872      }
2873
2874      case 6:      // Group DE
2875      {
2876         if (op2 < 0xc0)
2877         {
2878            pc--;      // adjust fetch pointer, so modrm byte read again
2879            opcode_ptr--;
2880            handle_modrm( modrm_string );
2881            switch ((op2 >> 3) & 0x7)
2882            {
2883               case 0: sprintf(s, "fiadd   word ptr %s", modrm_string); break;
2884               case 1: sprintf(s, "fimul   word ptr %s", modrm_string); break;
2885               case 2: sprintf(s, "ficom   word ptr %s", modrm_string); break;
2886               case 3: sprintf(s, "ficomp  word ptr %s", modrm_string); break;
2887               case 4: sprintf(s, "fisub   word ptr %s", modrm_string); break;
2888               case 5: sprintf(s, "fisubr  word ptr %s", modrm_string); break;
2889               case 6: sprintf(s, "fidiv   word ptr %s", modrm_string); break;
2890               case 7: sprintf(s, "fidivr  word ptr %s", modrm_string); break;
2891            }
2892         }
2893         else
2894         {
2895            switch (op2 & 0x3f)
2896            {
2897               case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
2898                  sprintf(s, "faddp   st(%d)", op2 & 0x7); break;
2899
2900               case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2901                  sprintf(s, "fmulp   st(%d)", op2 & 0x7); break;
2902
2903               case 0x19: sprintf(s, "fcompp"); break;
2904
2905               case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
2906                  sprintf(s, "fsubrp  st(%d)", op2 & 0x7); break;
2907
2908               case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2909                  sprintf(s, "fsubp   st(%d)", op2 & 0x7); break;
2910
2911               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
2912                  sprintf(s, "fdivrp  st(%d), st(0)", op2 & 0x7); break;
2913
2914               case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f:
2915                  sprintf(s, "fdivp   st(%d)", op2 & 0x7); break;
2916
2917               default: sprintf(s, "??? (FPU)"); break;
2918            }
2919         }
2920         break;
2921      }
2922
2923      case 7:      // Group DF
2924      {
2925         if (op2 < 0xc0)
2926         {
2927            pc--;      // adjust fetch pointer, so modrm byte read again
2928            opcode_ptr--;
2929            handle_modrm( modrm_string );
2930            switch ((op2 >> 3) & 0x7)
2931            {
2932               case 0: sprintf(s, "fild    word ptr %s", modrm_string); break;
2933               case 1: sprintf(s, "??? (FPU)"); break;
2934               case 2: sprintf(s, "fist    word ptr %s", modrm_string); break;
2935               case 3: sprintf(s, "fistp   word ptr %s", modrm_string); break;
2936               case 4: sprintf(s, "fbld    %s", modrm_string); break;
2937               case 5: sprintf(s, "fild    qword ptr %s", modrm_string); break;
2938               case 6: sprintf(s, "fbstp   %s", modrm_string); break;
2939               case 7: sprintf(s, "fistp   qword ptr %s", modrm_string); break;
2940            }
2941         }
2942         else
2943         {
2944            switch (op2 & 0x3f)
2945            {
2946               case 0x20: sprintf(s, "fstsw   aw"); break;
2947
2948               case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2949                  sprintf(s, "fucomip st(%d)", op2 & 0x7); break;
2950
2951               case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
2952                  sprintf(s, "fcomip  st(%d),st(0)", op2 & 0x7); break;
2953
2954               default: sprintf(s, "??? (FPU)"); break;
2955            }
2956         }
2957         break;
2958      }
2959   }
2960}
2961
2962static void decode_opcode(char *s, const I386_OPCODE *op, UINT8 op1)
2963{
2964   int i;
2965   UINT8 op2;
2966
2967   switch( op->flags )
2968   {
2969      case TWO_BYTE:
2970         op2 = FETCHD();
2971         decode_opcode( s, &necv_opcode_table2[op2], op1 );
2972         return;
2973
2974      case SEG_PS:
2975      case SEG_DS0:
2976      case SEG_DS1:
2977      case SEG_SS:
2978         segment = op->flags;
2979         op2 = FETCH();
2980         decode_opcode( s, &necv_opcode_table1[op2], op1 );
2981         return;
2982
2983      case PREFIX:
2984         s += sprintf( s, "%-8s", op->mnemonic );
2985         op2 = FETCH();
2986         decode_opcode( s, &necv_opcode_table1[op2], op1 );
2987         return;
2988
2989      case GROUP:
2990         handle_modrm( modrm_string );
2991         for( i=0; i < ARRAY_LENGTH(group_op_table); i++ ) {
2992            if( mame_stricmp(op->mnemonic, group_op_table[i].mnemonic) == 0 ) {
2993               decode_opcode( s, &group_op_table[i].opcode[MODRM_REG1], op1 );
2994               return;
2995            }
2996         }
2997         goto handle_unknown;
2998
2999      case FPU:
3000         op2 = FETCHD();
3001         handle_fpu( s, op1, op2);
3002         return;
3003
3004      case MODRM:
3005         handle_modrm( modrm_string );
3006         break;
3007   }
3008
3009   s += sprintf( s, "%-8s", op->mnemonic );
3010   dasm_flags = op->dasm_flags;
3011
3012   if( op->param1 != 0 ) {
3013      s = handle_param( s, op->param1 );
3014   }
3015
3016   if( op->param2 != 0 ) {
3017      s += sprintf( s, "," );
3018      s = handle_param( s, op->param2 );
3019   }
3020
3021   if( op->param3 != 0 ) {
3022      s += sprintf( s, "," );
3023      s = handle_param( s, op->param3 );
3024   }
3025   return;
3026
3027handle_unknown:
3028   sprintf(s, "???");
3029}
3030
3031int necv_dasm_one(char *buffer, UINT32 eip, const UINT8 *oprom)
3032{
3033   UINT8 op;
3034
3035   opcode_ptr = opcode_ptr_base = oprom;
3036   pc = eip;
3037   dasm_flags = 0;
3038   segment = 0;
3039
3040   op = FETCH();
3041
3042   decode_opcode( buffer, &necv_opcode_table1[op], op );
3043   return (pc-eip) | dasm_flags | DASMFLAG_SUPPORTED;
3044}
src/emu/cpu/x86emit.h
r936r937
200200
201201
202202/* floating point rounding modes */
203#define FPRND_NEAR            0
204#define FPRND_DOWN            1
205#define FPRND_UP            2
206#define FPRND_CHOP            3
207
208
209/* opcode flags (in upper 8 bits of opcode) */
210#define OPFLAG_8BITREG         (1 << 24)
211#define OPFLAG_8BITRM         (1 << 25)
212
213
214/* single byte opcodes */
215#define OP_ADD_Eb_Gb         0x00 | OPFLAG_8BITRM | OPFLAG_8BITREG
216#define OP_ADD_Ev_Gv         0x01
217#define OP_ADD_Gb_Eb         0x02 | OPFLAG_8BITRM | OPFLAG_8BITREG
218#define OP_ADD_Gv_Ev         0x03
219#define OP_ADD_AL_Ib         0x04
220#define OP_ADD_rAX_Iz         0x05
221#define OP_PUSH_ES              0x06
222#define OP_POP_ES               0x07
223#define OP_OR_Eb_Gb             0x08 | OPFLAG_8BITRM | OPFLAG_8BITREG
224#define OP_OR_Ev_Gv             0x09
225#define OP_OR_Gb_Eb             0x0a | OPFLAG_8BITRM | OPFLAG_8BITREG
226#define OP_OR_Gv_Ev             0x0b
227#define OP_OR_AL_Ib             0x0c
228#define OP_OR_eAX_Iv         0x0d
229#define OP_PUSH_CS              0x0e
230#define OP_EXTENDED             0x0f
231
232#define OP_ADC_Eb_Gb         0x10 | OPFLAG_8BITRM | OPFLAG_8BITREG
233#define OP_ADC_Ev_Gv         0x11
234#define OP_ADC_Gb_Eb         0x12 | OPFLAG_8BITRM | OPFLAG_8BITREG
235#define OP_ADC_Gv_Ev         0x13
236#define OP_ADC_AL_Ib         0x14
237#define OP_ADC_rAX_Iz         0x15
238#define OP_PUSH_SS              0x16
239#define OP_POP_SS               0x17
240#define OP_SBB_Eb_Gb         0x18 | OPFLAG_8BITRM | OPFLAG_8BITREG
241#define OP_SBB_Ev_Gv         0x19
242#define OP_SBB_Gb_Eb         0x1a | OPFLAG_8BITRM | OPFLAG_8BITREG
243#define OP_SBB_Gv_Ev         0x1b
244#define OP_SBB_AL_Ib         0x1c
245#define OP_SBB_eAX_Iv         0x1d
246#define OP_PUSH_DS              0x1e
247#define OP_POP_DS               0x1f
248
249#define OP_AND_Eb_Gb         0x20 | OPFLAG_8BITRM | OPFLAG_8BITREG
250#define OP_AND_Ev_Gv         0x21
251#define OP_AND_Gb_Eb         0x22 | OPFLAG_8BITRM | OPFLAG_8BITREG
252#define OP_AND_Gv_Ev         0x23
253#define OP_AND_AL_Ib         0x24
254#define OP_AND_rAX_Iz         0x25
255#define PREFIX_ES               0x26
256#define OP_DAA                 0x27
257#define OP_SUB_Eb_Gb         0x28 | OPFLAG_8BITRM | OPFLAG_8BITREG
258#define OP_SUB_Ev_Gv         0x29
259#define OP_SUB_Gb_Eb         0x2a | OPFLAG_8BITRM | OPFLAG_8BITREG
260#define OP_SUB_Gv_Ev         0x2b
261#define OP_SUB_AL_Ib         0x2c
262#define OP_SUB_eAX_Iv         0x2d
263#define PREFIX_CS               0x2e
264#define OP_DAS                 0x2f
265
266#define OP_XOR_Eb_Gb         0x30 | OPFLAG_8BITRM | OPFLAG_8BITREG
267#define OP_XOR_Ev_Gv         0x31
268#define OP_XOR_Gb_Eb         0x32 | OPFLAG_8BITRM | OPFLAG_8BITREG
269#define OP_XOR_Gv_Ev         0x33
270#define OP_XOR_AL_Ib         0x34
271#define OP_XOR_rAX_Iz         0x35
272#define PREFIX_SS               0x36
273#define OP_AAA                 0x37
274#define OP_CMP_Eb_Gb         0x38 | OPFLAG_8BITRM | OPFLAG_8BITREG
275#define OP_CMP_Ev_Gv         0x39
276#define OP_CMP_Gb_Eb         0x3a | OPFLAG_8BITRM | OPFLAG_8BITREG
277#define OP_CMP_Gv_Ev         0x3b
278#define OP_CMP_AL_Ib         0x3c
279#define OP_CMP_eAX_Iv         0x3d
280#define PREFIX_DS               0x3e
281#define OP_AAS                 0x3f
282
283#define OP_REX               0x40
284#define OP_REX_B            0x41
285#define OP_REX_X            0x42
286#define OP_REX_XB            0x43
287#define OP_REX_R            0x44
288#define OP_REX_RB            0x45
289#define OP_REX_RX            0x46
290#define OP_REX_RXB            0x47
291#define OP_REX_W            0x48
292#define OP_REX_WB            0x49
293#define OP_REX_WX            0x4a
294#define OP_REX_WXB            0x4b
295#define OP_REX_WR            0x4c
296#define OP_REX_WRB            0x4d
297#define OP_REX_WRX            0x4e
298#define OP_REX_WRXB            0x4f
299
300#define OP_PUSH_rAX            0x50
301#define OP_PUSH_rCX            0x51
302#define OP_PUSH_rDX            0x52
303#define OP_PUSH_rBX            0x53
304#define OP_PUSH_rSP            0x54
305#define OP_PUSH_rBP            0x55
306#define OP_PUSH_rSI            0x56
307#define OP_PUSH_rDI            0x57
308#define OP_POP_rAX            0x58
309#define OP_POP_rCX            0x59
310#define OP_POP_rDX            0x5a
311#define OP_POP_rBX            0x5b
312#define OP_POP_rSP            0x5c
313#define OP_POP_rBP            0x5d
314#define OP_POP_rSI            0x5e
315#define OP_POP_rDI            0x5f
316
317#define OP_PUSHA            0x60
318#define OP_POPA               0x61
319#define OP_BOUND_Gv_Ma         0x62
320#define OP_ARPL_Ew_Gw         0x63
321#define OP_MOVSXD_Gv_Ev         0x63
322#define PREFIX_FS            0x64
323#define PREFIX_GS            0x65
324#define PREFIX_OPSIZE         0x66
325#define PREFIX_ADSIZE         0x67
326#define OP_PUSH_Iz            0x68
327#define OP_IMUL_Gv_Ev_Iz       0x69
328#define OP_PUSH_Ib            0x6a
329#define OP_IMUL_Gv_Ev_Ib      0x6b
330#define OP_INS_Yb_DX         0x6c
331#define OP_INS_Yz_DX         0x6d
332#define OP_OUTS_DX_Xb         0x6e
333#define OP_OUTS_DX_Xz         0x6f
334
335#define OP_JCC_O_Jb            0x70
336#define OP_JCC_NO_Jb         0x71
337#define OP_JCC_B_Jb            0x72
338#define OP_JCC_C_Jb            0x72
339#define OP_JCC_NAE_Jb         0x72
340#define OP_JCC_AE_Jb         0x73
341#define OP_JCC_NB_Jb         0x73
342#define OP_JCC_NC_Jb         0x73
343#define OP_JCC_E_Jb            0x74
344#define OP_JCC_Z_Jb            0x74
345#define OP_JCC_NE_Jb         0x75
346#define OP_JCC_NZ_Jb         0x75
347#define OP_JCC_BE_Jb         0x76
348#define OP_JCC_NA_Jb         0x76
349#define OP_JCC_A_Jb            0x77
350#define OP_JCC_NBE_Jb         0x77
351#define OP_JCC_S_Jb            0x78
352#define OP_JCC_NS_Jb         0x79
353#define OP_JCC_P_Jb            0x7a
354#define OP_JCC_PE_Jb         0x7a
355#define OP_JCC_NP_Jb         0x7b
356#define OP_JCC_PO_Jb         0x7b
357#define OP_JCC_L_Jb            0x7c
358#define OP_JCC_NGE_Jb         0x7c
359#define OP_JCC_NL_Jb         0x7d
360#define OP_JCC_GE_Jb         0x7d
361#define OP_JCC_LE_Jb         0x7e
362#define OP_JCC_NG_Jb         0x7e
363#define OP_JCC_NLE_Jb         0x7f
364#define OP_JCC_G_Jb            0x7f
365
366#define OP_G1_Eb_Ib            0x80 | OPFLAG_8BITRM
367#define OP_G1_Ev_Iz            0x81
368#define OP_G1_Eb_Ibx         0x82 | OPFLAG_8BITRM
369#define OP_G1_Ev_Ib            0x83
370#define OP_TEST_Eb_Gb         0x84 | OPFLAG_8BITRM | OPFLAG_8BITREG
371#define OP_TEST_Ev_Gv         0x85
372#define OP_XCHG_Eb_Gb         0x86 | OPFLAG_8BITRM | OPFLAG_8BITREG
373#define OP_XCHG_Ev_Gv         0x87
374#define OP_MOV_Eb_Gb         0x88 | OPFLAG_8BITRM | OPFLAG_8BITREG
375#define OP_MOV_Ev_Gv         0x89
376#define OP_MOV_Gb_Eb         0x8a | OPFLAG_8BITRM | OPFLAG_8BITREG
377#define OP_MOV_Gv_Ev         0x8b
378#define OP_MOV_Ev_Sw         0x8c
379#define OP_LEA_Gv_M            0x8d
380#define OP_MOV_Sw_Ew         0x8e
381#define OP_G1A_Ev            0x8f
382
383#define OP_NOP               0x90
384#define OP_PAUSE            0x90
385#define OP_XCHG_rCX            0x91
386#define OP_XCHG_rDX            0x92
387#define OP_XCHG_rBX            0x93
388#define OP_XCHG_rSP            0x94
389#define OP_XCHG_rBP            0x95
390#define OP_XCHG_rSI            0x96
391#define OP_XCHG_rDI            0x97
392#define OP_CBW               0x98
393#define OP_CWDE               0x98
394#define OP_CDQE               0x98
395#define OP_CWD               0x99
396#define OP_CDQ               0x99
397#define OP_CQO               0x99
398#define OP_CALLF_Ap            0x9a
399#define OP_FWAIT            0x9b
400#define OP_PUSHF_Fv            0x9c
401#define OP_POPF_Fv            0x9d
402#define OP_SAHF               0x9e
403#define OP_LAHF               0x9f
404
405#define OP_MOV_AL_Ob         0xa0
406#define OP_MOV_rAX_Ov         0xa1
407#define OP_MOV_Ob_AL         0xa2
408#define OP_MOV_Ov_rAX         0xa3
409#define OP_MOVS_Xb_Yb         0xa4
410#define OP_MOVS_Xv_Yv         0xa5
411#define OP_CMPS_Xb_Yb         0xa6
412#define OP_CMPS_Xv_Yv         0xa7
413#define OP_TEST_AL_Ib         0xa8
414#define OP_TEST_rAX_Iz         0xa9
415#define OP_STOS_Yb_AL         0xaa
416#define OP_STOS_Yv_rAX         0xab
417#define OP_LODS_AL_Xb         0xac
418#define OP_LODS_rAX_Xv         0xad
419#define OP_SCAS_AL_Yb         0xae
420#define OP_SCAC_rAX_Yv         0xaf
421
422#define OP_MOV_AL_Ib         0xb0
423#define OP_MOV_CL_Ib         0xb1
424#define OP_MOV_DL_Ib         0xb2
425#define OP_MOV_BL_Ib         0xb3
426#define OP_MOV_AH_Ib         0xb4
427#define OP_MOV_CH_Ib         0xb5
428#define OP_MOV_DH_Ib         0xb6
429#define OP_MOV_BH_Ib         0xb7
430#define OP_MOV_rAX_Iv         0xb8
431#define OP_MOV_rCX_Iv         0xb9
432#define OP_MOV_rDX_Iv         0xba
433#define OP_MOV_rBX_Iv         0xbb
434#define OP_MOV_rSP_Iv         0xbc
435#define OP_MOV_rBP_Iv         0xbd
436#define OP_MOV_rSI_Iv         0xbe
437#define OP_MOV_rDI_Iv         0xbf
438
439#define OP_G2_Eb_Ib            0xc0 | OPFLAG_8BITRM
440#define OP_G2_Ev_Ib            0xc1
441#define OP_RETN_Iw            0xc2
442#define OP_RETN               0xc3
443#define OP_LES_Gz_Mp         0xc4
444#define OP_LDS_Gz_Mp         0xc5
445#define OP_G11_Eb_Ib         0xc6 | OPFLAG_8BITRM
446#define OP_G11_Ev_Iz         0xc7
447#define OP_ENTER_Iw_Ib         0xc8
448#define OP_LEAVE            0xc9
449#define OP_RETF_Iw            0xca
450#define OP_RETF               0xcb
451#define OP_INT_3            0xcc
452#define OP_INT_Ib            0xcd
453#define OP_INTO               0xce
454#define OP_IRET               0xcf
455
456#define OP_G2_Eb_1            0xd0 | OPFLAG_8BITRM
457#define OP_G2_Ev_1            0xd1
458#define OP_G2_Eb_CL            0xd2 | OPFLAG_8BITRM
459#define OP_G2_Ev_CL            0xd3
460#define OP_AAM               0xd4
461#define OP_AAD               0xd5
462#define OP_XLAT               0xd7
463#define OP_ESC_D8            0xd8
464#define OP_ESC_D9            0xd9
465#define OP_ESC_DA            0xda
466#define OP_ESC_DB            0xdb
467#define OP_ESC_DC            0xdc
468#define OP_ESC_DD            0xdd
469#define OP_ESC_DE            0xde
470#define OP_ESC_DF            0xdf
471
472#define OP_LOOPNE_Jb         0xe0
473#define OP_LOOPE_Jb            0xe1
474#define OP_LOOP_Jb            0xe2
475#define OP_JrCXZ_Jb            0xe3
476#define OP_IN_AL_Ib            0xe4
477#define OP_IN_eAX_Ib         0xe5
478#define OP_OUT_Ib_AL         0xe6
479#define OP_OUT_Ib_eAX         0xe7
480#define OP_CALL_Jz            0xe8
481#define OP_JMP_Jz            0xe9
482#define OP_JMPF_AP            0xea
483#define OP_JMP_Jb            0xeb
484#define OP_IN_AL_DX            0xec
485#define OP_IN_eAX_D            0xed
486#define OP_OUT_DX_AL         0xee
487#define OP_OUT_DX_eAX         0xef
488
489#define PREFIX_LOCK            0xf0
490#define PREFIX_REPNE         0xf2
491#define PREFIX_REPE            0xf3
492#define OP_HLT               0xf4
493#define OP_CMC               0xf5
494#define OP_G3_Eb            0xf6 | OPFLAG_8BITRM
495#define OP_G3_Ev            0xf7
496#define OP_CLC               0xf8
497#define OP_STC               0xf9
498#define OP_CLI               0xfa
499#define OP_STI               0xfb
500#define OP_CLD               0xfc
501#define OP_STD               0xfd
502#define OP_G4               0xfe
503#define OP_G5               0xff
504
505
506/* double byte opcodes */
507#define OP_G6               0x0f00
508#define OP_G7               0x0f01
509#define OP_LAR_Gv_Ew         0x0f02
510#define OP_LSL_Gv_Ew         0x0f03
511#define OP_SYSCALL            0x0f05
512#define OP_CLTS               0x0f06
513#define OP_SYSRET            0x0f07
514#define OP_INVD               0x0f08
515#define OP_WBINVD            0x0f09
516#define OP_UD2               0x0f0b
517
518#define OP_MOVUPS_Vps_Wps      0x0f10
519#define OP_MOVSS_Vss_Wss      0xf30f10
520#define OP_MOVUPD_Vpd_Wpd      0x660f10
521#define OP_MOVSD_Vsd_Wsd      0xf20f10
522#define OP_MOVUPS_Wps_Vps      0x0f11
523#define OP_MOVSS_Wss_Vss      0xf30f11
524#define OP_MOVUPD_Wpd_Vpd      0x660f11
525#define OP_MOVSD_Wsd_Vsd      0xf20f11
526#define OP_MOVLPS_Vq_Mq         0x0f12
527#define OP_MOVLPD_Vq_Mq         0x660f12
528#define OP_MOVHLPS_Vq_Uq      0x0f12
529#define OP_MOVDDUP_Vq_Wq      0xf20f12
530#define OP_MOVSLDUP_Vq_Wq      0xf30f12
531#define OP_MOVLPS_Mq_Vq         0x0f13
532#define OP_MOVLPD_Mq_Vq         0x660f13
533#define OP_UNPCKLPS_Vps_Wq      0x0f14
534#define OP_UNPCKLPD_Vpd_Wq      0x660f14
535#define OP_UNPCKHPS_Vps_Wq      0x0f15
536#define OP_UNPCKHPD_Vpd_Wq      0x660f15
537#define OP_MOVHPS_Vq_Mq         0x0f16
538#define OP_MOVHPD_Vq_Mq         0x660f16
539#define OP_MOVLHPS_Vq_Uq      0x0f16
540#define OP_MOVSHDUP_Vq_Wq      0xf30f16
541#define OP_MOVHPS_Mq_Vq         0x0f17
542#define OP_MOVHPD_Mq_Vq         0x660f17
543#define OP_PREFETCH_G16         0x0f18
544
545#define OP_MOV_Rd_Cd         0x0f20
546#define OP_MOV_Rd_Dd         0x0f21
547#define OP_MOV_Cd_Rd         0x0f22
548#define OP_MOV_Dd_Rd         0x0f23
549#define OP_MOVAPS_Vps_Wps      0x0f28
550#define OP_MOVAPD_Vpd_Wpd      0x660f28
551#define OP_MOVAPS_Wps_Vps      0x0f29
552#define OP_MOVAPD_Wpd_Vpd      0x660f29
553#define OP_CVTPI2PS_Vps_Qq      0x0f2a
554#define OP_CVTSI2SS_Vss_Ed      0xf30f2a
555#define OP_CVTPI2PD_Vpd_Qq      0x660f2a
556#define OP_CVTSI2SD_Vsd_Ed      0xf20f2a
557#define OP_MOVNTPS_Mps_Vps      0x0f2b
558#define OP_MOVNTPD_Mpd_Vpd      0x660f2b
559#define OP_CVTTPS2PI_Pq_Wq      0x0f2c
560#define OP_CVTTSS2SI_Gd_Wss      0xf30f2c
561#define OP_CVTTPD2PI_Pq_Wpd      0x660f2c
562#define OP_CVTTSD2SI_Gd_Wsd      0xf20f2c
563#define OP_CVTPS2PI_Pq_Wq      0x0f2d
564#define OP_CVTSS2SI_Gd_Wss      0xf30f2d
565#define OP_CVTPD2PI_Pq_Wpd      0x660f2d
566#define OP_CVTSD2SI_Gd_Wsd      0xf20f2d
567#define OP_UCOMISS_Vss_Wss      0x0f2e
568#define OP_UCOMISD_Vsd_Wsd      0x660f2e
569#define OP_COMISS_Vss_Wss      0x0f2f
570#define OP_COMISD_Vsd_Wsd      0x660f2f
571
572#define OP_WRMSR            0x0f30
573#define OP_RDTSC            0x0f31
574#define OP_RDMSR            0x0f32
575#define OP_RDPMC            0x0f33
576#define OP_SYSENTER            0x0f34
577#define OP_SYSEXIT            0x0f35
578
579#define OP_CMOV_O_Gv_Ev         0x0f40
580#define OP_CMOV_NO_Gv_Ev      0x0f41
581#define OP_CMOV_B_Gv_Ev         0x0f42
582#define OP_CMOV_C_Gv_Ev         0x0f42
583#define OP_CMOV_AE_Gv_Ev      0x0f43
584#define OP_CMOV_NC_Gv_Ev      0x0f43
585#define OP_CMOV_E_Gv_Ev         0x0f44
586#define OP_CMOV_Z_Gv_Ev         0x0f44
587#define OP_CMOV_NE_Gv_Ev      0x0f45
588#define OP_CMOV_NZ_Gv_Ev      0x0f45
589#define OP_CMOV_BE_Gv_Ev      0x0f46
590#define OP_CMOV_A_Gv_Ev         0x0f47
591#define OP_CMOV_S_Gv_Ev         0x0f48
592#define OP_CMOV_NS_Gv_Ev      0x0f49
593#define OP_CMOV_P_Gv_Ev         0x0f4a
594#define OP_CMOV_PE_Gv_Ev      0x0f4a
595#define OP_CMOV_NP_Gv_Ev      0x0f4b
596#define OP_CMOV_PO_Gv_Ev      0x0f4b
597#define OP_CMOV_L_Gv_Ev         0x0f4c
598#define OP_CMOV_NGE_Gv_Ev      0x0f4c
599#define OP_CMOV_NL_Gv_Ev      0x0f4d
600#define OP_CMOV_GE_Gv_Ev      0x0f4d
601#define OP_CMOV_LE_Gv_Ev      0x0f4e
602#define OP_CMOV_NG_Gv_Ev      0x0f4e
603#define OP_CMOV_NLE_Gv_Ev      0x0f4f
604#define OP_CMOV_G_Gv_Ev         0x0f4f
605
606#define OP_MOVMSKPS_Gd_Ups      0x0f50
607#define OP_MOVMSKPD_Gd_Upd      0x660f50
608#define OP_SQRTPS_Vps_Wps      0x0f51
609#define OP_SQRTSS_Vss_Wss      0xf30f51
610#define OP_SQRTPD_Vpd_Wpd      0x660f51
611#define OP_SQRTSD_Vsd_Wsd      0xf20f51
612#define OP_RSQRTPS_Vps_Wps      0x0f52
613#define OP_RSQRTSS_Vss_Wss      0xf30f52
614#define OP_RCPPS_Vps_Wps      0x0f53
615#define OP_RCPSS_Vss_Wss      0xf30f53
616#define OP_ANDPS_Vps_Wps      0x0f54
617#define OP_ANDPD_Vpd_Wpd      0x660f54
618#define OP_ANDNPS_Vps_Wps      0x0f55
619#define OP_ANDNPD_Vpd_Wpd      0x660f55
620#define OP_ORPS_Vps_Wps         0x0f56
621#define OP_ORPD_Vpd_Wpd         0x660f56
622#define OP_XORPS_Vps_Wps      0x0f57
623#define OP_XORPD_Vpd_Wpd      0x660f57
624#define OP_ADDPS_Vps_Wps      0x0f58
625#define OP_ADDSS_Vss_Wss      0xf30f58
626#define OP_ADDPD_Vpd_Wpd      0x660f58
627#define OP_ADDSD_Vsd_Wsd      0xf20f58
628#define OP_MULPS_Vps_Wps      0x0f59
629#define OP_MULSS_Vss_Wss      0xf30f59
630#define OP_MULPD_Vpd_Wpd      0x660f59
631#define OP_MULSD_Vsd_Wsd      0xf20f59
632#define OP_CVTPS2PD_Vpd_Wq      0x0f5a
633#define OP_CVTSS2SD_Vsd_Wss      0xf30f5a
634#define OP_CVTPD2PS_Vps_Wpd      0x660f5a
635#define OP_CVTSD2SS_Vss_Wsd      0xf20f5a
636#define OP_CVTDQ2PS_Vps_Wdq      0x0f5b
637#define OP_CVTPS2DQ_Vdq_Wps      0x660f5b
638#define OP_CVTTPS2DQ_Vdq_Wps    0xf30f5b
639#define OP_SUBPS_Vps_Wps      0x0f5c
640#define OP_SUBSS_Vss_Wss      0xf30f5c
641#define OP_SUBPD_Vpd_Wpd      0x660f5c
642#define OP_SUBSD_Vsd_Wsd      0xf20f5c
643#define OP_MINPS_Vps_Wps      0x0f5d
644#define OP_MINSS_Vss_Wss      0xf30f5d
645#define OP_MINPD_Vpd_Wpd      0x660f5d
646#define OP_MINSD_Vsd_Wsd      0xf20f5d
647#define OP_DIVPS_Vps_Wps      0x0f5e
648#define OP_DIVSS_Vss_Wss      0xf30f5e
649#define OP_DIVPD_Vpd_Wpd      0x660f5e
650#define OP_DIVSD_Vsd_Wsd      0xf20f5e
651#define OP_MAXPS_Vps_Wps      0x0f5f
652#define OP_MAXSS_Vss_Wss      0xf30f5f
653#define OP_MAXPD_Vpd_Wpd      0x660f5f
654#define OP_MAXSD_Vsd_Wsd      0xf20f5f
655
656#define OP_PUNPCKLBW_Pq_Qd      0x0f60
657#define OP_PUNPCKLBW_Vdq_Wdq    0x660f60
658#define OP_PUNPCKLWD_Pq_Qd      0x0f61
659#define OP_PUNPCKLWD_Vdq_Wdq    0x660f61
660#define OP_PUNPCKLDQ_Pq_Qd      0x0f62
661#define OP_PUNPCKLDQ_Vdq_Wdq    0x660f62
662#define OP_PACKSSWB_Pq_Qq      0x0f63
663#define OP_PACKSSWB_Vdq_Wdq      0x660f63
664#define OP_PCMPGTB_Pq_Qq      0x0f64
665#define OP_PCMPGTB_Vdq_Wdq      0x660f64
666#define OP_PCMPGTW_Pq_Qq      0x0f65
667#define OP_PCMPGTW_Vdq_Wdq      0x660f65
668#define OP_PCMPGTD_Pq_Qq      0x0f66
669#define OP_PCMPGTD_Vdq_Wdq      0x660f66
670#define OP_PACKUSWB_Pq_Qq      0x0f67
671#define OP_PACKUSWB_Vdq_Wdq      0x660f67
672#define OP_PUNPCKHBW_Pq_Qq      0x0f68
673#define OP_PUNPCKHBW_Vdq_Qdq    0x660f68
674#define OP_PUNPCKHWD_Pq_Qq      0x0f69
675#define OP_PUNPCKHWD_Vdq_Qdq    0x660f69
676#define OP_PUNPCKHDQ_Pq_Qq      0x0f6a
677#define OP_PUNPCKHDQ_Vdq_Qdq    0x660f6a
678#define OP_PACKSSDW_Pq_Qq      0x0f6b
679#define OP_PACKSSDW_Vdq_Qdq      0x660f6b
680#define OP_PUNPCKLQDQ_Vdq_Wdq    0x660f6c
681#define OP_PUNPCKHQDQ_Vdq_Wdq    0x660f6d
682#define OP_MOVD_Pd_Ed         0x0f6e
683#define OP_MOVD_Vd_Ed         0x660f6e
684#define OP_MOVQ_Pq_Qq         0x0f6f
685#define OP_MOVDQA_Vdq_Wdq      0x660f6f
686#define OP_MOVDQU_Vdq_Wdq      0xf30f6f
687
688#define OP_PSHUFW_Pq_Qq_Ib      0x0f70
689#define OP_PSHUFD_Vdq_Wdq_Ib    0x660f70
690#define OP_PSHUFHW_Vdq_Wdq_Ib    0xf30f70
691#define OP_PSHUFLW_Vdq_Wdq_Ib    0xf20f70
692#define OP_G12               0x0f71
693#define OP_G13               0x0f72
694#define OP_G14               0x0f73
695#define OP_PCMPEQB_Pq_Qq      0x0f74
696#define OP_PCMPEQB_Vdq_Wdq      0x660f74
697#define OP_PCMPEQW_Pq_Qq      0x0f75
698#define OP_PCMPEQW_Vdq_Wdq      0x660f75
699#define OP_PCMPEQD_Pq_Qq      0x0f76
700#define OP_PCMPEQD_Vdq_Wdq      0x660f76
701#define OP_EMMS               0x0f77
702#define OP_HADDPD_Vpd_Wpd      0x660f7c
703#define OP_HADDPS_Vps_Wps      0xf20f7c
704#define OP_HSUBPD_Vpd_Wpd      0x660f7d
705#define OP_HSUBPS_Vps_Wps      0xf20f7d
706#define OP_MOVD_Ed_Pd         0x0f7e
707#define OP_MOVD_Ed_Vd         0x660f7e
708#define OP_MOVQ_Vq_Wq         0xf30f7e
709#define OP_MOVQ_Qq_Pq         0x0f7f
710#define OP_MOVDQA_Wdq_Vdq      0x660f7f
711#define OP_MOVDQU_Wdq_Vdq      0xf30f7f
712
713#define OP_JCC_O_Jv            0x0f80
714#define OP_JCC_NO_Jv         0x0f81
715#define OP_JCC_B_Jv            0x0f82
716#define OP_JCC_C_Jv            0x0f82
717#define OP_JCC_NAE_Jv         0x0f82
718#define OP_JCC_AE_Jv         0x0f83
719#define OP_JCC_NB_Jv         0x0f83
720#define OP_JCC_NC_Jv         0x0f83
721#define OP_JCC_E_Jv            0x0f84
722#define OP_JCC_Z_Jv            0x0f84
723#define OP_JCC_NE_Jv         0x0f85
724#define OP_JCC_NZ_Jv         0x0f85
725#define OP_JCC_BE_Jv         0x0f86
726#define OP_JCC_NA_Jv         0x0f86
727#define OP_JCC_A_Jv            0x0f87
728#define OP_JCC_NBE_Jv         0x0f87
729#define OP_JCC_S_Jv            0x0f88
730#define OP_JCC_NS_Jv         0x0f89
731#define OP_JCC_P_Jv            0x0f8a
732#define OP_JCC_PE_Jv         0x0f8a
733#define OP_JCC_NP_Jv         0x0f8b
734#define OP_JCC_PO_Jv         0x0f8b
735#define OP_JCC_L_Jv            0x0f8c
736#define OP_JCC_NGE_Jv         0x0f8c
737#define OP_JCC_NL_Jv         0x0f8d
738#define OP_JCC_GE_Jv         0x0f8d
739#define OP_JCC_LE_Jv         0x0f8e
740#define OP_JCC_NG_Jv         0x0f8e
741#define OP_JCC_NLE_Jv         0x0f8f
742#define OP_JCC_G_Jv            0x0f8f
743
744#define OP_SETCC_O_Eb         0x0f90 | OPFLAG_8BITRM
745#define OP_SETCC_NO_Eb         0x0f91 | OPFLAG_8BITRM
746#define OP_SETCC_B_Eb         0x0f92 | OPFLAG_8BITRM
747#define OP_SETCC_C_Eb         0x0f92 | OPFLAG_8BITRM
748#define OP_SETCC_NAE_Eb         0x0f92 | OPFLAG_8BITRM
749#define OP_SETCC_AE_Eb         0x0f93 | OPFLAG_8BITRM
750#define OP_SETCC_NB_Eb         0x0f93 | OPFLAG_8BITRM
751#define OP_SETCC_NC_Eb         0x0f93 | OPFLAG_8BITRM
752#define OP_SETCC_E_Eb         0x0f94 | OPFLAG_8BITRM
753#define OP_SETCC_Z_Eb         0x0f94 | OPFLAG_8BITRM
754#define OP_SETCC_NE_Eb         0x0f95 | OPFLAG_8BITRM
755#define OP_SETCC_NZ_Eb         0x0f95 | OPFLAG_8BITRM
756#define OP_SETCC_BE_Eb         0x0f96 | OPFLAG_8BITRM
757#define OP_SETCC_NA_Eb         0x0f96 | OPFLAG_8BITRM
758#define OP_SETCC_A_Eb         0x0f97 | OPFLAG_8BITRM
759#define OP_SETCC_NBE_Eb         0x0f97 | OPFLAG_8BITRM
760#define OP_SETCC_S_Eb         0x0f98 | OPFLAG_8BITRM
761#define OP_SETCC_NS_Eb         0x0f99 | OPFLAG_8BITRM
762#define OP_SETCC_P_Eb         0x0f9a | OPFLAG_8BITRM
763#define OP_SETCC_PE_Eb         0x0f9a | OPFLAG_8BITRM
764#define OP_SETCC_NP_Eb         0x0f9b | OPFLAG_8BITRM
765#define OP_SETCC_PO_Eb         0x0f9b | OPFLAG_8BITRM
766#define OP_SETCC_L_Eb         0x0f9c | OPFLAG_8BITRM
767#define OP_SETCC_NGE_Eb         0x0f9c | OPFLAG_8BITRM
768#define OP_SETCC_NL_Eb         0x0f9d | OPFLAG_8BITRM
769#define OP_SETCC_GE_Eb         0x0f9d | OPFLAG_8BITRM
770#define OP_SETCC_LE_Eb         0x0f9e | OPFLAG_8BITRM
771#define OP_SETCC_NG_Eb         0x0f9e | OPFLAG_8BITRM
772#define OP_SETCC_NLE_Eb         0x0f9f | OPFLAG_8BITRM
773#define OP_SETCC_G_Eb         0x0f9f | OPFLAG_8BITRM
774
775#define OP_PUSH_FS            0x0fa0
776#define OP_POP_FS            0x0fa1
777#define OP_CPUID            0x0fa2
778#define OP_BT_Ev_Gv            0x0fa3
779#define OP_SHLD_Ev_Gv_Ib      0x0fa4
780#define OP_SHLD_Ev_Gv_CL      0x0fa5
781#define OP_PUSH_GS            0x0fa8
782#define OP_POP_GS            0x0fa9
783#define OP_RSM               0x0faa
784#define OP_BTS_Ev_Gv         0x0fab
785#define OP_SHRD_Ev_Gv_Ib      0x0fac
786#define OP_SHRD_Ev_Gv_CL      0x0fad
787#define OP_G16               0x0fae
788#define OP_IMUL_Gv_Ev         0x0faf
789
790#define OP_CMPXCHG_Eb_Gb      0x0fb0 | OPFLAG_8BITRM | OPFLAG_8BITREG
791#define OP_CMPXCHG_Ev_Gv      0x0fb1
792#define OP_LSS_Mp            0x0fb2
793#define OP_BTR_Ev_Gv         0x0fb3
794#define OP_LFS_Mp            0x0fb4
795#define OP_LGS_Mp            0x0fb5
796#define OP_MOVZX_Gv_Eb         0x0fb6 | OPFLAG_8BITRM
797#define OP_MOVZX_Gv_Ew         0x0fb7
798#define OP_G10_INVALID         0x0fb9
799#define OP_G8_Ev_Ib            0x0fba
800#define OP_BTC_Ev_Gv         0x0fbb
801#define OP_BSF_Gv_Ev         0x0fbc
802#define OP_BSR_Gv_Ev         0x0fbd
803#define OP_MOVSX_Gv_Eb         0x0fbe | OPFLAG_8BITRM
804#define OP_MOVSX_Gv_Ew         0x0fbf
805
806#define OP_XADD_Eb_Gb         0x0fc0 | OPFLAG_8BITRM | OPFLAG_8BITREG
807#define OP_XADD_Ev_Gv         0x0fc1
808#define OP_CMPPS_Vps_Wps_Ib      0x0fc2
809#define OP_CMPSS_Vss_Wss_Ib      0xf30fc2
810#define OP_CMPPD_Vpd_Wpd_Ib      0x660fc2
811#define OP_CMPSD_Vsd_Wsd_Ib      0xf20fc2
812#define OP_MOVNTI_Md_Gd         0x0fc3
813#define OP_PINSRW_Pw_Ew_Ib      0x0fc4
814#define OP_PINSRW_Vw_Ew_Ib      0x660fc4
815#define OP_PEXTRW_Gw_Pw_Ib      0x0fc5
816#define OP_PEXTRW_Gw_Vw_Ib      0x660fc5
817#define OP_SHUFPS_Vps_Wps_Ib   0x0fc6
818#define OP_SHUFPD_Vpd_Wpd_Ib   0x660fc6
819#define OP_G9               0x0fc7
820#define OP_BSWAP_EAX         0x0fc8
821#define OP_BSWAP_ECX         0x0fc9
822#define OP_BSWAP_EDX         0x0fca
823#define OP_BSWAP_EBX         0x0fcb
824#define OP_BSWAP_ESP         0x0fcc
825#define OP_BSWAP_EBP         0x0fcd
826#define OP_BSWAP_ESI         0x0fce
827#define OP_BSWAP_EDI         0x0fcf
828
829#define OP_ADDSUBPD_Vpd_Wpd      0x0fd0
830#define OP_ADDSUBPS_Vps_Wps      0xf20fd0
831#define OP_PSRLW_Pq_Qq         0x0fd1
832#define OP_PSRLW_Vdq_Wdq      0x660fd1
833#define OP_PSRLD_Pq_Qq         0x0fd2
834#define OP_PSRLD_Vdq_Wdq      0x660fd2
835#define OP_PSRLQ_Pq_Qq         0x0fd3
836#define OP_PSRLQ_Vdq_Wdq      0x660fd3
837#define OP_PADDQ_Pq_Qq         0x0fd4
838#define OP_PADDQ_Vdq_Wdq      0x660fd4
839#define OP_PMULLW_Pq_Qq         0x0fd5
840#define OP_PMULLW_Vdq_Wdq      0x660fd5
841#define OP_MOVQ_Wq_Vq         0x0fd6
842#define OP_MOVQ2DQ_Vdq_Qq      0xf30fd6
843#define OP_MOVDQ2Q_Pq_Vq      0xf20fd6
844#define OP_PMOVMSKB_Gd_Pq      0x0fd7
845#define OP_PMOVMSKB_Gd_Vdq      0x660fd7
846#define OP_PSUBUSB_Pq_Qq      0x0fd8
847#define OP_PSUBUSB_Vdq_Wdq      0x660fd8
848#define OP_PSUBUSW_Pq_Qq      0x0fd9
849#define OP_PSUBUSW_Vdq_Wdq      0x660fd9
850#define OP_PMINUB_Pq_Qq         0x0fda
851#define OP_PMINUB_Vdq_Wdq      0x660fda
852#define OP_PAND_Pq_Qq         0x0fdb
853#define OP_PAND_Vdq_Wdq         0x660fdb
854#define OP_PADDUSB_Pq_Qq      0x0fdc
855#define OP_PADDUSB_Vdq_Wdq      0x660fdc
856#define OP_PADDUSW_Pq_Qq      0x0fdd
857#define OP_PADDUSW_Vdq_Wdq      0x660fdd
858#define OP_PMAXUB_Pq_Qq         0x0fde
859#define OP_PMAXUB_Vdq_Wdq      0x660fde
860#define OP_PANDN_Pq_Qq         0x0fdf
861#define OP_PANDN_Vdq_Wdq      0x660fdf
862
863#define OP_PAVGB_Pq_Qq         0x0fe0
864#define OP_PAVGB_Vdq_Wdq      0x660fe0
865#define OP_PSRAW_Pq_Qq         0x0fe1
866#define OP_PSRAW_Vdq_Wdq      0x660fe1
867#define OP_PSRAD_Pq_Qq         0x0fe2
868#define OP_PSRAD_Vdq_Wdq      0x660fe2
869#define OP_PAVGW_Pq_Qq         0x0fe3
870#define OP_PAVGW_Vdq_Wdq      0x660fe3
871#define OP_PMULHUW_Pq_Qq      0x0fe4
872#define OP_PMULHUW_Vdq_Wdq      0x660fe4
873#define OP_PMULHW_Pq_Qq         0x0fe5
874#define OP_PMULHW_Vdq_Wdq      0x660fe5
875#define OP_CVTPD2DQ_Vdq_Wpd      0xf20fe6
876#define OP_CVTTPD2DQ_Vdq_Wpd   0x660fe6
877#define OP_CVTDQ2PD_Vpd_Wq      0xf30fe6
878#define OP_MOVNTQ_Mq_Vq         0x0fe7
879#define OP_MOVNTDQ_Mdq_Vdq      0x660fe7
880#define OP_PSUBSB_Pq_Qq         0x0fe8
881#define OP_PSUBSB_Vdq_Wdq      0x660fe8
882#define OP_PSUBSW_Pq_Qq         0x0fe9
883#define OP_PSUBSW_Vdq_Wdq      0x660fe9
884#define OP_PMINSW_Pq_Qq         0x0fea
885#define OP_PMINSW_Vdq_Wdq      0x660fea
886#define OP_POR_Pq_Qq         0x0feb
887#define OP_POR_Vdq_Wdq         0x660feb
888#define OP_PADDSB_Pq_Qq         0x0fec
889#define OP_PADDSB_Vdq_Wdq      0x660fec
890#define OP_PADDSW_Pq_Qq         0x0fed
891#define OP_PADDSW_Vdq_Wdq      0x660fed
892#define OP_PMAXSW_Pq_Qq         0x0fee
893#define OP_PMAXSW_Vdq_Wdq      0x660fee
894#define OP_PXOR_Pq_Qq         0x0fef
895#define OP_PXOR_Vdq_Wdq         0x660fef
896
897#define OP_LDDQU_Vdq_Mdq      0xf20ff0
898#define OP_PSLLW_Pq_Qq         0x0ff1
899#define OP_PSLLW_Vdq_Wdq      0x660ff1
900#define OP_PSLLD_Pq_Qq         0x0ff2
901#define OP_PSLLD_Vdq_Wdq      0x660ff2
902#define OP_PSLLQ_Pq_Qq         0x0ff3
903#define OP_PSLLQ_Vdq_Wdq      0x660ff3
904#define OP_PMULUDQ_Pq_Qq      0x0ff4
905#define OP_PMULUDQ_Vdq_Wdq      0x660ff4
906#define OP_PMADDWD_Pq_Qq      0x0ff5
907#define OP_PMADDWD_Vdq_Wdq      0x660ff5
908#define OP_PSADBW_Pq_Qq         0x0ff6
909#define OP_PSADBW_Vdq_Wdq      0x660ff6
910#define OP_MASKMOVQ_Pq_Qq      0x0ff7
911#define OP_MASKMOVDQU_Vdq_Wdq   0x660ff7
912#define OP_PSUBB_Pq_Qq         0x0ff8
913#define OP_PSUBB_Vdq_Wdq      0x660ff8
914#define OP_PSUBW_Pq_Qq         0x0ff9
915#define OP_PSUBW_Vdq_Wdq      0x660ff9
916#define OP_PSUBD_Pq_Qq         0x0ffa
917#define OP_PSUBD_Vdq_Wdq      0x660ffa
918#define OP_PSUBQ_Pq_Qq         0x0ffb
919#define OP_PSUBQ_Vdq_Wdq      0x660ffb
920#define OP_PADDB_Pq_Qq         0x0ffc
921#define OP_PADDB_Vdq_Wdq      0x660ffc
922#define OP_PADDW_Pq_Qq         0x0ffd
923#define OP_PADDW_Vdq_Wdq      0x660ffd
924#define OP_PADDD_Pq_Qq         0x0ffe
925#define OP_PADDD_Vdq_Wdq      0x660ffe
926
927
928/* floating point opcodes */
929#define OP_FADD_ST0_STn         0xd8c0
930#define OP_FMUL_ST0_STn         0xd8c8
931#define OP_FCOM_ST0_STn         0xd8d0
932#define OP_FCOMP_ST0_STn      0xd8d8
933#define OP_FSUB_ST0_STn         0xd8e0
934#define OP_FSUBR_ST0_STn      0xd8e8
935#define OP_FDIV_ST0_STn         0xd8f0
936#define OP_FDIVR_ST0_STn      0xd8f8
937#define OP_FLD_ST0_STn         0xd9c0
938#define OP_FXCH_ST0_STn         0xd9c8
939#define OP_FNOP               0xd9d0
940#define OP_FCHS               0xd9e0
941#define OP_FABS               0xd9e1
942#define OP_FTST               0xd9e4
943#define OP_FXAM               0xd9e5
944#define OP_FLD1               0xd9e8
945#define OP_FLDL2T            0xd9e9
946#define OP_FLDL2E            0xd9ea
947#define OP_FLDPI            0xd9eb
948#define OP_FLDLG2            0xd9ec
949#define OP_FLDLN2            0xd9ed
950#define OP_FLDZ               0xd9ee
951#define OP_F2XM1            0xd9f0
952#define OP_FYL2X            0xd9f1
953#define OP_FPTAN            0xd9f2
954#define OP_FPATAN            0xd9f3
955#define OP_FXTRACT            0xd9f4
956#define OP_FPREM1            0xd9f5
957#define OP_FDECSTP            0xd9f6
958#define OP_FINCSTP            0xd9f7
959#define OP_FPREM            0xd9f8
960#define OP_FYL2XP1            0xd9f9
961#define OP_FSQRT            0xd9fa
962#define OP_FSINCOS            0xd9fb
963#define OP_FRNDINT            0xd9fc
964#define OP_FSCALE            0xd9fd
965#define OP_FSIN               0xd9fe
966#define OP_FCOS               0xd9ff
967#define OP_FCMOVB_ST0_STn      0xdac0
968#define OP_FCMOVE_ST0_STn      0xdac8
969#define OP_FCMOVBE_ST0_STn      0xdad0
970#define OP_FCMOVU_ST0_STn      0xdad8
971#define OP_FUCOMPP            0xdae9
972#define OP_FCMOVNB_ST0_STn      0xdbc0
973#define OP_FCMOVNE_ST0_STn      0xdbc8
974#define OP_FCMOVNBE_ST0_STn      0xdbd0
975#define OP_FCMOVNU_ST0_STn      0xdbd8
976#define OP_FCLEX            0xdbe2
977#define OP_FINIT            0xdbe3
978#define OP_FUCOMI_ST0_STn      0xdbe8
979#define OP_FCOMI_ST0_STn      0xdbf0
980#define OP_FADD_STn_ST0         0xdcc0
981#define OP_FMUL_STn_ST0         0xdcc8
982#define OP_FSUBR_STn_ST0      0xdce0
983#define OP_FSUB_STn_ST0         0xdce8
984#define OP_FDIVR_STn_ST0      0xdcf0
985#define OP_FDIV_STn_ST0         0xdcf8
986#define OP_FFREE_STn         0xddc0
987#define OP_FST_STn            0xddd0
988#define OP_FSTP_STn            0xddd8
989#define OP_FUCOM_STn_ST0      0xdde0
990#define OP_FUCOMP_STn         0xdde8
991#define OP_FADDP_STn_ST0      0xdec0
992#define OP_FMULP_STn_ST0      0xdec8
993#define OP_FCOMPP            0xded9
994#define OP_FSUBRP_STn_ST0      0xdee0
995#define OP_FSUBP_STn_ST0      0xdee8
996#define OP_FDIVRP_STn_ST0      0xdef0
997#define OP_FDIVP_STn_ST0      0xdef8
998#define OP_FSTSW_AX            0xdfe0
999#define OP_FCOMIP_ST0_STn      0xdff0
1000
1001
1002
1003/***************************************************************************
1004    TYPE DEFINITIONS
1005***************************************************************************/
1006
1007typedef UINT8               x86code;
1008
1009
1010typedef struct _emit_link emit_link;
1011struct _emit_link
1012{
1013   x86code *      target;
1014   UINT8         size;
1015};
1016
1017
1018
1019/***************************************************************************
1020    CORE FUNCTIONS
1021***************************************************************************/
1022
1023/*-------------------------------------------------
1024    make_modrm - assemble a modrm byte from the
1025    three components
1026-------------------------------------------------*/
1027
1028INLINE UINT8 make_modrm(UINT8 mode, UINT8 reg, UINT8 rm)
1029{
1030   assert(mode < 4);
1031   assert(reg < REG_MAX);
1032   assert(rm < REG_MAX);
1033   return (mode << 6) | ((reg & 7) << 3) | (rm & 7);
1034}
1035
1036
1037/*-------------------------------------------------
1038    make_sib - assemble an sib byte from the
1039    three components
1040-------------------------------------------------*/
1041
1042INLINE UINT8 make_sib(UINT8 scale, UINT8 index, UINT8 base)
1043{
1044   static const UINT8 scale_lookup[9] = { 0<<6, 0<<6, 1<<6, 0<<6, 2<<6, 0<<6, 0<<6, 0<<6, 3<<6 };
1045   assert(scale == 1 || scale == 2 || scale == 4 || scale == 8);
1046   assert(index < REG_MAX);
1047   assert(base < REG_MAX);
1048   return scale_lookup[scale] | ((index & 7) << 3) | (base & 7);
1049}
1050
1051
1052/*-------------------------------------------------
1053    emit_byte - emit a byte
1054-------------------------------------------------*/
1055
1056INLINE void emit_byte(x86code **emitptr, UINT8 byte)
1057{
1058   *((UINT8 *)*emitptr) = byte;
1059   *emitptr += 1;
1060}
1061
1062
1063/*-------------------------------------------------
1064    emit_word - emit a word
1065-------------------------------------------------*/
1066
1067INLINE void emit_word(x86code **emitptr, UINT16 word)
1068{
1069   *((UINT16 *)*emitptr) = word;
1070   *emitptr += 2;
1071}
1072
1073
1074/*-------------------------------------------------
1075    emit_dword - emit a dword
1076-------------------------------------------------*/
1077
1078INLINE void emit_dword(x86code **emitptr, UINT32 dword)
1079{
1080   *((UINT32 *)*emitptr) = dword;
1081   *emitptr += 4;
1082}
1083
1084
1085/*-------------------------------------------------
1086    emit_qword - emit a dword
1087-------------------------------------------------*/
1088
1089INLINE void emit_qword(x86code **emitptr, UINT64 qword)
1090{
1091   *((UINT64 *)*emitptr) = qword;
1092   *emitptr += 8;
1093}
1094
1095
1096
1097/***************************************************************************
1098    GENERIC OPCODE EMITTERS
1099***************************************************************************/
1100
1101/*-------------------------------------------------
1102    emit_op - emit a 1, 2, or 3-byte opcode,
1103    along with any necessary REX prefixes for x64
1104-------------------------------------------------*/
1105
1106INLINE void emit_op(x86code **emitptr, UINT32 op, UINT8 op64, UINT8 reg, UINT8 sib, UINT8 rm)
1107{
1108#ifdef PTR64
1109   UINT8 rex;
1110
1111   assert(op64 == OP_32BIT || op64 == OP_64BIT);
1112
1113   rex = op64 | ((reg & 8) >> 1) | ((sib & 8) >> 2) | ((rm & 8) >> 3);
1114   if (rex != 0 || ((op & OPFLAG_8BITREG) && reg >= 4) || ((op & OPFLAG_8BITRM) && rm >= 4))
1115      emit_byte(emitptr, rex | 0x40);
1116#else
1117   assert(op64 == OP_32BIT);
1118#endif
1119
1120   if ((op & 0xff0000) != 0)
1121      emit_byte(emitptr, op >> 16);
1122   if ((op & 0xff00) != 0)
1123      emit_byte(emitptr, op >> 8);
1124   emit_byte(emitptr, op);
1125}
1126
1127
1128/*-------------------------------------------------
1129    emit_op_simple - emit a simple opcode
1130-------------------------------------------------*/
1131
1132INLINE void emit_op_simple(x86code **emitptr, UINT32 op, UINT8 op64)
1133{
1134   emit_op(emitptr, op, op64, 0, 0, 0);
1135}
1136
1137
1138/*-------------------------------------------------
1139    emit_op_modrm_reg - emit an opcode with a
1140    register modrm byte
1141-------------------------------------------------*/
1142
1143INLINE void emit_op_modrm_reg(x86code **emitptr, UINT32 op, UINT8 op64, UINT8 reg, UINT8 rm)
1144{
1145   assert(reg < REG_MAX);
1146   assert(rm < REG_MAX);
1147
1148   emit_op(emitptr, op, op64, reg, 0, rm);
1149   emit_byte(emitptr, make_modrm(3, reg, rm));
1150}
1151
1152
1153/*-------------------------------------------------
1154    emit_op_modrm_mem - emit an opcode with a
1155    memory modrm byte
1156-------------------------------------------------*/
1157
1158INLINE void emit_op_modrm_mem(x86code **emitptr, UINT32 op, UINT8 op64, UINT8 reg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1159{
1160   assert(reg < REG_MAX);
1161   assert(base < REG_MAX || base == REG_NONE);
1162   assert(index < REG_MAX || index == REG_NONE);
1163
1164   /* turn off the OPFLAG_8BITRM flag since it only applies to register operands */
1165   op &= ~OPFLAG_8BITRM;
1166
1167   /* displacement only case */
1168   if (base == REG_NONE && index == REG_NONE)
1169   {
1170#ifndef PTR64
1171      emit_op(emitptr, op, op64, reg, 0, 5);
1172      emit_byte(emitptr, make_modrm(0, reg, 5));
1173      emit_dword(emitptr, disp);
1174#else
1175      fatalerror("Invalid absolute mode in 64-bits!\n");
1176#endif
1177   }
1178
1179   /* base only case */
1180   else if (index == REG_NONE && base != REG_ESP)
1181   {
1182      emit_op(emitptr, op, op64, reg, 0, base);
1183
1184      /* mode 0 for no offset */
1185      if (disp == 0 && base != REG_EBP)
1186         emit_byte(emitptr, make_modrm(0, reg, base));
1187
1188      /* mode 1 for 1-byte offset */
1189      else if ((INT8)disp == disp)
1190      {
1191         emit_byte(emitptr, make_modrm(1, reg, base));
1192         emit_byte(emitptr, (INT8)disp);
1193      }
1194
1195      /* mode 2 for 4-byte offset */
1196      else
1197      {
1198         emit_byte(emitptr, make_modrm(2, reg, base));
1199         emit_dword(emitptr, disp);
1200      }
1201   }
1202
1203   /* full BISD case */
1204   else
1205   {
1206      assert(index != REG_ESP);
1207      emit_op(emitptr, op, op64, reg, index, base);
1208
1209      /* a "none" index == REG_ESP */
1210      if (index == REG_NONE)
1211         index = REG_ESP;
1212
1213      /* mode 0 for no offset */
1214      if (disp == 0 && base != REG_EBP)
1215      {
1216         emit_byte(emitptr, make_modrm(0, reg, 4));
1217         emit_byte(emitptr, make_sib(scale, index, (base == REG_NONE) ? REG_EBP : base));
1218         if (base == REG_NONE)
1219            emit_dword(emitptr, disp);
1220      }
1221
1222      /* mode 1 for 1-byte offset */
1223      else if ((INT8)disp == disp)
1224      {
1225         emit_byte(emitptr, make_modrm(1, reg, 4));
1226         emit_byte(emitptr, make_sib(scale, index, base));
1227         emit_byte(emitptr, (INT8)disp);
1228      }
1229
1230      /* mode 2 for 4-byte offset */
1231      else
1232      {
1233         emit_byte(emitptr, make_modrm(2, reg, 4));
1234         emit_byte(emitptr, make_sib(scale, index, base));
1235         emit_dword(emitptr, disp);
1236      }
1237   }
1238}
1239
1240
1241
1242/***************************************************************************
1243    SIMPLE OPCODE EMITTERS
1244***************************************************************************/
1245
1246INLINE void emit_nop(x86code **emitptr)
1247{
1248   emit_byte(emitptr, OP_NOP);
1249}
1250
1251INLINE void emit_int_3(x86code **emitptr)
1252{
1253   emit_byte(emitptr, OP_INT_3);
1254}
1255
1256INLINE void emit_ret(x86code **emitptr)
1257{
1258   emit_byte(emitptr, OP_RETN);
1259}
1260
1261INLINE void emit_cdq(x86code **emitptr)
1262{
1263   emit_byte(emitptr, OP_CDQ);
1264}
1265
1266#ifdef PTR64
1267INLINE void emit_cqo(x86code **emitptr)
1268{
1269   emit_byte(emitptr, OP_REX_W);
1270   emit_byte(emitptr, OP_CQO);
1271}
1272#endif
1273
1274
1275
1276/***************************************************************************
1277    CALL/JUMP EMITTERS
1278***************************************************************************/
1279
1280/*-------------------------------------------------
1281    resolve_link - resolve a link in a jump
1282    instruction
1283-------------------------------------------------*/
1284
1285INLINE void resolve_link(x86code **destptr, const emit_link *linkinfo)
1286{
1287   INT64 delta = *destptr - linkinfo->target;
1288   if (linkinfo->size == 1)
1289   {
1290      assert((INT8)delta == delta);
1291      ((INT8 *)linkinfo->target)[-1] = (INT8)delta;
1292   }
1293   else if (linkinfo->size == 2)
1294   {
1295      assert((INT16)delta == delta);
1296      ((INT16 *)linkinfo->target)[-1] = (INT16)delta;
1297   }
1298   else
1299   {
1300      assert((INT32)delta == delta);
1301      ((INT32 *)linkinfo->target)[-1] = (INT32)delta;
1302   }
1303}
1304
1305
1306/*------------------------------------------------------------------
1307    emit_call_*
1308------------------------------------------------------------------*/
1309
1310INLINE void emit_call_link(x86code **emitptr, emit_link *linkinfo)
1311{
1312   emit_op_simple(emitptr, OP_CALL_Jz, OP_32BIT);
1313   emit_dword(emitptr, 0);
1314   linkinfo->target = *emitptr;
1315   linkinfo->size = 4;
1316}
1317
1318INLINE void emit_call(x86code **emitptr, x86code *target)
1319{
1320   emit_link link;
1321
1322   emit_call_link(emitptr, &link);
1323   resolve_link(&target, &link);
1324}
1325
1326
1327/*------------------------------------------------------------------
1328    emit_call_r32_*
1329------------------------------------------------------------------*/
1330
1331#ifndef PTR64
1332
1333INLINE void emit_call_r32(x86code **emitptr, UINT8 dreg)
1334{
1335   emit_op_modrm_reg(emitptr, OP_G5, OP_32BIT, 2, dreg);
1336}
1337
1338INLINE void emit_call_m32bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1339{
1340   emit_op_modrm_mem(emitptr, OP_G5, OP_32BIT, 2, base, index, scale, disp);
1341}
1342
1343#define emit_call_m32abs(e, addr)                        emit_call_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1344#define emit_call_m32bd(e, base, disp)                     emit_call_m32bisd(e, (base),   REG_NONE, 1,       (disp))
1345#define emit_call_m32isd(e, index, scale, disp)               emit_call_m32bisd(e, REG_NONE, (index),  (scale), (disp))
1346
1347#endif
1348
1349
1350/*------------------------------------------------------------------
1351    emit_call_r64_*
1352------------------------------------------------------------------*/
1353
1354#ifdef PTR64
1355
1356INLINE void emit_call_r64(x86code **emitptr, UINT8 dreg)
1357{
1358   emit_op_modrm_reg(emitptr, OP_G5, OP_32BIT, 2, dreg);
1359}
1360
1361INLINE void emit_call_m64bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1362{
1363   emit_op_modrm_mem(emitptr, OP_G5, OP_32BIT, 2, base, index, scale, disp);
1364}
1365
1366#define emit_call_m64abs(e, addr)                        emit_call_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1367#define emit_call_m64bd(e, base, disp)                     emit_call_m64bisd(e, (base),   REG_NONE, 1,       (disp))
1368#define emit_call_m64isd(e, index, scale, disp)               emit_call_m64bisd(e, REG_NONE, (index),  (scale), (disp))
1369
1370#endif
1371
1372
1373/*------------------------------------------------------------------
1374    emit_jmp_*
1375------------------------------------------------------------------*/
1376
1377INLINE void emit_jmp_short_link(x86code **emitptr, emit_link *linkinfo)
1378{
1379   emit_op_simple(emitptr, OP_JMP_Jb, OP_32BIT);
1380   emit_byte(emitptr, 0);
1381   linkinfo->target = *emitptr;
1382   linkinfo->size = 1;
1383}
1384
1385INLINE void emit_jmp_near_link(x86code **emitptr, emit_link *linkinfo)
1386{
1387   emit_op_simple(emitptr, OP_JMP_Jz, OP_32BIT);
1388   emit_dword(emitptr, 0);
1389   linkinfo->target = *emitptr;
1390   linkinfo->size = 4;
1391}
1392
1393INLINE void emit_jmp(x86code **emitptr, x86code *target)
1394{
1395   INT32 delta = target - (*emitptr + 2);
1396   emit_link link;
1397
1398   if ((INT8)delta == delta)
1399      emit_jmp_short_link(emitptr, &link);
1400   else
1401      emit_jmp_near_link(emitptr, &link);
1402   resolve_link(&target, &link);
1403}
1404
1405
1406/*------------------------------------------------------------------
1407    emit_jcc_*
1408------------------------------------------------------------------*/
1409
1410INLINE void emit_jcc_short_link(x86code **emitptr, UINT8 condition, emit_link *linkinfo)
1411{
1412   emit_op_simple(emitptr, OP_JCC_O_Jb + condition, OP_32BIT);
1413   emit_byte(emitptr, 0);
1414   linkinfo->target = *emitptr;
1415   linkinfo->size = 1;
1416}
1417
1418INLINE void emit_jcc_near_link(x86code **emitptr, UINT8 condition, emit_link *linkinfo)
1419{
1420   emit_op_simple(emitptr, OP_JCC_O_Jv + condition, OP_32BIT);
1421   emit_dword(emitptr, 0);
1422   linkinfo->target = *emitptr;
1423   linkinfo->size = 4;
1424}
1425
1426INLINE void emit_jcc(x86code **emitptr, UINT8 condition, x86code *target)
1427{
1428   INT32 delta = *emitptr + 2 - target;
1429   emit_link link;
1430
1431   if ((INT8)delta == delta)
1432      emit_jcc_short_link(emitptr, condition, &link);
1433   else
1434      emit_jcc_near_link(emitptr, condition, &link);
1435   resolve_link(&target, &link);
1436}
1437
1438
1439/*------------------------------------------------------------------
1440    emit_jmp_r32_*
1441------------------------------------------------------------------*/
1442
1443#ifndef PTR64
1444
1445INLINE void emit_jmp_r32(x86code **emitptr, UINT8 dreg)
1446{
1447   emit_op_modrm_reg(emitptr, OP_G5, OP_32BIT, 4, dreg);
1448}
1449
1450INLINE void emit_jmp_m32bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1451{
1452   emit_op_modrm_mem(emitptr, OP_G5, OP_32BIT, 4, base, index, scale, disp);
1453}
1454
1455#define emit_jmp_m32abs(e, addr)                        emit_jmp_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1456#define emit_jmp_m32bd(e, base, disp)                     emit_jmp_m32bisd(e, (base),   REG_NONE, 1,       (disp))
1457#define emit_jmp_m32isd(e, index, scale, disp)               emit_jmp_m32bisd(e, REG_NONE, (index),  (scale), (disp))
1458
1459#endif
1460
1461
1462/*------------------------------------------------------------------
1463    emit_jmp_r64_*
1464------------------------------------------------------------------*/
1465
1466#ifdef PTR64
1467
1468INLINE void emit_jmp_r64(x86code **emitptr, UINT8 dreg)
1469{
1470   emit_op_modrm_reg(emitptr, OP_G5, OP_32BIT, 4, dreg);
1471}
1472
1473INLINE void emit_jmp_m64bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1474{
1475   emit_op_modrm_mem(emitptr, OP_G5, OP_32BIT, 4, base, index, scale, disp);
1476}
1477
1478#define emit_jmp_m64abs(e, addr)                        emit_jmp_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1479#define emit_jmp_m64bd(e, base, disp)                     emit_jmp_m64bisd(e, (base),   REG_NONE, 1,       (disp))
1480#define emit_jmp_m64isd(e, index, scale, disp)               emit_jmp_m64bisd(e, REG_NONE, (index),  (scale), (disp))
1481
1482#endif
1483
1484
1485
1486/***************************************************************************
1487    MOVE EMITTERS
1488***************************************************************************/
1489
1490/*------------------------------------------------------------------
1491    emit_mov_r8_*
1492------------------------------------------------------------------*/
1493
1494INLINE void emit_mov_r8_imm(x86code **emitptr, UINT8 dreg, UINT8 imm)
1495{
1496   emit_op(emitptr, OP_MOV_AL_Ib | (dreg & 7), OP_32BIT, 0, 0, dreg);
1497   emit_byte(emitptr, imm);
1498}
1499
1500INLINE void emit_mov_r8_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1501{
1502   emit_op_modrm_reg(emitptr, OP_MOV_Gb_Eb, OP_32BIT, dreg, sreg);
1503}
1504
1505INLINE void emit_mov_r8_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1506{
1507   emit_op_modrm_mem(emitptr, OP_MOV_Gb_Eb, OP_32BIT, dreg, base, index, scale, disp);
1508}
1509
1510INLINE void emit_mov_m8bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
1511{
1512   emit_op_modrm_mem(emitptr, OP_G11_Eb_Ib, OP_32BIT, 0, base, index, scale, disp);
1513   emit_byte(emitptr, imm);
1514}
1515
1516INLINE void emit_mov_m8bisd_r8(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
1517{
1518   emit_op_modrm_mem(emitptr, OP_MOV_Eb_Gb, OP_32BIT, sreg, base, index, scale, disp);
1519}
1520
1521#define emit_mov_r8_m8abs(e, dreg, addr)               emit_mov_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1522#define emit_mov_r8_m8bd(e, dreg, base, disp)            emit_mov_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1523#define emit_mov_r8_m8isd(e, dreg, index, scale, disp)      emit_mov_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1524
1525#define emit_mov_m8abs_r8(e, addr, sreg)               emit_mov_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
1526#define emit_mov_m8bd_r8(e, base, disp, sreg)            emit_mov_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
1527#define emit_mov_m8isd_r8(e, index, scale, disp, sreg)      emit_mov_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
1528
1529#define emit_mov_m8abs_imm(e, addr, imm)               emit_mov_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
1530#define emit_mov_m8bd_imm(e, base, disp, imm)            emit_mov_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
1531#define emit_mov_m8isd_imm(e, index, scale, disp, imm)      emit_mov_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
1532
1533
1534/*------------------------------------------------------------------
1535    emit_mov_r16_*
1536------------------------------------------------------------------*/
1537
1538INLINE void emit_mov_r16_imm(x86code **emitptr, UINT8 dreg, UINT16 imm)
1539{
1540   emit_byte(emitptr, PREFIX_OPSIZE);
1541   emit_op(emitptr, OP_MOV_rAX_Iv | (dreg & 7), OP_32BIT, 0, 0, dreg);
1542   emit_word(emitptr, imm);
1543}
1544
1545INLINE void emit_mov_r16_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1546{
1547   emit_byte(emitptr, PREFIX_OPSIZE);
1548   emit_op_modrm_reg(emitptr, OP_MOV_Gv_Ev, OP_32BIT, dreg, sreg);
1549}
1550
1551INLINE void emit_mov_r16_m16bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1552{
1553   emit_byte(emitptr, PREFIX_OPSIZE);
1554   emit_op_modrm_mem(emitptr, OP_MOV_Gv_Ev, OP_32BIT, dreg, base, index, scale, disp);
1555}
1556
1557INLINE void emit_mov_m16bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT16 imm)
1558{
1559   emit_byte(emitptr, PREFIX_OPSIZE);
1560   emit_op_modrm_mem(emitptr, OP_G11_Ev_Iz, OP_32BIT, 0, base, index, scale, disp);
1561   emit_word(emitptr, imm);
1562}
1563
1564INLINE void emit_mov_m16bisd_r16(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
1565{
1566   emit_byte(emitptr, PREFIX_OPSIZE);
1567   emit_op_modrm_mem(emitptr, OP_MOV_Ev_Gv, OP_32BIT, sreg, base, index, scale, disp);
1568}
1569
1570INLINE void emit_cmovcc_r16_r16(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 sreg)
1571{
1572   emit_byte(emitptr, PREFIX_OPSIZE);
1573   emit_op_modrm_reg(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_32BIT, dreg, sreg);
1574}
1575
1576INLINE void emit_cmovcc_r16_m16bisd(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1577{
1578   emit_byte(emitptr, PREFIX_OPSIZE);
1579   emit_op_modrm_mem(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_32BIT, dreg, base, index, scale, disp);
1580}
1581
1582#define emit_mov_r16_m16abs(e, dreg, addr)               emit_mov_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1583#define emit_mov_r16_m16bd(e, dreg, base, disp)            emit_mov_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1584#define emit_mov_r16_m16isd(e, dreg, index, scale, disp)   emit_mov_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1585
1586#define emit_mov_m16abs_r16(e, addr, sreg)               emit_mov_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
1587#define emit_mov_m16bd_r16(e, base, disp, sreg)            emit_mov_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
1588#define emit_mov_m16isd_r16(e, index, scale, disp, sreg)   emit_mov_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
1589
1590#define emit_mov_m16abs_imm(e, addr, imm)               emit_mov_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
1591#define emit_mov_m16bd_imm(e, base, disp, imm)            emit_mov_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
1592#define emit_mov_m16isd_imm(e, index, scale, disp, imm)      emit_mov_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
1593
1594#define emit_cmovcc_r16_m16abs(e, cond, dreg, addr)               emit_cmovcc_r16_m16bisd(e, cond, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1595#define emit_cmovcc_r16_m16bd(e, cond, dreg, base, disp)         emit_cmovcc_r16_m16bisd(e, cond, dreg, (base),   REG_NONE, 1,       (disp))
1596#define emit_cmovcc_r16_m16isd(e, cond, dreg, index, scale, disp)   emit_cmovcc_r16_m16bisd(e, cond, dreg, REG_NONE, (index),  (scale), (disp))
1597
1598
1599/*------------------------------------------------------------------
1600    emit_mov_r32_*
1601------------------------------------------------------------------*/
1602
1603INLINE void emit_mov_r32_imm(x86code **emitptr, UINT8 dreg, UINT32 imm)
1604{
1605   emit_op(emitptr, OP_MOV_rAX_Iv | (dreg & 7), OP_32BIT, 0, 0, dreg);
1606   emit_dword(emitptr, imm);
1607}
1608
1609INLINE void emit_mov_r32_r32(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1610{
1611   emit_op_modrm_reg(emitptr, OP_MOV_Gv_Ev, OP_32BIT, dreg, sreg);
1612}
1613
1614INLINE void emit_mov_r32_m32bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1615{
1616   emit_op_modrm_mem(emitptr, OP_MOV_Gv_Ev, OP_32BIT, dreg, base, index, scale, disp);
1617}
1618
1619INLINE void emit_mov_m32bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT32 imm)
1620{
1621   emit_op_modrm_mem(emitptr, OP_G11_Ev_Iz, OP_32BIT, 0, base, index, scale, disp);
1622   emit_dword(emitptr, imm);
1623}
1624
1625INLINE void emit_mov_m32bisd_r32(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
1626{
1627   emit_op_modrm_mem(emitptr, OP_MOV_Ev_Gv, OP_32BIT, sreg, base, index, scale, disp);
1628}
1629
1630INLINE void emit_cmovcc_r32_r32(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 sreg)
1631{
1632   emit_op_modrm_reg(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_32BIT, dreg, sreg);
1633}
1634
1635INLINE void emit_cmovcc_r32_m32bisd(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1636{
1637   emit_op_modrm_mem(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_32BIT, dreg, base, index, scale, disp);
1638}
1639
1640#define emit_mov_r32_m32abs(e, dreg, addr)               emit_mov_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1641#define emit_mov_r32_m32bd(e, dreg, base, disp)            emit_mov_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1642#define emit_mov_r32_m32isd(e, dreg, index, scale, disp)   emit_mov_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1643
1644#define emit_mov_m32abs_r32(e, addr, sreg)               emit_mov_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
1645#define emit_mov_m32bd_r32(e, base, disp, sreg)            emit_mov_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
1646#define emit_mov_m32isd_r32(e, index, scale, disp, sreg)   emit_mov_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
1647
1648#define emit_mov_m32abs_imm(e, addr, imm)               emit_mov_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
1649#define emit_mov_m32bd_imm(e, base, disp, imm)            emit_mov_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
1650#define emit_mov_m32isd_imm(e, index, scale, disp, imm)      emit_mov_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
1651
1652#define emit_cmovcc_r32_m32abs(e, cond, dreg, addr)               emit_cmovcc_r32_m32bisd(e, cond, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1653#define emit_cmovcc_r32_m32bd(e, cond, dreg, base, disp)         emit_cmovcc_r32_m32bisd(e, cond, dreg, (base),   REG_NONE, 1,       (disp))
1654#define emit_cmovcc_r32_m32isd(e, cond, dreg, index, scale, disp)   emit_cmovcc_r32_m32bisd(e, cond, dreg, REG_NONE, (index),  (scale), (disp))
1655
1656
1657/*------------------------------------------------------------------
1658    emit_mov_r64_*
1659------------------------------------------------------------------*/
1660
1661#ifdef PTR64
1662
1663INLINE void emit_mov_r64_imm(x86code **emitptr, UINT8 dreg, UINT64 imm)
1664{
1665   emit_op(emitptr, OP_MOV_rAX_Iv | (dreg & 7), OP_64BIT, 0, 0, dreg);
1666   emit_qword(emitptr, imm);
1667}
1668
1669INLINE void emit_mov_r64_r64(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1670{
1671   emit_op_modrm_reg(emitptr, OP_MOV_Gv_Ev, OP_64BIT, dreg, sreg);
1672}
1673
1674INLINE void emit_mov_r64_m64bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1675{
1676   emit_op_modrm_mem(emitptr, OP_MOV_Gv_Ev, OP_64BIT, dreg, base, index, scale, disp);
1677}
1678
1679INLINE void emit_mov_m64bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT64 imm)
1680{
1681   assert((INT32)imm == (INT64)imm);
1682   emit_op_modrm_mem(emitptr, OP_G11_Ev_Iz, OP_64BIT, 0, base, index, scale, disp);
1683   emit_dword(emitptr, (INT32)imm);
1684}
1685
1686INLINE void emit_mov_m64bisd_r64(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
1687{
1688   emit_op_modrm_mem(emitptr, OP_MOV_Ev_Gv, OP_64BIT, sreg, base, index, scale, disp);
1689}
1690
1691INLINE void emit_cmovcc_r64_r64(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 sreg)
1692{
1693   emit_op_modrm_reg(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_64BIT, dreg, sreg);
1694}
1695
1696INLINE void emit_cmovcc_r64_m64bisd(x86code **emitptr, UINT8 condition, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1697{
1698   emit_op_modrm_mem(emitptr, OP_CMOV_O_Gv_Ev + condition, OP_64BIT, dreg, base, index, scale, disp);
1699}
1700
1701#define emit_mov_r64_m64abs(e, dreg, addr)               emit_mov_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1702#define emit_mov_r64_m64bd(e, dreg, base, disp)            emit_mov_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1703#define emit_mov_r64_m64isd(e, dreg, index, scale, disp)   emit_mov_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1704
1705#define emit_mov_m64abs_r64(e, addr, sreg)               emit_mov_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
1706#define emit_mov_m64bd_r64(e, base, disp, sreg)            emit_mov_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
1707#define emit_mov_m64isd_r64(e, index, scale, disp, sreg)   emit_mov_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
1708
1709#define emit_mov_m64abs_imm(e, addr, imm)               emit_mov_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
1710#define emit_mov_m64bd_imm(e, base, disp, imm)            emit_mov_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
1711#define emit_mov_m64isd_imm(e, index, scale, disp, imm)      emit_mov_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
1712
1713#define emit_cmovcc_r64_m64abs(e, cond, dreg, addr)               emit_cmovcc_r64_m64bisd(e, cond, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1714#define emit_cmovcc_r64_m64bd(e, cond, dreg, base, disp)         emit_cmovcc_r64_m64bisd(e, cond, dreg, (base),   REG_NONE, 1,       (disp))
1715#define emit_cmovcc_r64_m64isd(e, cond, dreg, index, scale, disp)   emit_cmovcc_r64_m64bisd(e, cond, dreg, REG_NONE, (index),  (scale), (disp))
1716
1717#endif
1718
1719
1720
1721/***************************************************************************
1722    MOVE EXTENDED EMITTERS
1723***************************************************************************/
1724
1725/*------------------------------------------------------------------
1726    emit_movsx_r16_*
1727------------------------------------------------------------------*/
1728
1729INLINE void emit_movsx_r16_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1730{
1731   emit_byte(emitptr, PREFIX_OPSIZE);
1732   emit_op_modrm_reg(emitptr, OP_MOVSX_Gv_Eb, OP_32BIT, dreg, sreg);
1733}
1734
1735INLINE void emit_movsx_r16_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1736{
1737   emit_byte(emitptr, PREFIX_OPSIZE);
1738   emit_op_modrm_mem(emitptr, OP_MOVSX_Gv_Eb, OP_32BIT, dreg, base, index, scale, disp);
1739}
1740
1741#define emit_movsx_r16_m8abs(e, dreg, addr)               emit_movsx_r16_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1742#define emit_movsx_r16_m8bd(e, dreg, base, disp)         emit_movsx_r16_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1743#define emit_movsx_r16_m8isd(e, dreg, index, scale, disp)   emit_movsx_r16_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1744
1745
1746/*------------------------------------------------------------------
1747    emit_movzx_r16_*
1748------------------------------------------------------------------*/
1749
1750INLINE void emit_movzx_r16_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1751{
1752   emit_byte(emitptr, PREFIX_OPSIZE);
1753   emit_op_modrm_reg(emitptr, OP_MOVZX_Gv_Eb, OP_32BIT, dreg, sreg);
1754}
1755
1756INLINE void emit_movzx_r16_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1757{
1758   emit_byte(emitptr, PREFIX_OPSIZE);
1759   emit_op_modrm_mem(emitptr, OP_MOVZX_Gv_Eb, OP_32BIT, dreg, base, index, scale, disp);
1760}
1761
1762#define emit_movzx_r16_m8abs(e, dreg, addr)               emit_movzx_r16_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1763#define emit_movzx_r16_m8bd(e, dreg, base, disp)         emit_movzx_r16_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1764#define emit_movzx_r16_m8isd(e, dreg, index, scale, disp)   emit_movzx_r16_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1765
1766
1767/*------------------------------------------------------------------
1768    emit_movsx_r32_*
1769------------------------------------------------------------------*/
1770
1771INLINE void emit_movsx_r32_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1772{
1773   emit_byte(emitptr, PREFIX_OPSIZE);
1774   emit_op_modrm_reg(emitptr, OP_MOVSX_Gv_Eb, OP_32BIT, dreg, sreg);
1775}
1776
1777INLINE void emit_movsx_r32_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1778{
1779   emit_byte(emitptr, PREFIX_OPSIZE);
1780   emit_op_modrm_mem(emitptr, OP_MOVSX_Gv_Eb, OP_32BIT, dreg, base, index, scale, disp);
1781}
1782
1783INLINE void emit_movsx_r32_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1784{
1785   emit_byte(emitptr, PREFIX_OPSIZE);
1786   emit_op_modrm_reg(emitptr, OP_MOVSX_Gv_Ew, OP_32BIT, dreg, sreg);
1787}
1788
1789INLINE void emit_movsx_r32_m16bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1790{
1791   emit_byte(emitptr, PREFIX_OPSIZE);
1792   emit_op_modrm_mem(emitptr, OP_MOVSX_Gv_Ew, OP_32BIT, dreg, base, index, scale, disp);
1793}
1794
1795#define emit_movsx_r32_m8abs(e, dreg, addr)               emit_movsx_r32_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1796#define emit_movsx_r32_m8bd(e, dreg, base, disp)         emit_movsx_r32_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1797#define emit_movsx_r32_m8isd(e, dreg, index, scale, disp)   emit_movsx_r32_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1798
1799#define emit_movsx_r32_m16abs(e, dreg, addr)            emit_movsx_r32_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1800#define emit_movsx_r32_m16bd(e, dreg, base, disp)         emit_movsx_r32_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1801#define emit_movsx_r32_m16isd(e, dreg, index, scale, disp)   emit_movsx_r32_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1802
1803
1804/*------------------------------------------------------------------
1805    emit_movzx_r32_*
1806------------------------------------------------------------------*/
1807
1808INLINE void emit_movzx_r32_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1809{
1810   emit_byte(emitptr, PREFIX_OPSIZE);
1811   emit_op_modrm_reg(emitptr, OP_MOVZX_Gv_Eb, OP_32BIT, dreg, sreg);
1812}
1813
1814INLINE void emit_movzx_r32_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1815{
1816   emit_byte(emitptr, PREFIX_OPSIZE);
1817   emit_op_modrm_mem(emitptr, OP_MOVZX_Gv_Eb, OP_32BIT, dreg, base, index, scale, disp);
1818}
1819
1820INLINE void emit_movzx_r32_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1821{
1822   emit_byte(emitptr, PREFIX_OPSIZE);
1823   emit_op_modrm_reg(emitptr, OP_MOVZX_Gv_Ew, OP_32BIT, dreg, sreg);
1824}
1825
1826INLINE void emit_movzx_r32_m16bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1827{
1828   emit_byte(emitptr, PREFIX_OPSIZE);
1829   emit_op_modrm_mem(emitptr, OP_MOVZX_Gv_Ew, OP_32BIT, dreg, base, index, scale, disp);
1830}
1831
1832#define emit_movzx_r32_m8abs(e, dreg, addr)               emit_movzx_r32_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1833#define emit_movzx_r32_m8bd(e, dreg, base, disp)         emit_movzx_r32_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1834#define emit_movzx_r32_m8isd(e, dreg, index, scale, disp)   emit_movzx_r32_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1835
1836#define emit_movzx_r32_m16abs(e, dreg, addr)            emit_movzx_r32_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1837#define emit_movzx_r32_m16bd(e, dreg, base, disp)         emit_movzx_r32_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1838#define emit_movzx_r32_m16isd(e, dreg, index, scale, disp)   emit_movzx_r32_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1839
1840
1841/*------------------------------------------------------------------
1842    emit_movsx_r64_*
1843------------------------------------------------------------------*/
1844
1845#ifdef PTR64
1846
1847INLINE void emit_movsx_r64_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1848{
1849   emit_byte(emitptr, PREFIX_OPSIZE);
1850   emit_op_modrm_reg(emitptr, OP_MOVSX_Gv_Eb, OP_64BIT, dreg, sreg);
1851}
1852
1853INLINE void emit_movsx_r64_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1854{
1855   emit_byte(emitptr, PREFIX_OPSIZE);
1856   emit_op_modrm_mem(emitptr, OP_MOVSX_Gv_Eb, OP_64BIT, dreg, base, index, scale, disp);
1857}
1858
1859INLINE void emit_movsx_r64_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1860{
1861   emit_byte(emitptr, PREFIX_OPSIZE);
1862   emit_op_modrm_reg(emitptr, OP_MOVSX_Gv_Ew, OP_64BIT, dreg, sreg);
1863}
1864
1865INLINE void emit_movsx_r64_m16bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1866{
1867   emit_byte(emitptr, PREFIX_OPSIZE);
1868   emit_op_modrm_mem(emitptr, OP_MOVSX_Gv_Ew, OP_64BIT, dreg, base, index, scale, disp);
1869}
1870
1871INLINE void emit_movsxd_r64_r32(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1872{
1873   emit_byte(emitptr, PREFIX_OPSIZE);
1874   emit_op_modrm_reg(emitptr, OP_MOVSXD_Gv_Ev, OP_64BIT, dreg, sreg);
1875}
1876
1877INLINE void emit_movsxd_r64_m32bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1878{
1879   emit_byte(emitptr, PREFIX_OPSIZE);
1880   emit_op_modrm_mem(emitptr, OP_MOVSXD_Gv_Ev, OP_64BIT, dreg, base, index, scale, disp);
1881}
1882
1883#define emit_movsx_r64_m8abs(e, dreg, addr)               emit_movsx_r64_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1884#define emit_movsx_r64_m8bd(e, dreg, base, disp)         emit_movsx_r64_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1885#define emit_movsx_r64_m8isd(e, dreg, index, scale, disp)   emit_movsx_r64_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1886
1887#define emit_movsx_r64_m16abs(e, dreg, addr)            emit_movsx_r64_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1888#define emit_movsx_r64_m16bd(e, dreg, base, disp)         emit_movsx_r64_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1889#define emit_movsx_r64_m16isd(e, dreg, index, scale, disp)   emit_movsx_r64_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1890
1891#define emit_movsxd_r64_m32abs(e, dreg, addr)            emit_movsxd_r64_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1892#define emit_movsxd_r64_m32bd(e, dreg, base, disp)         emit_movsxd_r64_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1893#define emit_movsxd_r64_m32isd(e, dreg, index, scale, disp)   emit_movsxd_r64_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1894
1895#endif
1896
1897
1898/*------------------------------------------------------------------
1899    emit_movzx_r64_*
1900------------------------------------------------------------------*/
1901
1902#ifdef PTR64
1903
1904INLINE void emit_movzx_r64_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1905{
1906   emit_byte(emitptr, PREFIX_OPSIZE);
1907   emit_op_modrm_reg(emitptr, OP_MOVZX_Gv_Eb, OP_64BIT, dreg, sreg);
1908}
1909
1910INLINE void emit_movzx_r64_m8bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1911{
1912   emit_byte(emitptr, PREFIX_OPSIZE);
1913   emit_op_modrm_mem(emitptr, OP_MOVZX_Gv_Eb, OP_64BIT, dreg, base, index, scale, disp);
1914}
1915
1916INLINE void emit_movzx_r64_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1917{
1918   emit_byte(emitptr, PREFIX_OPSIZE);
1919   emit_op_modrm_reg(emitptr, OP_MOVZX_Gv_Ew, OP_64BIT, dreg, sreg);
1920}
1921
1922INLINE void emit_movzx_r64_m16bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
1923{
1924   emit_byte(emitptr, PREFIX_OPSIZE);
1925   emit_op_modrm_mem(emitptr, OP_MOVZX_Gv_Ew, OP_64BIT, dreg, base, index, scale, disp);
1926}
1927
1928#define emit_movzx_r64_m8abs(e, dreg, addr)               emit_movzx_r64_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1929#define emit_movzx_r64_m8bd(e, dreg, base, disp)         emit_movzx_r64_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1930#define emit_movzx_r64_m8isd(e, dreg, index, scale, disp)   emit_movzx_r64_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1931
1932#define emit_movzx_r64_m16abs(e, dreg, addr)            emit_movzx_r64_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
1933#define emit_movzx_r64_m16bd(e, dreg, base, disp)         emit_movzx_r64_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
1934#define emit_movzx_r64_m16isd(e, dreg, index, scale, disp)   emit_movzx_r64_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
1935
1936#endif
1937
1938
1939
1940/***************************************************************************
1941    TEST EMITTERS
1942***************************************************************************/
1943
1944/*------------------------------------------------------------------
1945    emit_test_r8_*
1946------------------------------------------------------------------*/
1947
1948INLINE void emit_test_r8_imm(x86code **emitptr, UINT8 dreg, UINT8 imm)
1949{
1950   emit_op_modrm_reg(emitptr, OP_G3_Eb, OP_32BIT, 0, dreg);
1951   emit_byte(emitptr, imm);
1952}
1953
1954INLINE void emit_test_r8_r8(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1955{
1956   emit_op_modrm_reg(emitptr, OP_TEST_Eb_Gb, OP_32BIT, sreg, dreg);
1957}
1958
1959INLINE void emit_test_m8bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
1960{
1961   emit_op_modrm_mem(emitptr, OP_G3_Eb, OP_32BIT, 0, base, index, scale, disp);
1962   emit_byte(emitptr, imm);
1963}
1964
1965INLINE void emit_test_m8bisd_r8(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
1966{
1967   emit_op_modrm_mem(emitptr, OP_TEST_Eb_Gb, OP_32BIT, sreg, base, index, scale, disp);
1968}
1969
1970#define emit_test_m8abs_imm(e, addr, imm)               emit_test_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
1971#define emit_test_m8bd_imm(e, base, disp, imm)            emit_test_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
1972#define emit_test_m8isd_imm(e, index, scale, disp, imm)      emit_test_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
1973
1974#define emit_test_m8abs_r8(e, addr, sreg)               emit_test_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
1975#define emit_test_m8bd_r8(e, base, disp, sreg)            emit_test_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
1976#define emit_test_m8isd_r8(e, index, scale, disp, sreg)      emit_test_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
1977
1978
1979/*------------------------------------------------------------------
1980    emit_test_r16_*
1981------------------------------------------------------------------*/
1982
1983INLINE void emit_test_r16_imm(x86code **emitptr, UINT8 dreg, UINT16 imm)
1984{
1985   emit_byte(emitptr, PREFIX_OPSIZE);
1986   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_32BIT, 0, dreg);
1987   emit_word(emitptr, imm);
1988}
1989
1990INLINE void emit_test_r16_r16(x86code **emitptr, UINT8 dreg, UINT8 sreg)
1991{
1992   emit_byte(emitptr, PREFIX_OPSIZE);
1993   emit_op_modrm_reg(emitptr, OP_TEST_Ev_Gv, OP_32BIT, sreg, dreg);
1994}
1995
1996INLINE void emit_test_m16bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT16 imm)
1997{
1998   emit_byte(emitptr, PREFIX_OPSIZE);
1999   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_32BIT, 0, base, index, scale, disp);
2000   emit_word(emitptr, imm);
2001}
2002
2003INLINE void emit_test_m16bisd_r16(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2004{
2005   emit_byte(emitptr, PREFIX_OPSIZE);
2006   emit_op_modrm_mem(emitptr, OP_TEST_Ev_Gv, OP_32BIT, sreg, base, index, scale, disp);
2007}
2008
2009#define emit_test_m16abs_imm(e, addr, imm)               emit_test_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2010#define emit_test_m16bd_imm(e, base, disp, imm)            emit_test_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2011#define emit_test_m16isd_imm(e, index, scale, disp, imm)   emit_test_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2012
2013#define emit_test_m16abs_r16(e, addr, sreg)               emit_test_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2014#define emit_test_m16bd_r16(e, base, disp, sreg)         emit_test_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2015#define emit_test_m16isd_r16(e, index, scale, disp, sreg)   emit_test_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2016
2017
2018/*------------------------------------------------------------------
2019    emit_test_r32_*
2020------------------------------------------------------------------*/
2021
2022INLINE void emit_test_r32_imm(x86code **emitptr, UINT8 dreg, UINT32 imm)
2023{
2024   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_32BIT, 0, dreg);
2025   emit_dword(emitptr, imm);
2026}
2027
2028INLINE void emit_test_r32_r32(x86code **emitptr, UINT8 dreg, UINT8 sreg)
2029{
2030   emit_op_modrm_reg(emitptr, OP_TEST_Ev_Gv, OP_32BIT, sreg, dreg);
2031}
2032
2033INLINE void emit_test_m32bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT32 imm)
2034{
2035   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_32BIT, 0, base, index, scale, disp);
2036   emit_dword(emitptr, imm);
2037}
2038
2039INLINE void emit_test_m32bisd_r32(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2040{
2041   emit_op_modrm_mem(emitptr, OP_TEST_Ev_Gv, OP_32BIT, sreg, base, index, scale, disp);
2042}
2043
2044#define emit_test_m32abs_imm(e, addr, imm)               emit_test_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2045#define emit_test_m32bd_imm(e, base, disp, imm)            emit_test_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2046#define emit_test_m32isd_imm(e, index, scale, disp, imm)   emit_test_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2047
2048#define emit_test_m32abs_r32(e, addr, sreg)               emit_test_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2049#define emit_test_m32bd_r32(e, base, disp, sreg)         emit_test_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2050#define emit_test_m32isd_r32(e, index, scale, disp, sreg)   emit_test_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2051
2052
2053/*------------------------------------------------------------------
2054    emit_test_r64_*
2055------------------------------------------------------------------*/
2056
2057#ifdef PTR64
2058
2059INLINE void emit_test_r64_imm(x86code **emitptr, UINT8 dreg, UINT64 imm)
2060{
2061   assert((INT32)imm == (INT64)imm);
2062   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_64BIT, 0, dreg);
2063   emit_dword(emitptr, imm);
2064}
2065
2066INLINE void emit_test_r64_r64(x86code **emitptr, UINT8 dreg, UINT8 sreg)
2067{
2068   emit_op_modrm_reg(emitptr, OP_TEST_Ev_Gv, OP_64BIT, sreg, dreg);
2069}
2070
2071INLINE void emit_test_m64bisd_imm(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT64 imm)
2072{
2073   assert((INT32)imm == (INT64)imm);
2074   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_64BIT, 0, base, index, scale, disp);
2075   emit_dword(emitptr, (INT32)imm);
2076}
2077
2078INLINE void emit_test_m64bisd_r64(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2079{
2080   emit_op_modrm_mem(emitptr, OP_TEST_Ev_Gv, OP_64BIT, sreg, base, index, scale, disp);
2081}
2082
2083#define emit_test_m64abs_imm(e, addr, imm)               emit_test_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2084#define emit_test_m64bd_imm(e, base, disp, imm)            emit_test_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2085#define emit_test_m64isd_imm(e, index, scale, disp, imm)   emit_test_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2086
2087#define emit_test_m64abs_r64(e, addr, sreg)               emit_test_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2088#define emit_test_m64bd_r64(e, base, disp, sreg)         emit_test_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
2089#define emit_test_m64isd_r64(e, index, scale, disp, sreg)   emit_test_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
2090
2091#endif
2092
2093
2094
2095/***************************************************************************
2096    8-BIT ARITHMETIC EMITTERS
2097***************************************************************************/
2098
2099/*
2100    Note that the following code relies on this:
2101
2102        00-05 or /0 = ADD
2103        08-0d or /1 = OR
2104        10-15 or /2 = ADC
2105        18-1d or /3 = SBB
2106        20-25 or /4 = AND
2107        28-2d or /5 = SUB
2108        30-35 or /6 = XOR
2109        38-3d or /7 = CMP
2110*/
2111
2112/*------------------------------------------------------------------
2113    emit_arith_r8_*
2114------------------------------------------------------------------*/
2115
2116INLINE void emit_arith_r8_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 imm)
2117{
2118   emit_op_modrm_reg(emitptr, OP_G1_Eb_Ib, OP_32BIT, opindex, dreg);
2119   emit_byte(emitptr, imm);
2120}
2121
2122INLINE void emit_arith_m8bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
2123{
2124   emit_op_modrm_mem(emitptr, OP_G1_Eb_Ib, OP_32BIT, opindex, base, index, scale, disp);
2125   emit_byte(emitptr, imm);
2126}
2127
2128INLINE void emit_arith_r8_r8(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 sreg)
2129{
2130   emit_op_modrm_reg(emitptr, OP_ADD_Eb_Gb + 8 * opindex, OP_32BIT, dreg, sreg);
2131}
2132
2133INLINE void emit_arith_r8_m8bisd(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
2134{
2135   emit_op_modrm_mem(emitptr, OP_ADD_Eb_Gb + 8 * opindex, OP_32BIT, dreg, base, index, scale, disp);
2136}
2137
2138INLINE void emit_arith_m8bisd_r8(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2139{
2140   emit_op_modrm_mem(emitptr, OP_ADD_Gb_Eb + 8 * opindex, OP_32BIT, sreg, base, index, scale, disp);
2141}
2142
2143
2144/*------------------------------------------------------------------
2145    emit_add_r8_*
2146------------------------------------------------------------------*/
2147
2148#define emit_add_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 0, dreg, imm)
2149#define emit_add_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 0, base, index, scale, disp, imm)
2150#define emit_add_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 0, dreg, sreg)
2151#define emit_add_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 0, dreg, base, index, scale, disp)
2152#define emit_add_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 0, base, index, scale, disp, sreg)
2153
2154#define emit_add_m8abs_imm(e, addr, imm)                  emit_add_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2155#define emit_add_m8bd_imm(e, base, disp, imm)               emit_add_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2156#define emit_add_m8isd_imm(e, index, scale, disp, imm)         emit_add_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2157
2158#define emit_add_r8_m8abs(e, dreg, addr)                  emit_add_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2159#define emit_add_r8_m8bd(e, dreg, base, disp)               emit_add_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2160#define emit_add_r8_m8isd(e, dreg, index, scale, disp)         emit_add_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2161
2162#define emit_add_m8abs_r8(e, addr, sreg)                  emit_add_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2163#define emit_add_m8bd_r8(e, base, disp, sreg)               emit_add_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2164#define emit_add_m8isd_r8(e, index, scale, disp, sreg)         emit_add_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2165
2166
2167/*------------------------------------------------------------------
2168    emit_or_r8_*
2169------------------------------------------------------------------*/
2170
2171#define emit_or_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 1, dreg, imm)
2172#define emit_or_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 1, base, index, scale, disp, imm)
2173#define emit_or_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 1, dreg, sreg)
2174#define emit_or_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 1, dreg, base, index, scale, disp)
2175#define emit_or_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 1, base, index, scale, disp, sreg)
2176
2177#define emit_or_m8abs_imm(e, addr, imm)                     emit_or_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2178#define emit_or_m8bd_imm(e, base, disp, imm)               emit_or_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2179#define emit_or_m8isd_imm(e, index, scale, disp, imm)         emit_or_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2180
2181#define emit_or_r8_m8abs(e, dreg, addr)                     emit_or_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2182#define emit_or_r8_m8bd(e, dreg, base, disp)               emit_or_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2183#define emit_or_r8_m8isd(e, dreg, index, scale, disp)         emit_or_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2184
2185#define emit_or_m8abs_r8(e, addr, sreg)                     emit_or_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2186#define emit_or_m8bd_r8(e, base, disp, sreg)               emit_or_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2187#define emit_or_m8isd_r8(e, index, scale, disp, sreg)         emit_or_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2188
2189
2190/*------------------------------------------------------------------
2191    emit_adc_r8_*
2192------------------------------------------------------------------*/
2193
2194#define emit_adc_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 2, dreg, imm)
2195#define emit_adc_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 2, base, index, scale, disp, imm)
2196#define emit_adc_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 2, dreg, sreg)
2197#define emit_adc_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 2, dreg, base, index, scale, disp)
2198#define emit_adc_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 2, base, index, scale, disp, sreg)
2199
2200#define emit_adc_m8abs_imm(e, addr, imm)                  emit_adc_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2201#define emit_adc_m8bd_imm(e, base, disp, imm)               emit_adc_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2202#define emit_adc_m8isd_imm(e, index, scale, disp, imm)         emit_adc_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2203
2204#define emit_adc_r8_m8abs(e, dreg, addr)                  emit_adc_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2205#define emit_adc_r8_m8bd(e, dreg, base, disp)               emit_adc_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2206#define emit_adc_r8_m8isd(e, dreg, index, scale, disp)         emit_adc_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2207
2208#define emit_adc_m8abs_r8(e, addr, sreg)                  emit_adc_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2209#define emit_adc_m8bd_r8(e, base, disp, sreg)               emit_adc_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2210#define emit_adc_m8isd_r8(e, index, scale, disp, sreg)         emit_adc_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2211
2212
2213/*------------------------------------------------------------------
2214    emit_sbb_r8_*
2215------------------------------------------------------------------*/
2216
2217#define emit_sbb_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 3, dreg, imm)
2218#define emit_sbb_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 3, base, index, scale, disp, imm)
2219#define emit_sbb_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 3, dreg, sreg)
2220#define emit_sbb_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 3, dreg, base, index, scale, disp)
2221#define emit_sbb_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 3, base, index, scale, disp, sreg)
2222
2223#define emit_sbb_m8abs_imm(e, addr, imm)                  emit_sbb_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2224#define emit_sbb_m8bd_imm(e, base, disp, imm)               emit_sbb_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2225#define emit_sbb_m8isd_imm(e, index, scale, disp, imm)         emit_sbb_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2226
2227#define emit_sbb_r8_m8abs(e, dreg, addr)                  emit_sbb_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2228#define emit_sbb_r8_m8bd(e, dreg, base, disp)               emit_sbb_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2229#define emit_sbb_r8_m8isd(e, dreg, index, scale, disp)         emit_sbb_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2230
2231#define emit_sbb_m8abs_r8(e, addr, sreg)                  emit_sbb_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2232#define emit_sbb_m8bd_r8(e, base, disp, sreg)               emit_sbb_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2233#define emit_sbb_m8isd_r8(e, index, scale, disp, sreg)         emit_sbb_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2234
2235
2236/*------------------------------------------------------------------
2237    emit_and_r8_*
2238------------------------------------------------------------------*/
2239
2240#define emit_and_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 4, dreg, imm)
2241#define emit_and_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 4, base, index, scale, disp, imm)
2242#define emit_and_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 4, dreg, sreg)
2243#define emit_and_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 4, dreg, base, index, scale, disp)
2244#define emit_and_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 4, base, index, scale, disp, sreg)
2245
2246#define emit_and_m8abs_imm(e, addr, imm)                  emit_and_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2247#define emit_and_m8bd_imm(e, base, disp, imm)               emit_and_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2248#define emit_and_m8isd_imm(e, index, scale, disp, imm)         emit_and_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2249
2250#define emit_and_r8_m8abs(e, dreg, addr)                  emit_and_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2251#define emit_and_r8_m8bd(e, dreg, base, disp)               emit_and_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2252#define emit_and_r8_m8isd(e, dreg, index, scale, disp)         emit_and_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2253
2254#define emit_and_m8abs_r8(e, addr, sreg)                  emit_and_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2255#define emit_and_m8bd_r8(e, base, disp, sreg)               emit_and_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2256#define emit_and_m8isd_r8(e, index, scale, disp, sreg)         emit_and_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2257
2258
2259/*------------------------------------------------------------------
2260    emit_sub_r8_*
2261------------------------------------------------------------------*/
2262
2263#define emit_sub_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 5, dreg, imm)
2264#define emit_sub_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 5, base, index, scale, disp, imm)
2265#define emit_sub_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 5, dreg, sreg)
2266#define emit_sub_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 5, dreg, base, index, scale, disp)
2267#define emit_sub_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 5, base, index, scale, disp, sreg)
2268
2269#define emit_sub_m8abs_imm(e, addr, imm)                  emit_sub_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2270#define emit_sub_m8bd_imm(e, base, disp, imm)               emit_sub_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2271#define emit_sub_m8isd_imm(e, index, scale, disp, imm)         emit_sub_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2272
2273#define emit_sub_r8_m8abs(e, dreg, addr)                  emit_sub_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2274#define emit_sub_r8_m8bd(e, dreg, base, disp)               emit_sub_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2275#define emit_sub_r8_m8isd(e, dreg, index, scale, disp)         emit_sub_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2276
2277#define emit_sub_m8abs_r8(e, addr, sreg)                  emit_sub_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2278#define emit_sub_m8bd_r8(e, base, disp, sreg)               emit_sub_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2279#define emit_sub_m8isd_r8(e, index, scale, disp, sreg)         emit_sub_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2280
2281
2282/*------------------------------------------------------------------
2283    emit_xor_r8_*
2284------------------------------------------------------------------*/
2285
2286#define emit_xor_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 6, dreg, imm)
2287#define emit_xor_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 6, base, index, scale, disp, imm)
2288#define emit_xor_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 6, dreg, sreg)
2289#define emit_xor_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 6, dreg, base, index, scale, disp)
2290#define emit_xor_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 6, base, index, scale, disp, sreg)
2291
2292#define emit_xor_m8abs_imm(e, addr, imm)                  emit_xor_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2293#define emit_xor_m8bd_imm(e, base, disp, imm)               emit_xor_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2294#define emit_xor_m8isd_imm(e, index, scale, disp, imm)         emit_xor_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2295
2296#define emit_xor_r8_m8abs(e, dreg, addr)                  emit_xor_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2297#define emit_xor_r8_m8bd(e, dreg, base, disp)               emit_xor_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2298#define emit_xor_r8_m8isd(e, dreg, index, scale, disp)         emit_xor_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2299
2300#define emit_xor_m8abs_r8(e, addr, sreg)                  emit_xor_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2301#define emit_xor_m8bd_r8(e, base, disp, sreg)               emit_xor_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2302#define emit_xor_m8isd_r8(e, index, scale, disp, sreg)         emit_xor_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2303
2304
2305/*------------------------------------------------------------------
2306    emit_cmp_r8_*
2307------------------------------------------------------------------*/
2308
2309#define emit_cmp_r8_imm(e, dreg, imm)                     emit_arith_r8_imm(e, 7, dreg, imm)
2310#define emit_cmp_m8bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m8bisd_imm(e, 7, base, index, scale, disp, imm)
2311#define emit_cmp_r8_r8(e, dreg, sreg)                     emit_arith_r8_r8(e, 7, dreg, sreg)
2312#define emit_cmp_r8_m8bisd(e, dreg, base, index, scale, disp)   emit_arith_r8_m8bisd(e, 7, dreg, base, index, scale, disp)
2313#define emit_cmp_m8bisd_r8(e, base, index, scale, disp, sreg)   emit_arith_m8bisd_r8(e, 7, base, index, scale, disp, sreg)
2314
2315#define emit_cmp_m8abs_imm(e, addr, imm)                  emit_cmp_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2316#define emit_cmp_m8bd_imm(e, base, disp, imm)               emit_cmp_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2317#define emit_cmp_m8isd_imm(e, index, scale, disp, imm)         emit_cmp_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2318
2319#define emit_cmp_r8_m8abs(e, dreg, addr)                  emit_cmp_r8_m8bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2320#define emit_cmp_r8_m8bd(e, dreg, base, disp)               emit_cmp_r8_m8bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2321#define emit_cmp_r8_m8isd(e, dreg, index, scale, disp)         emit_cmp_r8_m8bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2322
2323#define emit_cmp_m8abs_r8(e, addr, sreg)                  emit_cmp_m8bisd_r8(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2324#define emit_cmp_m8bd_r8(e, base, disp, sreg)               emit_cmp_m8bisd_r8(e, (base),   REG_NONE, 1,       (disp), sreg)
2325#define emit_cmp_m8isd_r8(e, index, scale, disp, sreg)         emit_cmp_m8bisd_r8(e, REG_NONE, (index),  (scale), (disp), sreg)
2326
2327
2328
2329/***************************************************************************
2330    16-BIT ARITHMETIC EMITTERS
2331***************************************************************************/
2332
2333/*
2334    Note that the following code relies on this:
2335
2336        00-05 or /0 = ADD
2337        08-0d or /1 = OR
2338        10-15 or /2 = ADC
2339        18-1d or /3 = SBB
2340        20-25 or /4 = AND
2341        28-2d or /5 = SUB
2342        30-35 or /6 = XOR
2343        38-3d or /7 = CMP
2344*/
2345
2346INLINE void emit_arith_r16_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT16 imm)
2347{
2348   emit_byte(emitptr, PREFIX_OPSIZE);
2349   if ((INT8)imm == (INT16)imm)
2350   {
2351      emit_op_modrm_reg(emitptr, OP_G1_Ev_Ib, OP_32BIT, opindex, dreg);
2352      emit_byte(emitptr, (INT8)imm);
2353   }
2354   else
2355   {
2356      emit_op_modrm_reg(emitptr, OP_G1_Ev_Iz, OP_32BIT, opindex, dreg);
2357      emit_word(emitptr, imm);
2358   }
2359}
2360
2361INLINE void emit_arith_m16bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT16 imm)
2362{
2363   emit_byte(emitptr, PREFIX_OPSIZE);
2364   if ((INT8)imm == (INT16)imm)
2365   {
2366      emit_op_modrm_mem(emitptr, OP_G1_Ev_Ib, OP_32BIT, opindex, base, index, scale, disp);
2367      emit_byte(emitptr, (INT8)imm);
2368   }
2369   else
2370   {
2371      emit_op_modrm_mem(emitptr, OP_G1_Ev_Iz, OP_32BIT, opindex, base, index, scale, disp);
2372      emit_word(emitptr, imm);
2373   }
2374}
2375
2376INLINE void emit_arith_r16_r16(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 sreg)
2377{
2378   emit_byte(emitptr, PREFIX_OPSIZE);
2379   emit_op_modrm_reg(emitptr, OP_ADD_Ev_Gv + 8 * opindex, OP_32BIT, dreg, sreg);
2380}
2381
2382INLINE void emit_arith_r16_m16bisd(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
2383{
2384   emit_byte(emitptr, PREFIX_OPSIZE);
2385   emit_op_modrm_mem(emitptr, OP_ADD_Ev_Gv + 8 * opindex, OP_32BIT, dreg, base, index, scale, disp);
2386}
2387
2388INLINE void emit_arith_m16bisd_r16(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2389{
2390   emit_byte(emitptr, PREFIX_OPSIZE);
2391   emit_op_modrm_mem(emitptr, OP_ADD_Gv_Ev + 8 * opindex, OP_32BIT, sreg, base, index, scale, disp);
2392}
2393
2394
2395/*------------------------------------------------------------------
2396    emit_add_r16_*
2397------------------------------------------------------------------*/
2398
2399#define emit_add_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 0, dreg, imm)
2400#define emit_add_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 0, base, index, scale, disp, imm)
2401#define emit_add_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 0, dreg, sreg)
2402#define emit_add_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 0, dreg, base, index, scale, disp)
2403#define emit_add_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 0, base, index, scale, disp, sreg)
2404
2405#define emit_add_m16abs_imm(e, addr, imm)                  emit_add_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2406#define emit_add_m16bd_imm(e, base, disp, imm)               emit_add_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2407#define emit_add_m16isd_imm(e, index, scale, disp, imm)         emit_add_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2408
2409#define emit_add_r16_m16abs(e, dreg, addr)                  emit_add_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2410#define emit_add_r16_m16bd(e, dreg, base, disp)               emit_add_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2411#define emit_add_r16_m16isd(e, dreg, index, scale, disp)      emit_add_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2412
2413#define emit_add_m16abs_r16(e, addr, sreg)                  emit_add_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2414#define emit_add_m16bd_r16(e, base, disp, sreg)               emit_add_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2415#define emit_add_m16isd_r16(e, index, scale, disp, sreg)      emit_add_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2416
2417
2418/*------------------------------------------------------------------
2419    emit_or_r16_*
2420------------------------------------------------------------------*/
2421
2422#define emit_or_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 1, dreg, imm)
2423#define emit_or_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 1, base, index, scale, disp, imm)
2424#define emit_or_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 1, dreg, sreg)
2425#define emit_or_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 1, dreg, base, index, scale, disp)
2426#define emit_or_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 1, base, index, scale, disp, sreg)
2427
2428#define emit_or_m16abs_imm(e, addr, imm)                  emit_or_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2429#define emit_or_m16bd_imm(e, base, disp, imm)               emit_or_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2430#define emit_or_m16isd_imm(e, index, scale, disp, imm)         emit_or_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2431
2432#define emit_or_r16_m16abs(e, dreg, addr)                  emit_or_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2433#define emit_or_r16_m16bd(e, dreg, base, disp)               emit_or_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2434#define emit_or_r16_m16isd(e, dreg, index, scale, disp)         emit_or_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2435
2436#define emit_or_m16abs_r16(e, addr, sreg)                  emit_or_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2437#define emit_or_m16bd_r16(e, base, disp, sreg)               emit_or_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2438#define emit_or_m16isd_r16(e, index, scale, disp, sreg)         emit_or_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2439
2440
2441/*------------------------------------------------------------------
2442    emit_adc_r16_*
2443------------------------------------------------------------------*/
2444
2445#define emit_adc_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 2, dreg, imm)
2446#define emit_adc_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 2, base, index, scale, disp, imm)
2447#define emit_adc_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 2, dreg, sreg)
2448#define emit_adc_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 2, dreg, base, index, scale, disp)
2449#define emit_adc_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 2, base, index, scale, disp, sreg)
2450
2451#define emit_adc_m16abs_imm(e, addr, imm)                  emit_adc_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2452#define emit_adc_m16bd_imm(e, base, disp, imm)               emit_adc_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2453#define emit_adc_m16isd_imm(e, index, scale, disp, imm)         emit_adc_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2454
2455#define emit_adc_r16_m16abs(e, dreg, addr)                  emit_adc_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2456#define emit_adc_r16_m16bd(e, dreg, base, disp)               emit_adc_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2457#define emit_adc_r16_m16isd(e, dreg, index, scale, disp)      emit_adc_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2458
2459#define emit_adc_m16abs_r16(e, addr, sreg)                  emit_adc_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2460#define emit_adc_m16bd_r16(e, base, disp, sreg)               emit_adc_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2461#define emit_adc_m16isd_r16(e, index, scale, disp, sreg)      emit_adc_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2462
2463
2464/*------------------------------------------------------------------
2465    emit_sbb_r16_*
2466------------------------------------------------------------------*/
2467
2468#define emit_sbb_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 3, dreg, imm)
2469#define emit_sbb_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 3, base, index, scale, disp, imm)
2470#define emit_sbb_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 3, dreg, sreg)
2471#define emit_sbb_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 3, dreg, base, index, scale, disp)
2472#define emit_sbb_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 3, base, index, scale, disp, sreg)
2473
2474#define emit_sbb_m16abs_imm(e, addr, imm)                  emit_sbb_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2475#define emit_sbb_m16bd_imm(e, base, disp, imm)               emit_sbb_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2476#define emit_sbb_m16isd_imm(e, index, scale, disp, imm)         emit_sbb_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2477
2478#define emit_sbb_r16_m16abs(e, dreg, addr)                  emit_sbb_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2479#define emit_sbb_r16_m16bd(e, dreg, base, disp)               emit_sbb_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2480#define emit_sbb_r16_m16isd(e, dreg, index, scale, disp)      emit_sbb_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2481
2482#define emit_sbb_m16abs_r16(e, addr, sreg)                  emit_sbb_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2483#define emit_sbb_m16bd_r16(e, base, disp, sreg)               emit_sbb_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2484#define emit_sbb_m16isd_r16(e, index, scale, disp, sreg)      emit_sbb_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2485
2486
2487/*------------------------------------------------------------------
2488    emit_and_r16_*
2489------------------------------------------------------------------*/
2490
2491#define emit_and_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 4, dreg, imm)
2492#define emit_and_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 4, base, index, scale, disp, imm)
2493#define emit_and_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 4, dreg, sreg)
2494#define emit_and_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 4, dreg, base, index, scale, disp)
2495#define emit_and_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 4, base, index, scale, disp, sreg)
2496
2497#define emit_and_m16abs_imm(e, addr, imm)                  emit_and_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2498#define emit_and_m16bd_imm(e, base, disp, imm)               emit_and_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2499#define emit_and_m16isd_imm(e, index, scale, disp, imm)         emit_and_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2500
2501#define emit_and_r16_m16abs(e, dreg, addr)                  emit_and_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2502#define emit_and_r16_m16bd(e, dreg, base, disp)               emit_and_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2503#define emit_and_r16_m16isd(e, dreg, index, scale, disp)      emit_and_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2504
2505#define emit_and_m16abs_r16(e, addr, sreg)                  emit_and_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2506#define emit_and_m16bd_r16(e, base, disp, sreg)               emit_and_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2507#define emit_and_m16isd_r16(e, index, scale, disp, sreg)      emit_and_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2508
2509
2510/*------------------------------------------------------------------
2511    emit_sub_r16_*
2512------------------------------------------------------------------*/
2513
2514#define emit_sub_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 5, dreg, imm)
2515#define emit_sub_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 5, base, index, scale, disp, imm)
2516#define emit_sub_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 5, dreg, sreg)
2517#define emit_sub_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 5, dreg, base, index, scale, disp)
2518#define emit_sub_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 5, base, index, scale, disp, sreg)
2519
2520#define emit_sub_m16abs_imm(e, addr, imm)                  emit_sub_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2521#define emit_sub_m16bd_imm(e, base, disp, imm)               emit_sub_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2522#define emit_sub_m16isd_imm(e, index, scale, disp, imm)         emit_sub_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2523
2524#define emit_sub_r16_m16abs(e, dreg, addr)                  emit_sub_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2525#define emit_sub_r16_m16bd(e, dreg, base, disp)               emit_sub_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2526#define emit_sub_r16_m16isd(e, dreg, index, scale, disp)      emit_sub_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2527
2528#define emit_sub_m16abs_r16(e, addr, sreg)                  emit_sub_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2529#define emit_sub_m16bd_r16(e, base, disp, sreg)               emit_sub_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2530#define emit_sub_m16isd_r16(e, index, scale, disp, sreg)      emit_sub_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2531
2532
2533/*------------------------------------------------------------------
2534    emit_xor_r16_*
2535------------------------------------------------------------------*/
2536
2537#define emit_xor_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 6, dreg, imm)
2538#define emit_xor_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 6, base, index, scale, disp, imm)
2539#define emit_xor_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 6, dreg, sreg)
2540#define emit_xor_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 6, dreg, base, index, scale, disp)
2541#define emit_xor_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 6, base, index, scale, disp, sreg)
2542
2543#define emit_xor_m16abs_imm(e, addr, imm)                  emit_xor_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2544#define emit_xor_m16bd_imm(e, base, disp, imm)               emit_xor_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2545#define emit_xor_m16isd_imm(e, index, scale, disp, imm)         emit_xor_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2546
2547#define emit_xor_r16_m16abs(e, dreg, addr)                  emit_xor_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2548#define emit_xor_r16_m16bd(e, dreg, base, disp)               emit_xor_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2549#define emit_xor_r16_m16isd(e, dreg, index, scale, disp)      emit_xor_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2550
2551#define emit_xor_m16abs_r16(e, addr, sreg)                  emit_xor_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2552#define emit_xor_m16bd_r16(e, base, disp, sreg)               emit_xor_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2553#define emit_xor_m16isd_r16(e, index, scale, disp, sreg)      emit_xor_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2554
2555
2556/*------------------------------------------------------------------
2557    emit_cmp_r16_*
2558------------------------------------------------------------------*/
2559
2560#define emit_cmp_r16_imm(e, dreg, imm)                     emit_arith_r16_imm(e, 7, dreg, imm)
2561#define emit_cmp_m16bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m16bisd_imm(e, 7, base, index, scale, disp, imm)
2562#define emit_cmp_r16_r16(e, dreg, sreg)                     emit_arith_r16_r16(e, 7, dreg, sreg)
2563#define emit_cmp_r16_m16bisd(e, dreg, base, index, scale, disp)   emit_arith_r16_m16bisd(e, 7, dreg, base, index, scale, disp)
2564#define emit_cmp_m16bisd_r16(e, base, index, scale, disp, sreg)   emit_arith_m16bisd_r16(e, 7, base, index, scale, disp, sreg)
2565
2566#define emit_cmp_m16abs_imm(e, addr, imm)                  emit_cmp_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2567#define emit_cmp_m16bd_imm(e, base, disp, imm)               emit_cmp_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2568#define emit_cmp_m16isd_imm(e, index, scale, disp, imm)         emit_cmp_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2569
2570#define emit_cmp_r16_m16abs(e, dreg, addr)                  emit_cmp_r16_m16bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2571#define emit_cmp_r16_m16bd(e, dreg, base, disp)               emit_cmp_r16_m16bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2572#define emit_cmp_r16_m16isd(e, dreg, index, scale, disp)      emit_cmp_r16_m16bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2573
2574#define emit_cmp_m16abs_r16(e, addr, sreg)                  emit_cmp_m16bisd_r16(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2575#define emit_cmp_m16bd_r16(e, base, disp, sreg)               emit_cmp_m16bisd_r16(e, (base),   REG_NONE, 1,       (disp), sreg)
2576#define emit_cmp_m16isd_r16(e, index, scale, disp, sreg)      emit_cmp_m16bisd_r16(e, REG_NONE, (index),  (scale), (disp), sreg)
2577
2578
2579
2580/***************************************************************************
2581    32-BIT ARITHMETIC EMITTERS
2582***************************************************************************/
2583
2584/*
2585    Note that the following code relies on this:
2586
2587        00-05 or /0 = ADD
2588        08-0d or /1 = OR
2589        10-15 or /2 = ADC
2590        18-1d or /3 = SBB
2591        20-25 or /4 = AND
2592        28-2d or /5 = SUB
2593        30-35 or /6 = XOR
2594        38-3d or /7 = CMP
2595*/
2596
2597INLINE void emit_arith_r32_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT32 imm)
2598{
2599   if ((INT8)imm == (INT32)imm)
2600   {
2601      emit_op_modrm_reg(emitptr, OP_G1_Ev_Ib, OP_32BIT, opindex, dreg);
2602      emit_byte(emitptr, (INT8)imm);
2603   }
2604   else
2605   {
2606      emit_op_modrm_reg(emitptr, OP_G1_Ev_Iz, OP_32BIT, opindex, dreg);
2607      emit_dword(emitptr, imm);
2608   }
2609}
2610
2611INLINE void emit_arith_m32bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT32 imm)
2612{
2613   if ((INT8)imm == (INT32)imm)
2614   {
2615      emit_op_modrm_mem(emitptr, OP_G1_Ev_Ib, OP_32BIT, opindex, base, index, scale, disp);
2616      emit_byte(emitptr, (INT8)imm);
2617   }
2618   else
2619   {
2620      emit_op_modrm_mem(emitptr, OP_G1_Ev_Iz, OP_32BIT, opindex, base, index, scale, disp);
2621      emit_dword(emitptr, imm);
2622   }
2623}
2624
2625INLINE void emit_arith_r32_r32(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 sreg)
2626{
2627   emit_op_modrm_reg(emitptr, OP_ADD_Gv_Ev + 8 * opindex, OP_32BIT, dreg, sreg);
2628}
2629
2630INLINE void emit_arith_r32_m32bisd(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
2631{
2632   emit_op_modrm_mem(emitptr, OP_ADD_Gv_Ev + 8 * opindex, OP_32BIT, dreg, base, index, scale, disp);
2633}
2634
2635INLINE void emit_arith_m32bisd_r32(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2636{
2637   emit_op_modrm_mem(emitptr, OP_ADD_Ev_Gv + 8 * opindex, OP_32BIT, sreg, base, index, scale, disp);
2638}
2639
2640
2641/*------------------------------------------------------------------
2642    emit_add_r32_*
2643------------------------------------------------------------------*/
2644
2645#define emit_add_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 0, dreg, imm)
2646#define emit_add_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 0, base, index, scale, disp, imm)
2647#define emit_add_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 0, dreg, sreg)
2648#define emit_add_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 0, dreg, base, index, scale, disp)
2649#define emit_add_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 0, base, index, scale, disp, sreg)
2650
2651#define emit_add_m32abs_imm(e, addr, imm)                  emit_add_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2652#define emit_add_m32bd_imm(e, base, disp, imm)               emit_add_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2653#define emit_add_m32isd_imm(e, index, scale, disp, imm)         emit_add_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2654
2655#define emit_add_r32_m32abs(e, dreg, addr)                  emit_add_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2656#define emit_add_r32_m32bd(e, dreg, base, disp)               emit_add_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2657#define emit_add_r32_m32isd(e, dreg, index, scale, disp)      emit_add_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2658
2659#define emit_add_m32abs_r32(e, addr, sreg)                  emit_add_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2660#define emit_add_m32bd_r32(e, base, disp, sreg)               emit_add_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2661#define emit_add_m32isd_r32(e, index, scale, disp, sreg)      emit_add_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2662
2663
2664/*------------------------------------------------------------------
2665    emit_or_r32_*
2666------------------------------------------------------------------*/
2667
2668#define emit_or_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 1, dreg, imm)
2669#define emit_or_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 1, base, index, scale, disp, imm)
2670#define emit_or_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 1, dreg, sreg)
2671#define emit_or_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 1, dreg, base, index, scale, disp)
2672#define emit_or_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 1, base, index, scale, disp, sreg)
2673
2674#define emit_or_m32abs_imm(e, addr, imm)                  emit_or_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2675#define emit_or_m32bd_imm(e, base, disp, imm)               emit_or_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2676#define emit_or_m32isd_imm(e, index, scale, disp, imm)         emit_or_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2677
2678#define emit_or_r32_m32abs(e, dreg, addr)                  emit_or_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2679#define emit_or_r32_m32bd(e, dreg, base, disp)               emit_or_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2680#define emit_or_r32_m32isd(e, dreg, index, scale, disp)         emit_or_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2681
2682#define emit_or_m32abs_r32(e, addr, sreg)                  emit_or_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2683#define emit_or_m32bd_r32(e, base, disp, sreg)               emit_or_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2684#define emit_or_m32isd_r32(e, index, scale, disp, sreg)         emit_or_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2685
2686
2687/*------------------------------------------------------------------
2688    emit_adc_r32_*
2689------------------------------------------------------------------*/
2690
2691#define emit_adc_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 2, dreg, imm)
2692#define emit_adc_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 2, base, index, scale, disp, imm)
2693#define emit_adc_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 2, dreg, sreg)
2694#define emit_adc_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 2, dreg, base, index, scale, disp)
2695#define emit_adc_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 2, base, index, scale, disp, sreg)
2696
2697#define emit_adc_m32abs_imm(e, addr, imm)                  emit_adc_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2698#define emit_adc_m32bd_imm(e, base, disp, imm)               emit_adc_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2699#define emit_adc_m32isd_imm(e, index, scale, disp, imm)         emit_adc_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2700
2701#define emit_adc_r32_m32abs(e, dreg, addr)                  emit_adc_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2702#define emit_adc_r32_m32bd(e, dreg, base, disp)               emit_adc_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2703#define emit_adc_r32_m32isd(e, dreg, index, scale, disp)      emit_adc_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2704
2705#define emit_adc_m32abs_r32(e, addr, sreg)                  emit_adc_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2706#define emit_adc_m32bd_r32(e, base, disp, sreg)               emit_adc_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2707#define emit_adc_m32isd_r32(e, index, scale, disp, sreg)      emit_adc_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2708
2709
2710/*------------------------------------------------------------------
2711    emit_sbb_r32_*
2712------------------------------------------------------------------*/
2713
2714#define emit_sbb_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 3, dreg, imm)
2715#define emit_sbb_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 3, base, index, scale, disp, imm)
2716#define emit_sbb_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 3, dreg, sreg)
2717#define emit_sbb_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 3, dreg, base, index, scale, disp)
2718#define emit_sbb_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 3, base, index, scale, disp, sreg)
2719
2720#define emit_sbb_m32abs_imm(e, addr, imm)                  emit_sbb_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2721#define emit_sbb_m32bd_imm(e, base, disp, imm)               emit_sbb_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2722#define emit_sbb_m32isd_imm(e, index, scale, disp, imm)         emit_sbb_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2723
2724#define emit_sbb_r32_m32abs(e, dreg, addr)                  emit_sbb_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2725#define emit_sbb_r32_m32bd(e, dreg, base, disp)               emit_sbb_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2726#define emit_sbb_r32_m32isd(e, dreg, index, scale, disp)      emit_sbb_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2727
2728#define emit_sbb_m32abs_r32(e, addr, sreg)                  emit_sbb_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2729#define emit_sbb_m32bd_r32(e, base, disp, sreg)               emit_sbb_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2730#define emit_sbb_m32isd_r32(e, index, scale, disp, sreg)      emit_sbb_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2731
2732
2733/*------------------------------------------------------------------
2734    emit_and_r32_*
2735------------------------------------------------------------------*/
2736
2737#define emit_and_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 4, dreg, imm)
2738#define emit_and_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 4, base, index, scale, disp, imm)
2739#define emit_and_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 4, dreg, sreg)
2740#define emit_and_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 4, dreg, base, index, scale, disp)
2741#define emit_and_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 4, base, index, scale, disp, sreg)
2742
2743#define emit_and_m32abs_imm(e, addr, imm)                  emit_and_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2744#define emit_and_m32bd_imm(e, base, disp, imm)               emit_and_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2745#define emit_and_m32isd_imm(e, index, scale, disp, imm)         emit_and_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2746
2747#define emit_and_r32_m32abs(e, dreg, addr)                  emit_and_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2748#define emit_and_r32_m32bd(e, dreg, base, disp)               emit_and_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2749#define emit_and_r32_m32isd(e, dreg, index, scale, disp)      emit_and_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2750
2751#define emit_and_m32abs_r32(e, addr, sreg)                  emit_and_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2752#define emit_and_m32bd_r32(e, base, disp, sreg)               emit_and_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2753#define emit_and_m32isd_r32(e, index, scale, disp, sreg)      emit_and_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2754
2755
2756/*------------------------------------------------------------------
2757    emit_sub_r32_*
2758------------------------------------------------------------------*/
2759
2760#define emit_sub_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 5, dreg, imm)
2761#define emit_sub_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 5, base, index, scale, disp, imm)
2762#define emit_sub_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 5, dreg, sreg)
2763#define emit_sub_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 5, dreg, base, index, scale, disp)
2764#define emit_sub_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 5, base, index, scale, disp, sreg)
2765
2766#define emit_sub_m32abs_imm(e, addr, imm)                  emit_sub_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2767#define emit_sub_m32bd_imm(e, base, disp, imm)               emit_sub_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2768#define emit_sub_m32isd_imm(e, index, scale, disp, imm)         emit_sub_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2769
2770#define emit_sub_r32_m32abs(e, dreg, addr)                  emit_sub_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2771#define emit_sub_r32_m32bd(e, dreg, base, disp)               emit_sub_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2772#define emit_sub_r32_m32isd(e, dreg, index, scale, disp)      emit_sub_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2773
2774#define emit_sub_m32abs_r32(e, addr, sreg)                  emit_sub_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2775#define emit_sub_m32bd_r32(e, base, disp, sreg)               emit_sub_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2776#define emit_sub_m32isd_r32(e, index, scale, disp, sreg)      emit_sub_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2777
2778
2779/*------------------------------------------------------------------
2780    emit_xor_r32_*
2781------------------------------------------------------------------*/
2782
2783#define emit_xor_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 6, dreg, imm)
2784#define emit_xor_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 6, base, index, scale, disp, imm)
2785#define emit_xor_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 6, dreg, sreg)
2786#define emit_xor_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 6, dreg, base, index, scale, disp)
2787#define emit_xor_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 6, base, index, scale, disp, sreg)
2788
2789#define emit_xor_m32abs_imm(e, addr, imm)                  emit_xor_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2790#define emit_xor_m32bd_imm(e, base, disp, imm)               emit_xor_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2791#define emit_xor_m32isd_imm(e, index, scale, disp, imm)         emit_xor_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2792
2793#define emit_xor_r32_m32abs(e, dreg, addr)                  emit_xor_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2794#define emit_xor_r32_m32bd(e, dreg, base, disp)               emit_xor_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2795#define emit_xor_r32_m32isd(e, dreg, index, scale, disp)      emit_xor_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2796
2797#define emit_xor_m32abs_r32(e, addr, sreg)                  emit_xor_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2798#define emit_xor_m32bd_r32(e, base, disp, sreg)               emit_xor_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2799#define emit_xor_m32isd_r32(e, index, scale, disp, sreg)      emit_xor_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2800
2801
2802/*------------------------------------------------------------------
2803    emit_cmp_r32_*
2804------------------------------------------------------------------*/
2805
2806#define emit_cmp_r32_imm(e, dreg, imm)                     emit_arith_r32_imm(e, 7, dreg, imm)
2807#define emit_cmp_m32bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m32bisd_imm(e, 7, base, index, scale, disp, imm)
2808#define emit_cmp_r32_r32(e, dreg, sreg)                     emit_arith_r32_r32(e, 7, dreg, sreg)
2809#define emit_cmp_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_arith_r32_m32bisd(e, 7, dreg, base, index, scale, disp)
2810#define emit_cmp_m32bisd_r32(e, base, index, scale, disp, sreg)   emit_arith_m32bisd_r32(e, 7, base, index, scale, disp, sreg)
2811
2812#define emit_cmp_m32abs_imm(e, addr, imm)                  emit_cmp_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2813#define emit_cmp_m32bd_imm(e, base, disp, imm)               emit_cmp_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2814#define emit_cmp_m32isd_imm(e, index, scale, disp, imm)         emit_cmp_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2815
2816#define emit_cmp_r32_m32abs(e, dreg, addr)                  emit_cmp_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2817#define emit_cmp_r32_m32bd(e, dreg, base, disp)               emit_cmp_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2818#define emit_cmp_r32_m32isd(e, dreg, index, scale, disp)      emit_cmp_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2819
2820#define emit_cmp_m32abs_r32(e, addr, sreg)                  emit_cmp_m32bisd_r32(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2821#define emit_cmp_m32bd_r32(e, base, disp, sreg)               emit_cmp_m32bisd_r32(e, (base),   REG_NONE, 1,       (disp), sreg)
2822#define emit_cmp_m32isd_r32(e, index, scale, disp, sreg)      emit_cmp_m32bisd_r32(e, REG_NONE, (index),  (scale), (disp), sreg)
2823
2824
2825
2826/***************************************************************************
2827    64-BIT ARITHMETIC EMITTERS
2828***************************************************************************/
2829
2830#ifdef PTR64
2831/*
2832    Note that the following code relies on this:
2833
2834        00-05 or /0 = ADD
2835        08-0d or /1 = OR
2836        10-15 or /2 = ADC
2837        18-1d or /3 = SBB
2838        20-25 or /4 = AND
2839        28-2d or /5 = SUB
2840        30-35 or /6 = XOR
2841        38-3d or /7 = CMP
2842*/
2843
2844INLINE void emit_arith_r64_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT32 imm)
2845{
2846   if ((INT8)imm == (INT32)imm)
2847   {
2848      emit_op_modrm_reg(emitptr, OP_G1_Ev_Ib, OP_64BIT, opindex, dreg);
2849      emit_byte(emitptr, (INT8)imm);
2850   }
2851   else
2852   {
2853      emit_op_modrm_reg(emitptr, OP_G1_Ev_Iz, OP_64BIT, opindex, dreg);
2854      emit_dword(emitptr, imm);
2855   }
2856}
2857
2858INLINE void emit_arith_m64bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT32 imm)
2859{
2860   if ((INT8)imm == (INT32)imm)
2861   {
2862      emit_op_modrm_mem(emitptr, OP_G1_Ev_Ib, OP_64BIT, opindex, base, index, scale, disp);
2863      emit_byte(emitptr, (INT8)imm);
2864   }
2865   else
2866   {
2867      emit_op_modrm_mem(emitptr, OP_G1_Ev_Iz, OP_64BIT, opindex, base, index, scale, disp);
2868      emit_dword(emitptr, imm);
2869   }
2870}
2871
2872INLINE void emit_arith_r64_r64(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 sreg)
2873{
2874   emit_op_modrm_reg(emitptr, OP_ADD_Gv_Ev + 8 * opindex, OP_64BIT, dreg, sreg);
2875}
2876
2877INLINE void emit_arith_r64_m64bisd(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
2878{
2879   emit_op_modrm_mem(emitptr, OP_ADD_Gv_Ev + 8 * opindex, OP_64BIT, dreg, base, index, scale, disp);
2880}
2881
2882INLINE void emit_arith_m64bisd_r64(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 sreg)
2883{
2884   emit_op_modrm_mem(emitptr, OP_ADD_Ev_Gv + 8 * opindex, OP_64BIT, sreg, base, index, scale, disp);
2885}
2886
2887
2888/*------------------------------------------------------------------
2889    emit_add_r64_*
2890------------------------------------------------------------------*/
2891
2892#define emit_add_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 0, dreg, imm)
2893#define emit_add_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 0, base, index, scale, disp, imm)
2894#define emit_add_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 0, dreg, sreg)
2895#define emit_add_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 0, dreg, base, index, scale, disp)
2896#define emit_add_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 0, base, index, scale, disp, sreg)
2897
2898#define emit_add_m64abs_imm(e, addr, imm)                  emit_add_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2899#define emit_add_m64bd_imm(e, base, disp, imm)               emit_add_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2900#define emit_add_m64isd_imm(e, index, scale, disp, imm)         emit_add_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2901
2902#define emit_add_r64_m64abs(e, dreg, addr)                  emit_add_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2903#define emit_add_r64_m64bd(e, dreg, base, disp)               emit_add_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2904#define emit_add_r64_m64isd(e, dreg, index, scale, disp)      emit_add_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2905
2906#define emit_add_m64abs_r64(e, addr, sreg)                  emit_add_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2907#define emit_add_m64bd_r64(e, base, disp, sreg)               emit_add_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
2908#define emit_add_m64isd_r64(e, index, scale, disp, sreg)      emit_add_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
2909
2910
2911/*------------------------------------------------------------------
2912    emit_or_r64_*
2913------------------------------------------------------------------*/
2914
2915#define emit_or_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 1, dreg, imm)
2916#define emit_or_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 1, base, index, scale, disp, imm)
2917#define emit_or_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 1, dreg, sreg)
2918#define emit_or_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 1, dreg, base, index, scale, disp)
2919#define emit_or_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 1, base, index, scale, disp, sreg)
2920
2921#define emit_or_m64abs_imm(e, addr, imm)                  emit_or_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2922#define emit_or_m64bd_imm(e, base, disp, imm)               emit_or_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2923#define emit_or_m64isd_imm(e, index, scale, disp, imm)         emit_or_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2924
2925#define emit_or_r64_m64abs(e, dreg, addr)                  emit_or_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2926#define emit_or_r64_m64bd(e, dreg, base, disp)               emit_or_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2927#define emit_or_r64_m64isd(e, dreg, index, scale, disp)         emit_or_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2928
2929#define emit_or_m64abs_r64(e, addr, sreg)                  emit_or_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2930#define emit_or_m64bd_r64(e, base, disp, sreg)               emit_or_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
2931#define emit_or_m64isd_r64(e, index, scale, disp, sreg)         emit_or_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
2932
2933
2934/*------------------------------------------------------------------
2935    emit_adc_r64_*
2936------------------------------------------------------------------*/
2937
2938#define emit_adc_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 2, dreg, imm)
2939#define emit_adc_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 2, base, index, scale, disp, imm)
2940#define emit_adc_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 2, dreg, sreg)
2941#define emit_adc_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 2, dreg, base, index, scale, disp)
2942#define emit_adc_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 2, base, index, scale, disp, sreg)
2943
2944#define emit_adc_m64abs_imm(e, addr, imm)                  emit_adc_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2945#define emit_adc_m64bd_imm(e, base, disp, imm)               emit_adc_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2946#define emit_adc_m64isd_imm(e, index, scale, disp, imm)         emit_adc_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2947
2948#define emit_adc_r64_m64abs(e, dreg, addr)                  emit_adc_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2949#define emit_adc_r64_m64bd(e, dreg, base, disp)               emit_adc_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2950#define emit_adc_r64_m64isd(e, dreg, index, scale, disp)      emit_adc_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2951
2952#define emit_adc_m64abs_r64(e, addr, sreg)                  emit_adc_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2953#define emit_adc_m64bd_r64(e, base, disp, sreg)               emit_adc_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
2954#define emit_adc_m64isd_r64(e, index, scale, disp, sreg)      emit_adc_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
2955
2956
2957/*------------------------------------------------------------------
2958    emit_sbb_r64_*
2959------------------------------------------------------------------*/
2960
2961#define emit_sbb_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 3, dreg, imm)
2962#define emit_sbb_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 3, base, index, scale, disp, imm)
2963#define emit_sbb_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 3, dreg, sreg)
2964#define emit_sbb_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 3, dreg, base, index, scale, disp)
2965#define emit_sbb_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 3, base, index, scale, disp, sreg)
2966
2967#define emit_sbb_m64abs_imm(e, addr, imm)                  emit_sbb_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2968#define emit_sbb_m64bd_imm(e, base, disp, imm)               emit_sbb_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2969#define emit_sbb_m64isd_imm(e, index, scale, disp, imm)         emit_sbb_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2970
2971#define emit_sbb_r64_m64abs(e, dreg, addr)                  emit_sbb_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2972#define emit_sbb_r64_m64bd(e, dreg, base, disp)               emit_sbb_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2973#define emit_sbb_r64_m64isd(e, dreg, index, scale, disp)      emit_sbb_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2974
2975#define emit_sbb_m64abs_r64(e, addr, sreg)                  emit_sbb_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2976#define emit_sbb_m64bd_r64(e, base, disp, sreg)               emit_sbb_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
2977#define emit_sbb_m64isd_r64(e, index, scale, disp, sreg)      emit_sbb_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
2978
2979
2980/*------------------------------------------------------------------
2981    emit_and_r64_*
2982------------------------------------------------------------------*/
2983
2984#define emit_and_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 4, dreg, imm)
2985#define emit_and_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 4, base, index, scale, disp, imm)
2986#define emit_and_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 4, dreg, sreg)
2987#define emit_and_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 4, dreg, base, index, scale, disp)
2988#define emit_and_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 4, base, index, scale, disp, sreg)
2989
2990#define emit_and_m64abs_imm(e, addr, imm)                  emit_and_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
2991#define emit_and_m64bd_imm(e, base, disp, imm)               emit_and_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
2992#define emit_and_m64isd_imm(e, index, scale, disp, imm)         emit_and_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
2993
2994#define emit_and_r64_m64abs(e, dreg, addr)                  emit_and_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
2995#define emit_and_r64_m64bd(e, dreg, base, disp)               emit_and_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
2996#define emit_and_r64_m64isd(e, dreg, index, scale, disp)      emit_and_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
2997
2998#define emit_and_m64abs_r64(e, addr, sreg)                  emit_and_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
2999#define emit_and_m64bd_r64(e, base, disp, sreg)               emit_and_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
3000#define emit_and_m64isd_r64(e, index, scale, disp, sreg)      emit_and_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
3001
3002
3003/*------------------------------------------------------------------
3004    emit_sub_r64_*
3005------------------------------------------------------------------*/
3006
3007#define emit_sub_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 5, dreg, imm)
3008#define emit_sub_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 5, base, index, scale, disp, imm)
3009#define emit_sub_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 5, dreg, sreg)
3010#define emit_sub_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 5, dreg, base, index, scale, disp)
3011#define emit_sub_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 5, base, index, scale, disp, sreg)
3012
3013#define emit_sub_m64abs_imm(e, addr, imm)                  emit_sub_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3014#define emit_sub_m64bd_imm(e, base, disp, imm)               emit_sub_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3015#define emit_sub_m64isd_imm(e, index, scale, disp, imm)         emit_sub_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3016
3017#define emit_sub_r64_m64abs(e, dreg, addr)                  emit_sub_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3018#define emit_sub_r64_m64bd(e, dreg, base, disp)               emit_sub_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
3019#define emit_sub_r64_m64isd(e, dreg, index, scale, disp)      emit_sub_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
3020
3021#define emit_sub_m64abs_r64(e, addr, sreg)                  emit_sub_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
3022#define emit_sub_m64bd_r64(e, base, disp, sreg)               emit_sub_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
3023#define emit_sub_m64isd_r64(e, index, scale, disp, sreg)      emit_sub_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
3024
3025
3026/*------------------------------------------------------------------
3027    emit_xor_r64_*
3028------------------------------------------------------------------*/
3029
3030#define emit_xor_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 6, dreg, imm)
3031#define emit_xor_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 6, base, index, scale, disp, imm)
3032#define emit_xor_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 6, dreg, sreg)
3033#define emit_xor_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 6, dreg, base, index, scale, disp)
3034#define emit_xor_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 6, base, index, scale, disp, sreg)
3035
3036#define emit_xor_m64abs_imm(e, addr, imm)                  emit_xor_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3037#define emit_xor_m64bd_imm(e, base, disp, imm)               emit_xor_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3038#define emit_xor_m64isd_imm(e, index, scale, disp, imm)         emit_xor_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3039
3040#define emit_xor_r64_m64abs(e, dreg, addr)                  emit_xor_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3041#define emit_xor_r64_m64bd(e, dreg, base, disp)               emit_xor_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
3042#define emit_xor_r64_m64isd(e, dreg, index, scale, disp)      emit_xor_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
3043
3044#define emit_xor_m64abs_r64(e, addr, sreg)                  emit_xor_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
3045#define emit_xor_m64bd_r64(e, base, disp, sreg)               emit_xor_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
3046#define emit_xor_m64isd_r64(e, index, scale, disp, sreg)      emit_xor_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
3047
3048
3049/*------------------------------------------------------------------
3050    emit_cmp_r64_*
3051------------------------------------------------------------------*/
3052
3053#define emit_cmp_r64_imm(e, dreg, imm)                     emit_arith_r64_imm(e, 7, dreg, imm)
3054#define emit_cmp_m64bisd_imm(e, base, index, scale, disp, imm)   emit_arith_m64bisd_imm(e, 7, base, index, scale, disp, imm)
3055#define emit_cmp_r64_r64(e, dreg, sreg)                     emit_arith_r64_r64(e, 7, dreg, sreg)
3056#define emit_cmp_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_arith_r64_m64bisd(e, 7, dreg, base, index, scale, disp)
3057#define emit_cmp_m64bisd_r64(e, base, index, scale, disp, sreg)   emit_arith_m64bisd_r64(e, 7, base, index, scale, disp, sreg)
3058
3059#define emit_cmp_m64abs_imm(e, addr, imm)                  emit_cmp_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3060#define emit_cmp_m64bd_imm(e, base, disp, imm)               emit_cmp_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3061#define emit_cmp_m64isd_imm(e, index, scale, disp, imm)         emit_cmp_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3062
3063#define emit_cmp_r64_m64abs(e, dreg, addr)                  emit_cmp_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3064#define emit_cmp_r64_m64bd(e, dreg, base, disp)               emit_cmp_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
3065#define emit_cmp_r64_m64isd(e, dreg, index, scale, disp)      emit_cmp_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
3066
3067#define emit_cmp_m64abs_r64(e, addr, sreg)                  emit_cmp_m64bisd_r64(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), sreg)
3068#define emit_cmp_m64bd_r64(e, base, disp, sreg)               emit_cmp_m64bisd_r64(e, (base),   REG_NONE, 1,       (disp), sreg)
3069#define emit_cmp_m64isd_r64(e, index, scale, disp, sreg)      emit_cmp_m64bisd_r64(e, REG_NONE, (index),  (scale), (disp), sreg)
3070
3071#endif
3072
3073
3074
3075/***************************************************************************
3076    8-BIT SHIFT EMITTERS
3077***************************************************************************/
3078
3079/*
3080    Note that the following code relies on this:
3081
3082        /0 = ROL
3083        /1 = ROR
3084        /2 = RCL
3085        /3 = RCR
3086        /4 = SHL
3087        /5 = SHR
3088        /7 = SAR
3089*/
3090
3091/*------------------------------------------------------------------
3092    emit_shift_r8_*
3093------------------------------------------------------------------*/
3094
3095INLINE void emit_shift_r8_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 imm)
3096{
3097   if (imm == 1)
3098      emit_op_modrm_reg(emitptr, OP_G2_Eb_1, OP_32BIT, opindex, dreg);
3099   else
3100   {
3101      emit_op_modrm_reg(emitptr, OP_G2_Eb_Ib, OP_32BIT, opindex, dreg);
3102      emit_byte(emitptr, imm);
3103   }
3104}
3105
3106INLINE void emit_shift_m8bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
3107{
3108   if (imm == 1)
3109      emit_op_modrm_mem(emitptr, OP_G2_Eb_1, OP_32BIT, opindex, base, index, scale, disp);
3110   else
3111   {
3112      emit_op_modrm_mem(emitptr, OP_G2_Eb_Ib, OP_32BIT, opindex, base, index, scale, disp);
3113      emit_byte(emitptr, imm);
3114   }
3115}
3116
3117INLINE void emit_shift_r8_cl(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3118{
3119   emit_op_modrm_reg(emitptr, OP_G2_Eb_CL, OP_32BIT, opindex, dreg);
3120}
3121
3122INLINE void emit_shift_m8bisd_cl(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3123{
3124   emit_op_modrm_mem(emitptr, OP_G2_Eb_CL, OP_32BIT, opindex, base, index, scale, disp);
3125}
3126
3127
3128/*------------------------------------------------------------------
3129    emit_rol_r8_*
3130------------------------------------------------------------------*/
3131
3132#define emit_rol_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 0, dreg, imm)
3133#define emit_rol_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 0, base, index, scale, disp, imm)
3134#define emit_rol_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 0, dreg)
3135#define emit_rol_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 0, base, index, scale, disp)
3136
3137#define emit_rol_m8abs_imm(e, addr, imm)                  emit_rol_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3138#define emit_rol_m8bd_imm(e, base, disp, imm)               emit_rol_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3139#define emit_rol_m8isd_imm(e, index, scale, disp, imm)         emit_rol_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3140
3141#define emit_rol_m8abs_cl(e, addr)                        emit_rol_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3142#define emit_rol_m8bd_cl(e, base, disp)                     emit_rol_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3143#define emit_rol_m8isd_cl(e, index, scale, disp)            emit_rol_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3144
3145
3146/*------------------------------------------------------------------
3147    emit_ror_r8_*
3148------------------------------------------------------------------*/
3149
3150#define emit_ror_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 1, dreg, imm)
3151#define emit_ror_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 1, base, index, scale, disp, imm)
3152#define emit_ror_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 1, dreg)
3153#define emit_ror_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 1, base, index, scale, disp)
3154
3155#define emit_ror_m8abs_imm(e, addr, imm)                  emit_ror_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3156#define emit_ror_m8bd_imm(e, base, disp, imm)               emit_ror_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3157#define emit_ror_m8isd_imm(e, index, scale, disp, imm)         emit_ror_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3158
3159#define emit_ror_m8abs_cl(e, addr)                        emit_ror_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3160#define emit_ror_m8bd_cl(e, base, disp)                     emit_ror_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3161#define emit_ror_m8isd_cl(e, index, scale, disp)            emit_ror_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3162
3163
3164/*------------------------------------------------------------------
3165    emit_rcl_r8_*
3166------------------------------------------------------------------*/
3167
3168#define emit_rcl_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 2, dreg, imm)
3169#define emit_rcl_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 2, base, index, scale, disp, imm)
3170#define emit_rcl_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 2, dreg)
3171#define emit_rcl_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 2, base, index, scale, disp)
3172
3173#define emit_rcl_m8abs_imm(e, addr, imm)                  emit_rcl_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3174#define emit_rcl_m8bd_imm(e, base, disp, imm)               emit_rcl_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3175#define emit_rcl_m8isd_imm(e, index, scale, disp, imm)         emit_rcl_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3176
3177#define emit_rcl_m8abs_cl(e, addr)                        emit_rcl_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3178#define emit_rcl_m8bd_cl(e, base, disp)                     emit_rcl_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3179#define emit_rcl_m8isd_cl(e, index, scale, disp)            emit_rcl_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3180
3181
3182/*------------------------------------------------------------------
3183    emit_rcr_r8_*
3184------------------------------------------------------------------*/
3185
3186#define emit_rcr_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 3, dreg, imm)
3187#define emit_rcr_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 3, base, index, scale, disp, imm)
3188#define emit_rcr_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 3, dreg)
3189#define emit_rcr_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 3, base, index, scale, disp)
3190
3191#define emit_rcr_m8abs_imm(e, addr, imm)                  emit_rcr_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3192#define emit_rcr_m8bd_imm(e, base, disp, imm)               emit_rcr_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3193#define emit_rcr_m8isd_imm(e, index, scale, disp, imm)         emit_rcr_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3194
3195#define emit_rcr_m8abs_cl(e, addr)                        emit_rcr_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3196#define emit_rcr_m8bd_cl(e, base, disp)                     emit_rcr_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3197#define emit_rcr_m8isd_cl(e, index, scale, disp)            emit_rcr_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3198
3199
3200/*------------------------------------------------------------------
3201    emit_shl_r8_*
3202------------------------------------------------------------------*/
3203
3204#define emit_shl_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 4, dreg, imm)
3205#define emit_shl_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 4, base, index, scale, disp, imm)
3206#define emit_shl_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 4, dreg)
3207#define emit_shl_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 4, base, index, scale, disp)
3208
3209#define emit_shl_m8abs_imm(e, addr, imm)                  emit_shl_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3210#define emit_shl_m8bd_imm(e, base, disp, imm)               emit_shl_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3211#define emit_shl_m8isd_imm(e, index, scale, disp, imm)         emit_shl_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3212
3213#define emit_shl_m8abs_cl(e, addr)                        emit_shl_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3214#define emit_shl_m8bd_cl(e, base, disp)                     emit_shl_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3215#define emit_shl_m8isd_cl(e, index, scale, disp)            emit_shl_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3216
3217
3218/*------------------------------------------------------------------
3219    emit_shr_r8_*
3220------------------------------------------------------------------*/
3221
3222#define emit_shr_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 5, dreg, imm)
3223#define emit_shr_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 5, base, index, scale, disp, imm)
3224#define emit_shr_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 5, dreg)
3225#define emit_shr_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 5, base, index, scale, disp)
3226
3227#define emit_shr_m8abs_imm(e, addr, imm)                  emit_shr_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3228#define emit_shr_m8bd_imm(e, base, disp, imm)               emit_shr_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3229#define emit_shr_m8isd_imm(e, index, scale, disp, imm)         emit_shr_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3230
3231#define emit_shr_m8abs_cl(e, addr)                        emit_shr_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3232#define emit_shr_m8bd_cl(e, base, disp)                     emit_shr_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3233#define emit_shr_m8isd_cl(e, index, scale, disp)            emit_shr_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3234
3235
3236/*------------------------------------------------------------------
3237    emit_sar_r8_*
3238------------------------------------------------------------------*/
3239
3240#define emit_sar_r8_imm(e, dreg, imm)                     emit_shift_r8_imm(e, 7, dreg, imm)
3241#define emit_sar_m8bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m8bisd_imm(e, 7, base, index, scale, disp, imm)
3242#define emit_sar_r8_cl(e, dreg)                           emit_shift_r8_cl(e, 7, dreg)
3243#define emit_sar_m8bisd_cl(e, base, index, scale, disp)         emit_shift_m8bisd_cl(e, 7, base, index, scale, disp)
3244
3245#define emit_sar_m8abs_imm(e, addr, imm)                  emit_sar_m8bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3246#define emit_sar_m8bd_imm(e, base, disp, imm)               emit_sar_m8bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3247#define emit_sar_m8isd_imm(e, index, scale, disp, imm)         emit_sar_m8bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3248
3249#define emit_sar_m8abs_cl(e, addr)                        emit_sar_m8bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3250#define emit_sar_m8bd_cl(e, base, disp)                     emit_sar_m8bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3251#define emit_sar_m8isd_cl(e, index, scale, disp)            emit_sar_m8bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3252
3253
3254
3255/***************************************************************************
3256    16-BIT SHIFT EMITTERS
3257***************************************************************************/
3258
3259/*
3260    Note that the following code relies on this:
3261
3262        /0 = ROL
3263        /1 = ROR
3264        /2 = RCL
3265        /3 = RCR
3266        /4 = SHL
3267        /5 = SHR
3268        /7 = SAR
3269*/
3270
3271/*------------------------------------------------------------------
3272    emit_shift_r16_*
3273------------------------------------------------------------------*/
3274
3275INLINE void emit_shift_r16_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 imm)
3276{
3277   emit_byte(emitptr, PREFIX_OPSIZE);
3278   if (imm == 1)
3279      emit_op_modrm_reg(emitptr, OP_G2_Ev_1, OP_32BIT, opindex, dreg);
3280   else
3281   {
3282      emit_op_modrm_reg(emitptr, OP_G2_Ev_Ib, OP_32BIT, opindex, dreg);
3283      emit_byte(emitptr, imm);
3284   }
3285}
3286
3287INLINE void emit_shift_m16bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
3288{
3289   emit_byte(emitptr, PREFIX_OPSIZE);
3290   if (imm == 1)
3291      emit_op_modrm_mem(emitptr, OP_G2_Ev_1, OP_32BIT, opindex, base, index, scale, disp);
3292   else
3293   {
3294      emit_op_modrm_mem(emitptr, OP_G2_Ev_Ib, OP_32BIT, opindex, base, index, scale, disp);
3295      emit_byte(emitptr, imm);
3296   }
3297}
3298
3299INLINE void emit_shift_r16_cl(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3300{
3301   emit_byte(emitptr, PREFIX_OPSIZE);
3302   emit_op_modrm_reg(emitptr, OP_G2_Ev_CL, OP_32BIT, opindex, dreg);
3303}
3304
3305INLINE void emit_shift_m16bisd_cl(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3306{
3307   emit_byte(emitptr, PREFIX_OPSIZE);
3308   emit_op_modrm_mem(emitptr, OP_G2_Ev_CL, OP_32BIT, opindex, base, index, scale, disp);
3309}
3310
3311
3312/*------------------------------------------------------------------
3313    emit_rol_r16_*
3314------------------------------------------------------------------*/
3315
3316#define emit_rol_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 0, dreg, imm)
3317#define emit_rol_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 0, base, index, scale, disp, imm)
3318#define emit_rol_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 0, dreg)
3319#define emit_rol_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 0, base, index, scale, disp)
3320
3321#define emit_rol_m16abs_imm(e, addr, imm)                  emit_rol_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3322#define emit_rol_m16bd_imm(e, base, disp, imm)               emit_rol_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3323#define emit_rol_m16isd_imm(e, index, scale, disp, imm)         emit_rol_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3324
3325#define emit_rol_m16abs_cl(e, addr)                        emit_rol_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3326#define emit_rol_m16bd_cl(e, base, disp)                  emit_rol_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3327#define emit_rol_m16isd_cl(e, index, scale, disp)            emit_rol_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3328
3329
3330/*------------------------------------------------------------------
3331    emit_ror_r16_*
3332------------------------------------------------------------------*/
3333
3334#define emit_ror_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 1, dreg, imm)
3335#define emit_ror_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 1, base, index, scale, disp, imm)
3336#define emit_ror_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 1, dreg)
3337#define emit_ror_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 1, base, index, scale, disp)
3338
3339#define emit_ror_m16abs_imm(e, addr, imm)                  emit_ror_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3340#define emit_ror_m16bd_imm(e, base, disp, imm)               emit_ror_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3341#define emit_ror_m16isd_imm(e, index, scale, disp, imm)         emit_ror_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3342
3343#define emit_ror_m16abs_cl(e, addr)                        emit_ror_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3344#define emit_ror_m16bd_cl(e, base, disp)                  emit_ror_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3345#define emit_ror_m16isd_cl(e, index, scale, disp)            emit_ror_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3346
3347
3348/*------------------------------------------------------------------
3349    emit_rcl_r16_*
3350------------------------------------------------------------------*/
3351
3352#define emit_rcl_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 2, dreg, imm)
3353#define emit_rcl_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 2, base, index, scale, disp, imm)
3354#define emit_rcl_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 2, dreg)
3355#define emit_rcl_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 2, base, index, scale, disp)
3356
3357#define emit_rcl_m16abs_imm(e, addr, imm)                  emit_rcl_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3358#define emit_rcl_m16bd_imm(e, base, disp, imm)               emit_rcl_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3359#define emit_rcl_m16isd_imm(e, index, scale, disp, imm)         emit_rcl_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3360
3361#define emit_rcl_m16abs_cl(e, addr)                        emit_rcl_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3362#define emit_rcl_m16bd_cl(e, base, disp)                  emit_rcl_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3363#define emit_rcl_m16isd_cl(e, index, scale, disp)            emit_rcl_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3364
3365
3366/*------------------------------------------------------------------
3367    emit_rcr_r16_*
3368------------------------------------------------------------------*/
3369
3370#define emit_rcr_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 3, dreg, imm)
3371#define emit_rcr_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 31, base, index, scale, disp, imm)
3372#define emit_rcr_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 3, dreg)
3373#define emit_rcr_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 3, base, index, scale, disp)
3374
3375#define emit_rcr_m16abs_imm(e, addr, imm)                  emit_rcr_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3376#define emit_rcr_m16bd_imm(e, base, disp, imm)               emit_rcr_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3377#define emit_rcr_m16isd_imm(e, index, scale, disp, imm)         emit_rcr_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3378
3379#define emit_rcr_m16abs_cl(e, addr)                        emit_rcr_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3380#define emit_rcr_m16bd_cl(e, base, disp)                  emit_rcr_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3381#define emit_rcr_m16isd_cl(e, index, scale, disp)            emit_rcr_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3382
3383
3384/*------------------------------------------------------------------
3385    emit_shl_r16_*
3386------------------------------------------------------------------*/
3387
3388#define emit_shl_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 4, dreg, imm)
3389#define emit_shl_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 4, base, index, scale, disp, imm)
3390#define emit_shl_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 4, dreg)
3391#define emit_shl_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 4, base, index, scale, disp)
3392
3393#define emit_shl_m16abs_imm(e, addr, imm)                  emit_shl_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3394#define emit_shl_m16bd_imm(e, base, disp, imm)               emit_shl_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3395#define emit_shl_m16isd_imm(e, index, scale, disp, imm)         emit_shl_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3396
3397#define emit_shl_m16abs_cl(e, addr)                        emit_shl_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3398#define emit_shl_m16bd_cl(e, base, disp)                  emit_shl_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3399#define emit_shl_m16isd_cl(e, index, scale, disp)            emit_shl_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3400
3401
3402/*------------------------------------------------------------------
3403    emit_shr_r16_*
3404------------------------------------------------------------------*/
3405
3406#define emit_shr_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 5, dreg, imm)
3407#define emit_shr_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 5, base, index, scale, disp, imm)
3408#define emit_shr_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 5, dreg)
3409#define emit_shr_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 5, base, index, scale, disp)
3410
3411#define emit_shr_m16abs_imm(e, addr, imm)                  emit_shr_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3412#define emit_shr_m16bd_imm(e, base, disp, imm)               emit_shr_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3413#define emit_shr_m16isd_imm(e, index, scale, disp, imm)         emit_shr_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3414
3415#define emit_shr_m16abs_cl(e, addr)                        emit_shr_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3416#define emit_shr_m16bd_cl(e, base, disp)                  emit_shr_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3417#define emit_shr_m16isd_cl(e, index, scale, disp)            emit_shr_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3418
3419
3420/*------------------------------------------------------------------
3421    emit_sar_r16_*
3422------------------------------------------------------------------*/
3423
3424#define emit_sar_r16_imm(e, dreg, imm)                     emit_shift_r16_imm(e, 7, dreg, imm)
3425#define emit_sar_m16bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m16bisd_imm(e, 7, base, index, scale, disp, imm)
3426#define emit_sar_r16_cl(e, dreg)                        emit_shift_r16_cl(e, 7, dreg)
3427#define emit_sar_m16bisd_cl(e, base, index, scale, disp)      emit_shift_m16bisd_cl(e, 7, base, index, scale, disp)
3428
3429#define emit_sar_m16abs_imm(e, addr, imm)                  emit_sar_m16bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3430#define emit_sar_m16bd_imm(e, base, disp, imm)               emit_sar_m16bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3431#define emit_sar_m16isd_imm(e, index, scale, disp, imm)         emit_sar_m16bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3432
3433#define emit_sar_m16abs_cl(e, addr)                        emit_sar_m16bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3434#define emit_sar_m16bd_cl(e, base, disp)                  emit_sar_m16bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3435#define emit_sar_m16isd_cl(e, index, scale, disp)            emit_sar_m16bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3436
3437
3438
3439/***************************************************************************
3440    32-BIT SHIFT EMITTERS
3441***************************************************************************/
3442
3443/*
3444    Note that the following code relies on this:
3445
3446        /0 = ROL
3447        /1 = ROR
3448        /2 = RCL
3449        /3 = RCR
3450        /4 = SHL
3451        /5 = SHR
3452        /7 = SAR
3453*/
3454
3455/*------------------------------------------------------------------
3456    emit_shift_r32_*
3457------------------------------------------------------------------*/
3458
3459INLINE void emit_shift_r32_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 imm)
3460{
3461   if (imm == 1)
3462      emit_op_modrm_reg(emitptr, OP_G2_Ev_1, OP_32BIT, opindex, dreg);
3463   else
3464   {
3465      emit_op_modrm_reg(emitptr, OP_G2_Ev_Ib, OP_32BIT, opindex, dreg);
3466      emit_byte(emitptr, imm);
3467   }
3468}
3469
3470INLINE void emit_shift_m32bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
3471{
3472   if (imm == 1)
3473      emit_op_modrm_mem(emitptr, OP_G2_Ev_1, OP_32BIT, opindex, base, index, scale, disp);
3474   else
3475   {
3476      emit_op_modrm_mem(emitptr, OP_G2_Ev_Ib, OP_32BIT, opindex, base, index, scale, disp);
3477      emit_byte(emitptr, imm);
3478   }
3479}
3480
3481INLINE void emit_shift_r32_cl(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3482{
3483   emit_op_modrm_reg(emitptr, OP_G2_Ev_CL, OP_32BIT, opindex, dreg);
3484}
3485
3486INLINE void emit_shift_m32bisd_cl(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3487{
3488   emit_op_modrm_mem(emitptr, OP_G2_Ev_CL, OP_32BIT, opindex, base, index, scale, disp);
3489}
3490
3491
3492/*------------------------------------------------------------------
3493    emit_rol_r32_*
3494------------------------------------------------------------------*/
3495
3496#define emit_rol_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 0, dreg, imm)
3497#define emit_rol_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 0, base, index, scale, disp, imm)
3498#define emit_rol_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 0, dreg)
3499#define emit_rol_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 0, base, index, scale, disp)
3500
3501#define emit_rol_m32abs_imm(e, addr, imm)                  emit_rol_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3502#define emit_rol_m32bd_imm(e, base, disp, imm)               emit_rol_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3503#define emit_rol_m32isd_imm(e, index, scale, disp, imm)         emit_rol_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3504
3505#define emit_rol_m32abs_cl(e, addr)                        emit_rol_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3506#define emit_rol_m32bd_cl(e, base, disp)                  emit_rol_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3507#define emit_rol_m32isd_cl(e, index, scale, disp)            emit_rol_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3508
3509
3510/*------------------------------------------------------------------
3511    emit_ror_r32_*
3512------------------------------------------------------------------*/
3513
3514#define emit_ror_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 1, dreg, imm)
3515#define emit_ror_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 1, base, index, scale, disp, imm)
3516#define emit_ror_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 1, dreg)
3517#define emit_ror_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 1, base, index, scale, disp)
3518
3519#define emit_ror_m32abs_imm(e, addr, imm)                  emit_ror_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3520#define emit_ror_m32bd_imm(e, base, disp, imm)               emit_ror_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3521#define emit_ror_m32isd_imm(e, index, scale, disp, imm)         emit_ror_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3522
3523#define emit_ror_m32abs_cl(e, addr)                        emit_ror_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3524#define emit_ror_m32bd_cl(e, base, disp)                  emit_ror_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3525#define emit_ror_m32isd_cl(e, index, scale, disp)            emit_ror_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3526
3527
3528/*------------------------------------------------------------------
3529    emit_rcl_r32_*
3530------------------------------------------------------------------*/
3531
3532#define emit_rcl_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 2, dreg, imm)
3533#define emit_rcl_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 2, base, index, scale, disp, imm)
3534#define emit_rcl_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 2, dreg)
3535#define emit_rcl_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 2, base, index, scale, disp)
3536
3537#define emit_rcl_m32abs_imm(e, addr, imm)                  emit_rcl_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3538#define emit_rcl_m32bd_imm(e, base, disp, imm)               emit_rcl_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3539#define emit_rcl_m32isd_imm(e, index, scale, disp, imm)         emit_rcl_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3540
3541#define emit_rcl_m32abs_cl(e, addr)                        emit_rcl_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3542#define emit_rcl_m32bd_cl(e, base, disp)                  emit_rcl_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3543#define emit_rcl_m32isd_cl(e, index, scale, disp)            emit_rcl_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3544
3545
3546/*------------------------------------------------------------------
3547    emit_rcr_r32_*
3548------------------------------------------------------------------*/
3549
3550#define emit_rcr_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 3, dreg, imm)
3551#define emit_rcr_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 3, base, index, scale, disp, imm)
3552#define emit_rcr_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 3, dreg)
3553#define emit_rcr_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 3, base, index, scale, disp)
3554
3555#define emit_rcr_m32abs_imm(e, addr, imm)                  emit_rcr_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3556#define emit_rcr_m32bd_imm(e, base, disp, imm)               emit_rcr_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3557#define emit_rcr_m32isd_imm(e, index, scale, disp, imm)         emit_rcr_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3558
3559#define emit_rcr_m32abs_cl(e, addr)                        emit_rcr_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3560#define emit_rcr_m32bd_cl(e, base, disp)                  emit_rcr_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3561#define emit_rcr_m32isd_cl(e, index, scale, disp)            emit_rcr_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3562
3563
3564/*------------------------------------------------------------------
3565    emit_shl_r32_*
3566------------------------------------------------------------------*/
3567
3568#define emit_shl_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 4, dreg, imm)
3569#define emit_shl_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 4, base, index, scale, disp, imm)
3570#define emit_shl_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 4, dreg)
3571#define emit_shl_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 4, base, index, scale, disp)
3572
3573#define emit_shl_m32abs_imm(e, addr, imm)                  emit_shl_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3574#define emit_shl_m32bd_imm(e, base, disp, imm)               emit_shl_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3575#define emit_shl_m32isd_imm(e, index, scale, disp, imm)         emit_shl_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3576
3577#define emit_shl_m32abs_cl(e, addr)                        emit_shl_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3578#define emit_shl_m32bd_cl(e, base, disp)                  emit_shl_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3579#define emit_shl_m32isd_cl(e, index, scale, disp)            emit_shl_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3580
3581
3582/*------------------------------------------------------------------
3583    emit_shr_r32_*
3584------------------------------------------------------------------*/
3585
3586#define emit_shr_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 5, dreg, imm)
3587#define emit_shr_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 5, base, index, scale, disp, imm)
3588#define emit_shr_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 5, dreg)
3589#define emit_shr_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 5, base, index, scale, disp)
3590
3591#define emit_shr_m32abs_imm(e, addr, imm)                  emit_shr_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3592#define emit_shr_m32bd_imm(e, base, disp, imm)               emit_shr_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3593#define emit_shr_m32isd_imm(e, index, scale, disp, imm)         emit_shr_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3594
3595#define emit_shr_m32abs_cl(e, addr)                        emit_shr_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3596#define emit_shr_m32bd_cl(e, base, disp)                  emit_shr_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3597#define emit_shr_m32isd_cl(e, index, scale, disp)            emit_shr_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3598
3599
3600/*------------------------------------------------------------------
3601    emit_sar_r32_*
3602------------------------------------------------------------------*/
3603
3604#define emit_sar_r32_imm(e, dreg, imm)                     emit_shift_r32_imm(e, 7, dreg, imm)
3605#define emit_sar_m32bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m32bisd_imm(e, 7, base, index, scale, disp, imm)
3606#define emit_sar_r32_cl(e, dreg)                        emit_shift_r32_cl(e, 7, dreg)
3607#define emit_sar_m32bisd_cl(e, base, index, scale, disp)      emit_shift_m32bisd_cl(e, 7, base, index, scale, disp)
3608
3609#define emit_sar_m32abs_imm(e, addr, imm)                  emit_sar_m32bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3610#define emit_sar_m32bd_imm(e, base, disp, imm)               emit_sar_m32bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3611#define emit_sar_m32isd_imm(e, index, scale, disp, imm)         emit_sar_m32bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3612
3613#define emit_sar_m32abs_cl(e, addr)                        emit_sar_m32bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3614#define emit_sar_m32bd_cl(e, base, disp)                  emit_sar_m32bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3615#define emit_sar_m32isd_cl(e, index, scale, disp)            emit_sar_m32bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3616
3617
3618
3619/***************************************************************************
3620    64-BIT SHIFT EMITTERS
3621***************************************************************************/
3622
3623#ifdef PTR64
3624/*
3625    Note that the following code relies on this:
3626
3627        /0 = ROL
3628        /1 = ROR
3629        /2 = RCL
3630        /3 = RCR
3631        /4 = SHL
3632        /5 = SHR
3633        /7 = SAR
3634*/
3635
3636/*------------------------------------------------------------------
3637    emit_shift_r64_*
3638------------------------------------------------------------------*/
3639
3640INLINE void emit_shift_r64_imm(x86code **emitptr, UINT8 opindex, UINT8 dreg, UINT8 imm)
3641{
3642   if (imm == 1)
3643      emit_op_modrm_reg(emitptr, OP_G2_Ev_1, OP_64BIT, opindex, dreg);
3644   else
3645   {
3646      emit_op_modrm_reg(emitptr, OP_G2_Ev_Ib, OP_64BIT, opindex, dreg);
3647      emit_byte(emitptr, imm);
3648   }
3649}
3650
3651INLINE void emit_shift_m64bisd_imm(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp, UINT8 imm)
3652{
3653   if (imm == 1)
3654      emit_op_modrm_mem(emitptr, OP_G2_Ev_1, OP_64BIT, opindex, base, index, scale, disp);
3655   else
3656   {
3657      emit_op_modrm_mem(emitptr, OP_G2_Ev_Ib, OP_64BIT, opindex, base, index, scale, disp);
3658      emit_byte(emitptr, imm);
3659   }
3660}
3661
3662INLINE void emit_shift_r64_cl(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3663{
3664   emit_op_modrm_reg(emitptr, OP_G2_Ev_CL, OP_64BIT, opindex, dreg);
3665}
3666
3667INLINE void emit_shift_m64bisd_cl(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3668{
3669   emit_op_modrm_mem(emitptr, OP_G2_Ev_CL, OP_64BIT, opindex, base, index, scale, disp);
3670}
3671
3672
3673/*------------------------------------------------------------------
3674    emit_rol_r64_*
3675------------------------------------------------------------------*/
3676
3677#define emit_rol_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 0, dreg, imm)
3678#define emit_rol_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 0, base, index, scale, disp, imm)
3679#define emit_rol_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 0, dreg)
3680#define emit_rol_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 0, base, index, scale, disp)
3681
3682#define emit_rol_m64abs_imm(e, addr, imm)                  emit_rol_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3683#define emit_rol_m64bd_imm(e, base, disp, imm)               emit_rol_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3684#define emit_rol_m64isd_imm(e, index, scale, disp, imm)         emit_rol_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3685
3686#define emit_rol_m64abs_cl(e, addr)                        emit_rol_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3687#define emit_rol_m64bd_cl(e, base, disp)                  emit_rol_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3688#define emit_rol_m64isd_cl(e, index, scale, disp)            emit_rol_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3689
3690
3691/*------------------------------------------------------------------
3692    emit_ror_r64_*
3693------------------------------------------------------------------*/
3694
3695#define emit_ror_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 1, dreg, imm)
3696#define emit_ror_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 1, base, index, scale, disp, imm)
3697#define emit_ror_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 1, dreg)
3698#define emit_ror_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 1, base, index, scale, disp)
3699
3700#define emit_ror_m64abs_imm(e, addr, imm)                  emit_ror_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3701#define emit_ror_m64bd_imm(e, base, disp, imm)               emit_ror_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3702#define emit_ror_m64isd_imm(e, index, scale, disp, imm)         emit_ror_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3703
3704#define emit_ror_m64abs_cl(e, addr)                        emit_ror_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3705#define emit_ror_m64bd_cl(e, base, disp)                  emit_ror_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3706#define emit_ror_m64isd_cl(e, index, scale, disp)            emit_ror_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3707
3708
3709/*------------------------------------------------------------------
3710    emit_rcl_r64_*
3711------------------------------------------------------------------*/
3712
3713#define emit_rcl_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 2, dreg, imm)
3714#define emit_rcl_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 2, base, index, scale, disp, imm)
3715#define emit_rcl_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 2, dreg)
3716#define emit_rcl_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 2, base, index, scale, disp)
3717
3718#define emit_rcl_m64abs_imm(e, addr, imm)                  emit_rcl_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3719#define emit_rcl_m64bd_imm(e, base, disp, imm)               emit_rcl_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3720#define emit_rcl_m64isd_imm(e, index, scale, disp, imm)         emit_rcl_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3721
3722#define emit_rcl_m64abs_cl(e, addr)                        emit_rcl_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3723#define emit_rcl_m64bd_cl(e, base, disp)                  emit_rcl_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3724#define emit_rcl_m64isd_cl(e, index, scale, disp)            emit_rcl_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3725
3726
3727/*------------------------------------------------------------------
3728    emit_rcr_r64_*
3729------------------------------------------------------------------*/
3730
3731#define emit_rcr_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 3, dreg, imm)
3732#define emit_rcr_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 3, base, index, scale, disp, imm)
3733#define emit_rcr_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 3, dreg)
3734#define emit_rcr_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 3, base, index, scale, disp)
3735
3736#define emit_rcr_m64abs_imm(e, addr, imm)                  emit_rcr_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3737#define emit_rcr_m64bd_imm(e, base, disp, imm)               emit_rcr_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3738#define emit_rcr_m64isd_imm(e, index, scale, disp, imm)         emit_rcr_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3739
3740#define emit_rcr_m64abs_cl(e, addr)                        emit_rcr_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3741#define emit_rcr_m64bd_cl(e, base, disp)                  emit_rcr_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3742#define emit_rcr_m64isd_cl(e, index, scale, disp)            emit_rcr_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3743
3744
3745/*------------------------------------------------------------------
3746    emit_shl_r64_*
3747------------------------------------------------------------------*/
3748
3749#define emit_shl_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 4, dreg, imm)
3750#define emit_shl_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 4, base, index, scale, disp, imm)
3751#define emit_shl_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 4, dreg)
3752#define emit_shl_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 4, base, index, scale, disp)
3753
3754#define emit_shl_m64abs_imm(e, addr, imm)                  emit_shl_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3755#define emit_shl_m64bd_imm(e, base, disp, imm)               emit_shl_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3756#define emit_shl_m64isd_imm(e, index, scale, disp, imm)         emit_shl_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3757
3758#define emit_shl_m64abs_cl(e, addr)                        emit_shl_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3759#define emit_shl_m64bd_cl(e, base, disp)                  emit_shl_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3760#define emit_shl_m64isd_cl(e, index, scale, disp)            emit_shl_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3761
3762
3763/*------------------------------------------------------------------
3764    emit_shr_r64_*
3765------------------------------------------------------------------*/
3766
3767#define emit_shr_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 5, dreg, imm)
3768#define emit_shr_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 5, base, index, scale, disp, imm)
3769#define emit_shr_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 5, dreg)
3770#define emit_shr_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 5, base, index, scale, disp)
3771
3772#define emit_shr_m64abs_imm(e, addr, imm)                  emit_shr_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3773#define emit_shr_m64bd_imm(e, base, disp, imm)               emit_shr_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3774#define emit_shr_m64isd_imm(e, index, scale, disp, imm)         emit_shr_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3775
3776#define emit_shr_m64abs_cl(e, addr)                        emit_shr_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3777#define emit_shr_m64bd_cl(e, base, disp)                  emit_shr_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3778#define emit_shr_m64isd_cl(e, index, scale, disp)            emit_shr_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3779
3780
3781/*------------------------------------------------------------------
3782    emit_sar_r64_*
3783------------------------------------------------------------------*/
3784
3785#define emit_sar_r64_imm(e, dreg, imm)                     emit_shift_r64_imm(e, 7, dreg, imm)
3786#define emit_sar_m64bisd_imm(e, base, index, scale, disp, imm)   emit_shift_m64bisd_imm(e, 7, base, index, scale, disp, imm)
3787#define emit_sar_r64_cl(e, dreg)                        emit_shift_r64_cl(e, 7, dreg)
3788#define emit_sar_m64bisd_cl(e, base, index, scale, disp)      emit_shift_m64bisd_cl(e, 7, base, index, scale, disp)
3789
3790#define emit_sar_m64abs_imm(e, addr, imm)                  emit_sar_m64bisd_imm(e, REG_NONE, REG_NONE, 1,       (INT32)(addr), imm)
3791#define emit_sar_m64bd_imm(e, base, disp, imm)               emit_sar_m64bisd_imm(e, (base),   REG_NONE, 1,       (disp), imm)
3792#define emit_sar_m64isd_imm(e, index, scale, disp, imm)         emit_sar_m64bisd_imm(e, REG_NONE, (index),  (scale), (disp), imm)
3793
3794#define emit_sar_m64abs_cl(e, addr)                        emit_sar_m64bisd_cl(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3795#define emit_sar_m64bd_cl(e, base, disp)                  emit_sar_m64bisd_cl(e, (base),   REG_NONE, 1,       (disp))
3796#define emit_sar_m64isd_cl(e, index, scale, disp)            emit_sar_m64bisd_cl(e, REG_NONE, (index),  (scale), (disp))
3797
3798#endif
3799
3800
3801
3802/***************************************************************************
3803    8-BIT GROUP3 EMITTERS
3804***************************************************************************/
3805
3806/*
3807    Note that the following code relies on this:
3808
3809        /2 = NOT
3810        /3 = NEG
3811        /4 = MUL
3812        /5 = IMUL
3813        /6 = DIV
3814        /7 = IDIV
3815*/
3816
3817/*------------------------------------------------------------------
3818    emit_group3_r8_*
3819------------------------------------------------------------------*/
3820
3821INLINE void emit_group3_r8(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3822{
3823   emit_op_modrm_reg(emitptr, OP_G3_Eb, OP_32BIT, opindex, dreg);
3824}
3825
3826INLINE void emit_group3_m8bisd(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3827{
3828   emit_op_modrm_mem(emitptr, OP_G3_Eb, OP_32BIT, opindex, base, index, scale, disp);
3829}
3830
3831
3832/*------------------------------------------------------------------
3833    emit_not_r8_*
3834------------------------------------------------------------------*/
3835
3836#define emit_not_r8(e, dreg)                        emit_group3_r8(e, 2, dreg)
3837#define emit_not_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 2, base, index, scale, disp)
3838
3839#define emit_not_m8abs(e, addr)                        emit_not_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3840#define emit_not_m8bd(e, base, disp)                  emit_not_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3841#define emit_not_m8isd(e, index, scale, disp)            emit_not_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3842
3843
3844/*------------------------------------------------------------------
3845    emit_neg_r8_*
3846------------------------------------------------------------------*/
3847
3848#define emit_neg_r8(e, dreg)                        emit_group3_r8(e, 3, dreg)
3849#define emit_neg_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 3, base, index, scale, disp)
3850
3851#define emit_neg_m8abs(e, addr)                        emit_neg_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3852#define emit_neg_m8bd(e, base, disp)                  emit_neg_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3853#define emit_neg_m8isd(e, index, scale, disp)            emit_neg_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3854
3855
3856/*------------------------------------------------------------------
3857    emit_mul_r8_*
3858------------------------------------------------------------------*/
3859
3860#define emit_mul_r8(e, dreg)                        emit_group3_r8(e, 4, dreg)
3861#define emit_mul_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 4, base, index, scale, disp)
3862
3863#define emit_mul_m8abs(e, addr)                        emit_mul_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3864#define emit_mul_m8bd(e, base, disp)                  emit_mul_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3865#define emit_mul_m8isd(e, index, scale, disp)            emit_mul_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3866
3867
3868/*------------------------------------------------------------------
3869    emit_imul_r8_*
3870------------------------------------------------------------------*/
3871
3872#define emit_imul_r8(e, dreg)                        emit_group3_r8(e, 5, dreg)
3873#define emit_imul_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 5, base, index, scale, disp)
3874
3875#define emit_imul_m8abs(e, addr)                     emit_imul_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3876#define emit_imul_m8bd(e, base, disp)                  emit_imul_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3877#define emit_imul_m8isd(e, index, scale, disp)            emit_imul_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3878
3879
3880/*------------------------------------------------------------------
3881    emit_div_r8_*
3882------------------------------------------------------------------*/
3883
3884#define emit_div_r8(e, dreg)                        emit_group3_r8(e, 6, dreg)
3885#define emit_div_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 6, base, index, scale, disp)
3886
3887#define emit_div_m8abs(e, addr)                        emit_div_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3888#define emit_div_m8bd(e, base, disp)                  emit_div_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3889#define emit_div_m8isd(e, index, scale, disp)            emit_div_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3890
3891
3892/*------------------------------------------------------------------
3893    emit_idiv_r8_*
3894------------------------------------------------------------------*/
3895
3896#define emit_idiv_r8(e, dreg)                        emit_group3_r8(e, 7, dreg)
3897#define emit_idiv_m8bisd(e, base, index, scale, disp)      emit_group3_m8bisd(e, 7, base, index, scale, disp)
3898
3899#define emit_idiv_m8abs(e, addr)                     emit_idiv_m8bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3900#define emit_idiv_m8bd(e, base, disp)                  emit_idiv_m8bisd(e, (base),   REG_NONE, 1,       (disp))
3901#define emit_idiv_m8isd(e, index, scale, disp)            emit_idiv_m8bisd(e, REG_NONE, (index),  (scale), (disp))
3902
3903
3904
3905/***************************************************************************
3906    16-BIT GROUP3 EMITTERS
3907***************************************************************************/
3908
3909/*
3910    Note that the following code relies on this:
3911
3912        /0 = ROL
3913        /1 = ROR
3914        /2 = RCL
3915        /3 = RCR
3916        /4 = SHL
3917        /5 = SHR
3918        /7 = SAR
3919*/
3920
3921/*------------------------------------------------------------------
3922    emit_group3_r16_*
3923------------------------------------------------------------------*/
3924
3925INLINE void emit_group3_r16(x86code **emitptr, UINT8 opindex, UINT8 dreg)
3926{
3927   emit_byte(emitptr, PREFIX_OPSIZE);
3928   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_32BIT, opindex, dreg);
3929}
3930
3931INLINE void emit_group3_m16bisd(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
3932{
3933   emit_byte(emitptr, PREFIX_OPSIZE);
3934   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_32BIT, opindex, base, index, scale, disp);
3935}
3936
3937
3938/*------------------------------------------------------------------
3939    emit_not_r16_*
3940------------------------------------------------------------------*/
3941
3942#define emit_not_r16(e, dreg)                        emit_group3_r16(e, 2, dreg)
3943#define emit_not_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 2, base, index, scale, disp)
3944
3945#define emit_not_m16abs(e, addr)                     emit_not_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3946#define emit_not_m16bd(e, base, disp)                  emit_not_m16bisd(e, (base),   REG_NONE, 1,       (disp))
3947#define emit_not_m16isd(e, index, scale, disp)            emit_not_m16bisd(e, REG_NONE, (index),  (scale), (disp))
3948
3949
3950/*------------------------------------------------------------------
3951    emit_neg_r16_*
3952------------------------------------------------------------------*/
3953
3954#define emit_neg_r16(e, dreg)                        emit_group3_r16(e, 3, dreg)
3955#define emit_neg_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 3, base, index, scale, disp)
3956
3957#define emit_neg_m16abs(e, addr)                     emit_neg_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3958#define emit_neg_m16bd(e, base, disp)                  emit_neg_m16bisd(e, (base),   REG_NONE, 1,       (disp))
3959#define emit_neg_m16isd(e, index, scale, disp)            emit_neg_m16bisd(e, REG_NONE, (index),  (scale), (disp))
3960
3961
3962/*------------------------------------------------------------------
3963    emit_mul_r16_*
3964------------------------------------------------------------------*/
3965
3966#define emit_mul_r16(e, dreg)                        emit_group3_r16(e, 4, dreg)
3967#define emit_mul_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 4, base, index, scale, disp)
3968
3969#define emit_mul_m16abs(e, addr)                     emit_mul_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3970#define emit_mul_m16bd(e, base, disp)                  emit_mul_m16bisd(e, (base),   REG_NONE, 1,       (disp))
3971#define emit_mul_m16isd(e, index, scale, disp)            emit_mul_m16bisd(e, REG_NONE, (index),  (scale), (disp))
3972
3973
3974/*------------------------------------------------------------------
3975    emit_imul_r16_*
3976------------------------------------------------------------------*/
3977
3978#define emit_imul_r16(e, dreg)                        emit_group3_r16(e, 5, dreg)
3979#define emit_imul_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 5, base, index, scale, disp)
3980
3981#define emit_imul_m16abs(e, addr)                     emit_imul_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3982#define emit_imul_m16bd(e, base, disp)                  emit_imul_m16bisd(e, (base),   REG_NONE, 1,       (disp))
3983#define emit_imul_m16isd(e, index, scale, disp)            emit_imul_m16bisd(e, REG_NONE, (index),  (scale), (disp))
3984
3985
3986/*------------------------------------------------------------------
3987    emit_div_r16_*
3988------------------------------------------------------------------*/
3989
3990#define emit_div_r16(e, dreg)                        emit_group3_r16(e, 6, dreg)
3991#define emit_div_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 6, base, index, scale, disp)
3992
3993#define emit_div_m16abs(e, addr)                     emit_div_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
3994#define emit_div_m16bd(e, base, disp)                  emit_div_m16bisd(e, (base),   REG_NONE, 1,       (disp))
3995#define emit_div_m16isd(e, index, scale, disp)            emit_div_m16bisd(e, REG_NONE, (index),  (scale), (disp))
3996
3997
3998/*------------------------------------------------------------------
3999    emit_idiv_r16_*
4000------------------------------------------------------------------*/
4001
4002#define emit_idiv_r16(e, dreg)                        emit_group3_r16(e, 7, dreg)
4003#define emit_idiv_m16bisd(e, base, index, scale, disp)      emit_group3_m16bisd(e, 7, base, index, scale, disp)
4004
4005#define emit_idiv_m16abs(e, addr)                     emit_idiv_m16bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4006#define emit_idiv_m16bd(e, base, disp)                  emit_idiv_m16bisd(e, (base),   REG_NONE, 1,       (disp))
4007#define emit_idiv_m16isd(e, index, scale, disp)            emit_idiv_m16bisd(e, REG_NONE, (index),  (scale), (disp))
4008
4009
4010
4011/***************************************************************************
4012    32-BIT GROUP3 EMITTERS
4013***************************************************************************/
4014
4015/*
4016    Note that the following code relies on this:
4017
4018        /0 = ROL
4019        /1 = ROR
4020        /2 = RCL
4021        /3 = RCR
4022        /4 = SHL
4023        /5 = SHR
4024        /7 = SAR
4025*/
4026
4027/*------------------------------------------------------------------
4028    emit_group3_r32_*
4029------------------------------------------------------------------*/
4030
4031INLINE void emit_group3_r32(x86code **emitptr, UINT8 opindex, UINT8 dreg)
4032{
4033   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_32BIT, opindex, dreg);
4034}
4035
4036INLINE void emit_group3_m32bisd(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4037{
4038   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_32BIT, opindex, base, index, scale, disp);
4039}
4040
4041
4042/*------------------------------------------------------------------
4043    emit_not_r32_*
4044------------------------------------------------------------------*/
4045
4046#define emit_not_r32(e, dreg)                        emit_group3_r32(e, 2, dreg)
4047#define emit_not_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 2, base, index, scale, disp)
4048
4049#define emit_not_m32abs(e, addr)                     emit_not_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4050#define emit_not_m32bd(e, base, disp)                  emit_not_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4051#define emit_not_m32isd(e, index, scale, disp)            emit_not_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4052
4053
4054/*------------------------------------------------------------------
4055    emit_neg_r32_*
4056------------------------------------------------------------------*/
4057
4058#define emit_neg_r32(e, dreg)                        emit_group3_r32(e, 3, dreg)
4059#define emit_neg_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 3, base, index, scale, disp)
4060
4061#define emit_neg_m32abs(e, addr)                     emit_neg_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4062#define emit_neg_m32bd(e, base, disp)                  emit_neg_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4063#define emit_neg_m32isd(e, index, scale, disp)            emit_neg_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4064
4065
4066/*------------------------------------------------------------------
4067    emit_mul_r32_*
4068------------------------------------------------------------------*/
4069
4070#define emit_mul_r32(e, dreg)                        emit_group3_r32(e, 4, dreg)
4071#define emit_mul_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 4, base, index, scale, disp)
4072
4073#define emit_mul_m32abs(e, addr)                     emit_mul_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4074#define emit_mul_m32bd(e, base, disp)                  emit_mul_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4075#define emit_mul_m32isd(e, index, scale, disp)            emit_mul_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4076
4077
4078/*------------------------------------------------------------------
4079    emit_imul_r32_*
4080------------------------------------------------------------------*/
4081
4082#define emit_imul_r32(e, dreg)                        emit_group3_r32(e, 5, dreg)
4083#define emit_imul_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 5, base, index, scale, disp)
4084
4085#define emit_imul_m32abs(e, addr)                     emit_imul_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4086#define emit_imul_m32bd(e, base, disp)                  emit_imul_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4087#define emit_imul_m32isd(e, index, scale, disp)            emit_imul_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4088
4089
4090/*------------------------------------------------------------------
4091    emit_div_r32_*
4092------------------------------------------------------------------*/
4093
4094#define emit_div_r32(e, dreg)                        emit_group3_r32(e, 6, dreg)
4095#define emit_div_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 6, base, index, scale, disp)
4096
4097#define emit_div_m32abs(e, addr)                     emit_div_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4098#define emit_div_m32bd(e, base, disp)                  emit_div_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4099#define emit_div_m32isd(e, index, scale, disp)            emit_div_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4100
4101
4102/*------------------------------------------------------------------
4103    emit_idiv_r32_*
4104------------------------------------------------------------------*/
4105
4106#define emit_idiv_r32(e, dreg)                        emit_group3_r32(e, 7, dreg)
4107#define emit_idiv_m32bisd(e, base, index, scale, disp)      emit_group3_m32bisd(e, 7, base, index, scale, disp)
4108
4109#define emit_idiv_m32abs(e, addr)                     emit_idiv_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4110#define emit_idiv_m32bd(e, base, disp)                  emit_idiv_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4111#define emit_idiv_m32isd(e, index, scale, disp)            emit_idiv_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4112
4113
4114
4115/***************************************************************************
4116    64-BIT GROUP3 EMITTERS
4117***************************************************************************/
4118
4119#ifdef PTR64
4120/*
4121    Note that the following code relies on this:
4122
4123        /0 = ROL
4124        /1 = ROR
4125        /2 = RCL
4126        /3 = RCR
4127        /4 = SHL
4128        /5 = SHR
4129        /7 = SAR
4130*/
4131
4132/*------------------------------------------------------------------
4133    emit_group3_r64_*
4134------------------------------------------------------------------*/
4135
4136INLINE void emit_group3_r64(x86code **emitptr, UINT8 opindex, UINT8 dreg)
4137{
4138   emit_op_modrm_reg(emitptr, OP_G3_Ev, OP_64BIT, opindex, dreg);
4139}
4140
4141INLINE void emit_group3_m64bisd(x86code **emitptr, UINT8 opindex, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4142{
4143   emit_op_modrm_mem(emitptr, OP_G3_Ev, OP_64BIT, opindex, base, index, scale, disp);
4144}
4145
4146
4147/*------------------------------------------------------------------
4148    emit_not_r64_*
4149------------------------------------------------------------------*/
4150
4151#define emit_not_r64(e, dreg)                        emit_group3_r64(e, 2, dreg)
4152#define emit_not_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 2, base, index, scale, disp)
4153
4154#define emit_not_m64abs(e, addr)                     emit_not_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4155#define emit_not_m64bd(e, base, disp)                  emit_not_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4156#define emit_not_m64isd(e, index, scale, disp)            emit_not_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4157
4158
4159/*------------------------------------------------------------------
4160    emit_neg_r64_*
4161------------------------------------------------------------------*/
4162
4163#define emit_neg_r64(e, dreg)                        emit_group3_r64(e, 3, dreg)
4164#define emit_neg_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 3, base, index, scale, disp)
4165
4166#define emit_neg_m64abs(e, addr)                     emit_neg_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4167#define emit_neg_m64bd(e, base, disp)                  emit_neg_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4168#define emit_neg_m64isd(e, index, scale, disp)            emit_neg_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4169
4170
4171/*------------------------------------------------------------------
4172    emit_mul_r64_*
4173------------------------------------------------------------------*/
4174
4175#define emit_mul_r64(e, dreg)                        emit_group3_r64(e, 4, dreg)
4176#define emit_mul_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 4, base, index, scale, disp)
4177
4178#define emit_mul_m64abs(e, addr)                     emit_mul_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4179#define emit_mul_m64bd(e, base, disp)                  emit_mul_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4180#define emit_mul_m64isd(e, index, scale, disp)            emit_mul_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4181
4182
4183/*------------------------------------------------------------------
4184    emit_imul_r64_*
4185------------------------------------------------------------------*/
4186
4187#define emit_imul_r64(e, dreg)                        emit_group3_r64(e, 5, dreg)
4188#define emit_imul_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 5, base, index, scale, disp)
4189
4190#define emit_imul_m64abs(e, addr)                     emit_imul_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4191#define emit_imul_m64bd(e, base, disp)                  emit_imul_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4192#define emit_imul_m64isd(e, index, scale, disp)            emit_imul_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4193
4194
4195/*------------------------------------------------------------------
4196    emit_div_r64_*
4197------------------------------------------------------------------*/
4198
4199#define emit_div_r64(e, dreg)                        emit_group3_r64(e, 6, dreg)
4200#define emit_div_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 6, base, index, scale, disp)
4201
4202#define emit_div_m64abs(e, addr)                     emit_div_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4203#define emit_div_m64bd(e, base, disp)                  emit_div_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4204#define emit_div_m64isd(e, index, scale, disp)            emit_div_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4205
4206
4207/*------------------------------------------------------------------
4208    emit_idiv_r64_*
4209------------------------------------------------------------------*/
4210
4211#define emit_idiv_r64(e, dreg)                        emit_group3_r64(e, 7, dreg)
4212#define emit_idiv_m64bisd(e, base, index, scale, disp)      emit_group3_m64bisd(e, 7, base, index, scale, disp)
4213
4214#define emit_idiv_m64abs(e, addr)                     emit_idiv_m64bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4215#define emit_idiv_m64bd(e, base, disp)                  emit_idiv_m64bisd(e, (base),   REG_NONE, 1,       (disp))
4216#define emit_idiv_m64isd(e, index, scale, disp)            emit_idiv_m64bisd(e, REG_NONE, (index),  (scale), (disp))
4217
4218#endif
4219
4220
4221
4222/***************************************************************************
4223    LEA EMITTERS
4224***************************************************************************/
4225
4226/*------------------------------------------------------------------
4227    emit_lea_r32_*
4228------------------------------------------------------------------*/
4229
4230INLINE void emit_lea_r32_m32bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4231{
4232   emit_op_modrm_mem(emitptr, OP_LEA_Gv_M, OP_32BIT, dreg, base, index, scale, disp);
4233}
4234
4235#define emit_lea_r32_m32abs(e, dreg, addr)               emit_lea_r32_m32bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4236#define emit_lea_r32_m32bd(e, dreg, base, disp)            emit_lea_r32_m32bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
4237#define emit_lea_r32_m32isd(e, dreg, index, scale, disp)   emit_lea_r32_m32bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
4238
4239
4240/*------------------------------------------------------------------
4241    emit_lea_r64_*
4242------------------------------------------------------------------*/
4243
4244#ifdef PTR64
4245INLINE void emit_lea_r64_m64bisd(x86code **emitptr, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4246{
4247   emit_op_modrm_mem(emitptr, OP_LEA_Gv_M, OP_64BIT, dreg, base, index, scale, disp);
4248}
4249
4250#define emit_lea_r64_m64abs(e, dreg, addr)               emit_lea_r64_m64bisd(e, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4251#define emit_lea_r64_m64bd(e, dreg, base, disp)            emit_lea_r64_m64bisd(e, dreg, (base),   REG_NONE, 1,       (disp))
4252#define emit_lea_r64_m64isd(e, dreg, index, scale, disp)   emit_lea_r64_m64bisd(e, dreg, REG_NONE, (index),  (scale), (disp))
4253#endif
4254
4255
4256
4257/***************************************************************************
4258    PUSH/POP EMITTERS
4259***************************************************************************/
4260
4261/*------------------------------------------------------------------
4262    emit_push_*
4263------------------------------------------------------------------*/
4264
4265#ifndef PTR64
4266INLINE void emit_push_r32(x86code **emitptr, UINT8 reg)
4267{
4268   emit_op(emitptr, OP_PUSH_rAX + (reg & 7), OP_32BIT, 0, 0, reg);
4269}
4270#endif
4271
4272#ifdef PTR64
4273INLINE void emit_push_r64(x86code **emitptr, UINT8 reg)
4274{
4275   emit_op(emitptr, OP_PUSH_rAX + (reg & 7), OP_32BIT, 0, 0, reg);
4276}
4277#endif
4278
4279
4280/*------------------------------------------------------------------
4281    emit_pop_*
4282------------------------------------------------------------------*/
4283
4284#ifndef PTR64
4285INLINE void emit_pop_r32(x86code **emitptr, UINT8 reg)
4286{
4287   emit_op(emitptr, OP_POP_rAX + (reg & 7), OP_32BIT, 0, 0, reg);
4288}
4289#endif
4290
4291#ifdef PTR64
4292INLINE void emit_pop_r64(x86code **emitptr, UINT8 reg)
4293{
4294   emit_op(emitptr, OP_POP_rAX + (reg & 7), OP_32BIT, 0, 0, reg);
4295}
4296#endif
4297
4298
4299
4300/***************************************************************************
4301    SET EMITTERS
4302***************************************************************************/
4303
4304/*------------------------------------------------------------------
4305    emit_setcc_*
4306------------------------------------------------------------------*/
4307
4308INLINE void emit_setcc_r8(x86code **emitptr, UINT8 condition, UINT8 dreg)
4309{
4310   emit_op_modrm_reg(emitptr, OP_SETCC_O_Eb + condition, OP_32BIT, 0, dreg);
4311}
4312
4313INLINE void emit_setcc_m8bisd(x86code **emitptr, UINT8 condition, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4314{
4315   emit_op_modrm_mem(emitptr, OP_SETCC_O_Eb + condition, OP_32BIT, 0, base, index, scale, disp);
4316}
4317
4318#define emit_setcc_m8abs(e, cond, addr)                  emit_setcc_m8bisd(e, cond, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4319#define emit_setcc_m8bd(e, cond, base, disp)            emit_setcc_m8bisd(e, cond, (base),   REG_NONE, 1,       (disp))
4320#define emit_setcc_m8isd(e, cond, index, scale, disp)      emit_setcc_m8bisd(e, cond, REG_NONE, (index),  (scale), (disp))
4321
4322
4323
4324/***************************************************************************
4325    FPU EMITTERS
4326***************************************************************************/
4327
4328#ifndef PTR64
4329INLINE void emit_fp_simple(x86code **emitptr, UINT8 op)
4330{
4331   emit_op_simple(emitptr, op, OP_32BIT);
4332}
4333
4334INLINE void emit_fp_reg(x86code **emitptr, UINT8 op, UINT8 reg)
4335{
4336   emit_op_simple(emitptr, op + reg, OP_32BIT);
4337}
4338
4339INLINE void emit_fp_modrm(x86code **emitptr, UINT32 op, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4340{
4341   emit_op_modrm_mem(emitptr, op, OP_32BIT, dreg, base, index, scale, disp);
4342}
4343
4344
4345
4346/***************************************************************************
4347    SIMPLE FPU EMITTERS
4348***************************************************************************/
4349
4350#define emit_fnop(e)                           emit_fp_simple(e, OP_FNOP)
4351#define emit_fchs(e)                           emit_fp_simple(e, OP_FCHS)
4352#define emit_fabs(e)                           emit_fp_simple(e, OP_FABS)
4353#define emit_ftst(e)                           emit_fp_simple(e, OP_FTST)
4354#define emit_fxam(e)                           emit_fp_simple(e, OP_FXAM)
4355#define emit_fld1(e)                           emit_fp_simple(e, OP_FLD1)
4356#define emit_fldl2t(e)                           emit_fp_simple(e, OP_FLDL2T)
4357#define emit_fldl2e(e)                           emit_fp_simple(e, OP_FLDL2E)
4358#define emit_fldpi(e)                           emit_fp_simple(e, OP_FLDPI)
4359#define emit_fldlg2(e)                           emit_fp_simple(e, OP_FLDLG2)
4360#define emit_fldln2(e)                           emit_fp_simple(e, OP_FLDLN2)
4361#define emit_fldz(e)                           emit_fp_simple(e, OP_FLDZ)
4362#define emit_f2xm1(e)                           emit_fp_simple(e, OP_F2XM1)
4363#define emit_fyl2x(e)                           emit_fp_simple(e, OP_FYL2X)
4364#define emit_fptan(e)                           emit_fp_simple(e, OP_FPTAN)
4365#define emit_fpatan(e)                           emit_fp_simple(e, OP_FPATAN)
4366#define emit_fxtract(e)                           emit_fp_simple(e, OP_FXTRACT)
4367#define emit_fprem1(e)                           emit_fp_simple(e, OP_FPREM1)
4368#define emit_fdecstp(e)                           emit_fp_simple(e, OP_FDECSTP)
4369#define emit_fincstp(e)                           emit_fp_simple(e, OP_FINCSTP)
4370#define emit_fprem(e)                           emit_fp_simple(e, OP_FPREM)
4371#define emit_fyl2xp1(e)                           emit_fp_simple(e, OP_FYl2XP1)
4372#define emit_fsqrt(e)                           emit_fp_simple(e, OP_FSQRT)
4373#define emit_fsincos(e)                           emit_fp_simple(e, OP_FSINCOS)
4374#define emit_frndint(e)                           emit_fp_simple(e, OP_FRNDINT)
4375#define emit_fscale(e)                           emit_fp_simple(e, OP_FSCALE)
4376#define emit_fsin(e)                           emit_fp_simple(e, OP_FSIN)
4377#define emit_fcos(e)                           emit_fp_simple(e, OP_FCOS)
4378#define emit_fucompp(e)                           emit_fp_simple(e, OP_FUCOMPP)
4379#define emit_fclex(e)                           emit_fp_simple(e, OP_FCLEX)
4380#define emit_finit(e)                           emit_fp_simple(e, OP_FINIT)
4381#define emit_fcompp(e)                           emit_fp_simple(e, OP_FCOMPP)
4382#define emit_fstsw_ax(e)                        emit_fp_simple(e, OP_FSTSW_AX)
4383
4384
4385
4386/***************************************************************************
4387    REGISTER-BASED FPU EMITTERS
4388***************************************************************************/
4389
4390#define emit_ffree_stn(e, reg)                     emit_fp_reg(e, OP_FFREE_STn, reg)
4391#define emit_fst_stn(e, reg)                     emit_fp_reg(e, OP_FST_STn, reg)
4392#define emit_fstp_stn(e, reg)                     emit_fp_reg(e, OP_FSTP_STn, reg)
4393#define emit_fucomp_stn(e, reg)                     emit_fp_reg(e, OP_FUCOMP_STn, reg)
4394
4395#define emit_fadd_st0_stn(e, reg)                  emit_fp_reg(e, OP_FADD_ST0_STn, reg)
4396#define emit_fmul_st0_stn(e, reg)                  emit_fp_reg(e, OP_FMUL_ST0_STn, reg)
4397#define emit_fcom_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCOM_ST0_STn, reg)
4398#define emit_fcomp_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCOMP_ST0_STn, reg)
4399#define emit_fsub_st0_stn(e, reg)                  emit_fp_reg(e, OP_FSUB_ST0_STn, reg)
4400#define emit_fsubr_st0_stn(e, reg)                  emit_fp_reg(e, OP_FSUBR_ST0_STn, reg)
4401#define emit_fdiv_st0_stn(e, reg)                  emit_fp_reg(e, OP_FDIV_ST0_STn, reg)
4402#define emit_fdivr_st0_stn(e, reg)                  emit_fp_reg(e, OP_FDIVR_ST0_STn, reg)
4403#define emit_fld_st0_stn(e, reg)                  emit_fp_reg(e, OP_FLD_ST0_STn, reg)
4404#define emit_fxch_st0_stn(e, reg)                  emit_fp_reg(e, OP_FXCH_ST0_STn, reg)
4405#define emit_fcmovb_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCMOVB_ST0_STn, reg)
4406#define emit_fcmove_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCMOVE_ST0_STn, reg)
4407#define emit_fcmovbe_st0_stn(e, reg)               emit_fp_reg(e, OP_FCMOVBE_ST0_STn, reg)
4408#define emit_fcmovu_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCMOVU_ST0_STn, reg)
4409#define emit_fcmovnb_st0_stn(e, reg)               emit_fp_reg(e, OP_FCMOVNB_ST0_STn, reg)
4410#define emit_fcmovne_st0_stn(e, reg)               emit_fp_reg(e, OP_FCMOVNE_ST0_STn, reg)
4411#define emit_fcmovnbe_st0_stn(e, reg)               emit_fp_reg(e, OP_FCMOVNBE_ST0_STn, reg)
4412#define emit_fcmovnu_st0_stn(e, reg)               emit_fp_reg(e, OP_FCMOVNU_ST0_STn, reg)
4413#define emit_fucomi_st0_stn(e, reg)                  emit_fp_reg(e, OP_FUCOMI_ST0_STn, reg)
4414#define emit_fcomi_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCOMI_ST0_STn, reg)
4415#define emit_fcomip_st0_stn(e, reg)                  emit_fp_reg(e, OP_FCOMIP_ST0_STn, reg)
4416
4417#define emit_fadd_stn_st0(e, reg)                  emit_fp_reg(e, OP_FADD_STn_ST0, reg)
4418#define emit_fmul_stn_st0(e, reg)                  emit_fp_reg(e, OP_FMUL_STn_ST0, reg)
4419#define emit_fsubr_stn_st0(e, reg)                  emit_fp_reg(e, OP_FSUBR_STn_ST0, reg)
4420#define emit_fsub_stn_st0(e, reg)                  emit_fp_reg(e, OP_FSUB_STn_ST0, reg)
4421#define emit_fdivr_stn_st0(e, reg)                  emit_fp_reg(e, OP_FDIVR_STn_ST0, reg)
4422#define emit_fdiv_stn_st0(e, reg)                  emit_fp_reg(e, OP_FDIV_STn_ST0, reg)
4423#define emit_fucom_stn_st0(e, reg)                  emit_fp_reg(e, OP_FUCOM_STn_ST0, reg)
4424#define emit_faddp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FADDP_STn_ST0, reg)
4425#define emit_fmulp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FMULP_STn_ST0, reg)
4426#define emit_fsubrp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FSUBRP_STn_ST0, reg)
4427#define emit_fsubp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FSUBP_STn_ST0, reg)
4428#define emit_fdivrp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FDIVRP_STn_ST0, reg)
4429#define emit_fdivp_stn_st0(e, reg)                  emit_fp_reg(e, OP_FDIVP_STn_ST0, reg)
4430
4431
4432
4433/***************************************************************************
4434    MEMORY FPU EMITTERS
4435***************************************************************************/
4436
4437#define emit_fadd_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4438#define emit_fadd_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 0, (base),   REG_NONE, 1,       (disp))
4439#define emit_fadd_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D8, 0, REG_NONE, (index),  (scale), (disp))
4440#define emit_fadd_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 0, (base),   (index),  (scale), (disp))
4441
4442#define emit_fmul_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4443#define emit_fmul_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 1, (base),   REG_NONE, 1,       (disp))
4444#define emit_fmul_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D8, 1, REG_NONE, (index),  (scale), (disp))
4445#define emit_fmul_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 1, (base),   (index),  (scale), (disp))
4446
4447#define emit_fcom_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4448#define emit_fcom_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 2, (base),   REG_NONE, 1,       (disp))
4449#define emit_fcom_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D8, 2, REG_NONE, (index),  (scale), (disp))
4450#define emit_fcom_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 2, (base),   (index),  (scale), (disp))
4451
4452#define emit_fcomp_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4453#define emit_fcomp_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 3, (base),   REG_NONE, 1,       (disp))
4454#define emit_fcomp_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_D8, 3, REG_NONE, (index),  (scale), (disp))
4455#define emit_fcomp_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 3, (base),   (index),  (scale), (disp))
4456
4457#define emit_fsub_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4458#define emit_fsub_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 4, (base),   REG_NONE, 1,       (disp))
4459#define emit_fsub_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D8, 4, REG_NONE, (index),  (scale), (disp))
4460#define emit_fsub_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 4, (base),   (index),  (scale), (disp))
4461
4462#define emit_fsubr_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4463#define emit_fsubr_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 5, (base),   REG_NONE, 1,       (disp))
4464#define emit_fsubr_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_D8, 5, REG_NONE, (index),  (scale), (disp))
4465#define emit_fsubr_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 5, (base),   (index),  (scale), (disp))
4466
4467#define emit_fdiv_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4468#define emit_fdiv_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 6, (base),   REG_NONE, 1,       (disp))
4469#define emit_fdiv_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D8, 6, REG_NONE, (index),  (scale), (disp))
4470#define emit_fdiv_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 6, (base),   (index),  (scale), (disp))
4471
4472#define emit_fdivr_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D8, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4473#define emit_fdivr_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D8, 7, (base),   REG_NONE, 1,       (disp))
4474#define emit_fdivr_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_D8, 7, REG_NONE, (index),  (scale), (disp))
4475#define emit_fdivr_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D8, 7, (base),   (index),  (scale), (disp))
4476
4477
4478#define emit_fld_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4479#define emit_fld_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 0, (base),   REG_NONE, 1,       (disp))
4480#define emit_fld_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D9, 0, REG_NONE, (index),  (scale), (disp))
4481#define emit_fld_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 0, (base),   (index),  (scale), (disp))
4482
4483#define emit_fst_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4484#define emit_fst_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 2, (base),   REG_NONE, 1,       (disp))
4485#define emit_fst_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D9, 2, REG_NONE, (index),  (scale), (disp))
4486#define emit_fst_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 2, (base),   (index),  (scale), (disp))
4487
4488#define emit_fstp_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4489#define emit_fstp_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 3, (base),   REG_NONE, 1,       (disp))
4490#define emit_fstp_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D9, 3, REG_NONE, (index),  (scale), (disp))
4491#define emit_fstp_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 3, (base),   (index),  (scale), (disp))
4492
4493#define emit_fldenv_mabs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4494#define emit_fldenv_mbd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 4, (base),   REG_NONE, 1,       (disp))
4495#define emit_fldenv_misd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D9, 4, REG_NONE, (index),  (scale), (disp))
4496#define emit_fldenv_mbisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 4, (base),   (index),  (scale), (disp))
4497
4498#define emit_fldcw_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4499#define emit_fldcw_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 5, (base),   REG_NONE, 1,       (disp))
4500#define emit_fldcw_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_D9, 5, REG_NONE, (index),  (scale), (disp))
4501#define emit_fldcw_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 5, (base),   (index),  (scale), (disp))
4502
4503#define emit_fstenv_mabs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4504#define emit_fstenv_mbd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 6, (base),   REG_NONE, 1,       (disp))
4505#define emit_fstenv_misd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_D9, 6, REG_NONE, (index),  (scale), (disp))
4506#define emit_fstenv_mbisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 6, (base),   (index),  (scale), (disp))
4507
4508#define emit_fstcw_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_D9, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4509#define emit_fstcw_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_D9, 7, (base),   REG_NONE, 1,       (disp))
4510#define emit_fstcw_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_D9, 7, REG_NONE, (index),  (scale), (disp))
4511#define emit_fstcw_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_D9, 7, (base),   (index),  (scale), (disp))
4512
4513
4514#define emit_fiadd_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4515#define emit_fiadd_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DA, 0, (base),   REG_NONE, 1,       (disp))
4516#define emit_fiadd_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 0, REG_NONE, (index),  (scale), (disp))
4517#define emit_fiadd_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DA, 0, (base),   (index),  (scale), (disp))
4518
4519#define emit_fimul_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4520#define emit_fimul_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DA, 1, (base),   REG_NONE, 1,       (disp))
4521#define emit_fimul_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 1, REG_NONE, (index),  (scale), (disp))
4522#define emit_fimul_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DA, 1, (base),   (index),  (scale), (disp))
4523
4524#define emit_ficom_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4525#define emit_ficom_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DA, 2, (base),   REG_NONE, 1,       (disp))
4526#define emit_ficom_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 2, REG_NONE, (index),  (scale), (disp))
4527#define emit_ficom_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DA, 2, (base),   (index),  (scale), (disp))
4528
4529#define emit_ficomp_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4530#define emit_ficomp_m32bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DA, 3, (base),   REG_NONE, 1,       (disp))
4531#define emit_ficomp_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 3, REG_NONE, (index),  (scale), (disp))
4532#define emit_ficomp_m32bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DA, 3, (base),   (index),  (scale), (disp))
4533
4534#define emit_fisub_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4535#define emit_fisub_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DA, 4, (base),   REG_NONE, 1,       (disp))
4536#define emit_fisub_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 4, REG_NONE, (index),  (scale), (disp))
4537#define emit_fisub_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DA, 4, (base),   (index),  (scale), (disp))
4538
4539#define emit_fisubr_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4540#define emit_fisubr_m32bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DA, 5, (base),   REG_NONE, 1,       (disp))
4541#define emit_fisubr_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 5, REG_NONE, (index),  (scale), (disp))
4542#define emit_fisubr_m32bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DA, 5, (base),   (index),  (scale), (disp))
4543
4544#define emit_fidiv_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4545#define emit_fidiv_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DA, 6, (base),   REG_NONE, 1,       (disp))
4546#define emit_fidiv_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 6, REG_NONE, (index),  (scale), (disp))
4547#define emit_fidiv_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DA, 6, (base),   (index),  (scale), (disp))
4548
4549#define emit_fidivr_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DA, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4550#define emit_fidivr_m32bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DA, 7, (base),   REG_NONE, 1,       (disp))
4551#define emit_fidivr_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DA, 7, REG_NONE, (index),  (scale), (disp))
4552#define emit_fidivr_m32bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DA, 7, (base),   (index),  (scale), (disp))
4553
4554
4555#define emit_fild_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4556#define emit_fild_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DB, 0, (base),   REG_NONE, 1,       (disp))
4557#define emit_fild_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DB, 0, REG_NONE, (index),  (scale), (disp))
4558#define emit_fild_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DB, 0, (base),   (index),  (scale), (disp))
4559
4560#define emit_fisttp_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4561#define emit_fisttp_m32bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DB, 1, (base),   REG_NONE, 1,       (disp))
4562#define emit_fisttp_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DB, 1, REG_NONE, (index),  (scale), (disp))
4563#define emit_fisttp_m32bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DB, 1, (base),   (index),  (scale), (disp))
4564
4565#define emit_fist_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4566#define emit_fist_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DB, 2, (base),   REG_NONE, 1,       (disp))
4567#define emit_fist_m32isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DB, 2, REG_NONE, (index),  (scale), (disp))
4568#define emit_fist_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DB, 2, (base),   (index),  (scale), (disp))
4569
4570#define emit_fistp_m32abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4571#define emit_fistp_m32bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DB, 3, (base),   REG_NONE, 1,       (disp))
4572#define emit_fistp_m32isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DB, 3, REG_NONE, (index),  (scale), (disp))
4573#define emit_fistp_m32bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DB, 3, (base),   (index),  (scale), (disp))
4574
4575#define emit_fld_m80abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4576#define emit_fld_m80bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DB, 5, (base),   REG_NONE, 1,       (disp))
4577#define emit_fld_m80isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DB, 5, REG_NONE, (index),  (scale), (disp))
4578#define emit_fld_m80bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DB, 5, (base),   (index),  (scale), (disp))
4579
4580#define emit_fstp_m80abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DB, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4581#define emit_fstp_m80bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DB, 7, (base),   REG_NONE, 1,       (disp))
4582#define emit_fstp_m80isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DB, 7, REG_NONE, (index),  (scale), (disp))
4583#define emit_fstp_m80bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DB, 7, (base),   (index),  (scale), (disp))
4584
4585
4586#define emit_fadd_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4587#define emit_fadd_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 0, (base),   REG_NONE, 1,       (disp))
4588#define emit_fadd_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DC, 0, REG_NONE, (index),  (scale), (disp))
4589#define emit_fadd_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 0, (base),   (index),  (scale), (disp))
4590
4591#define emit_fmul_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4592#define emit_fmul_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 1, (base),   REG_NONE, 1,       (disp))
4593#define emit_fmul_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DC, 1, REG_NONE, (index),  (scale), (disp))
4594#define emit_fmul_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 1, (base),   (index),  (scale), (disp))
4595
4596#define emit_fcom_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4597#define emit_fcom_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 2, (base),   REG_NONE, 1,       (disp))
4598#define emit_fcom_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DC, 2, REG_NONE, (index),  (scale), (disp))
4599#define emit_fcom_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 2, (base),   (index),  (scale), (disp))
4600
4601#define emit_fcomp_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4602#define emit_fcomp_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 3, (base),   REG_NONE, 1,       (disp))
4603#define emit_fcomp_m64isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DC, 3, REG_NONE, (index),  (scale), (disp))
4604#define emit_fcomp_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 3, (base),   (index),  (scale), (disp))
4605
4606#define emit_fsub_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4607#define emit_fsub_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 4, (base),   REG_NONE, 1,       (disp))
4608#define emit_fsub_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DC, 4, REG_NONE, (index),  (scale), (disp))
4609#define emit_fsub_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 4, (base),   (index),  (scale), (disp))
4610
4611#define emit_fsubr_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4612#define emit_fsubr_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 5, (base),   REG_NONE, 1,       (disp))
4613#define emit_fsubr_m64isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DC, 5, REG_NONE, (index),  (scale), (disp))
4614#define emit_fsubr_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 5, (base),   (index),  (scale), (disp))
4615
4616#define emit_fdiv_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4617#define emit_fdiv_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 6, (base),   REG_NONE, 1,       (disp))
4618#define emit_fdiv_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DC, 6, REG_NONE, (index),  (scale), (disp))
4619#define emit_fdiv_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 6, (base),   (index),  (scale), (disp))
4620
4621#define emit_fdivr_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DC, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4622#define emit_fdivr_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DC, 7, (base),   REG_NONE, 1,       (disp))
4623#define emit_fdivr_m64isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DC, 7, REG_NONE, (index),  (scale), (disp))
4624#define emit_fdivr_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DC, 7, (base),   (index),  (scale), (disp))
4625
4626
4627#define emit_fld_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4628#define emit_fld_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 0, (base),   REG_NONE, 1,       (disp))
4629#define emit_fld_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DD, 0, REG_NONE, (index),  (scale), (disp))
4630#define emit_fld_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 0, (base),   (index),  (scale), (disp))
4631
4632#define emit_fisttp_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4633#define emit_fisttp_m64bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DD, 1, (base),   REG_NONE, 1,       (disp))
4634#define emit_fisttp_m64isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DD, 1, REG_NONE, (index),  (scale), (disp))
4635#define emit_fisttp_m64bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DD, 1, (base),   (index),  (scale), (disp))
4636
4637#define emit_fst_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4638#define emit_fst_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 2, (base),   REG_NONE, 1,       (disp))
4639#define emit_fst_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DD, 2, REG_NONE, (index),  (scale), (disp))
4640#define emit_fst_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 2, (base),   (index),  (scale), (disp))
4641
4642#define emit_fstp_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4643#define emit_fstp_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 3, (base),   REG_NONE, 1,       (disp))
4644#define emit_fstp_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DD, 3, REG_NONE, (index),  (scale), (disp))
4645#define emit_fstp_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 3, (base),   (index),  (scale), (disp))
4646
4647#define emit_frstor_mabs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4648#define emit_frstor_mbd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 4, (base),   REG_NONE, 1,       (disp))
4649#define emit_frstor_misd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DD, 4, REG_NONE, (index),  (scale), (disp))
4650#define emit_frstor_mbisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 4, (base),   (index),  (scale), (disp))
4651
4652#define emit_fsave_mabs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4653#define emit_fsave_mbd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 6, (base),   REG_NONE, 1,       (disp))
4654#define emit_fsave_misd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DD, 6, REG_NONE, (index),  (scale), (disp))
4655#define emit_fsave_mbisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 6, (base),   (index),  (scale), (disp))
4656
4657#define emit_fstsw_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DD, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4658#define emit_fstsw_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DD, 7, (base),   REG_NONE, 1,       (disp))
4659#define emit_fstsw_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DD, 7, REG_NONE, (index),  (scale), (disp))
4660#define emit_fstsw_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DD, 7, (base),   (index),  (scale), (disp))
4661
4662
4663#define emit_fiadd_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4664#define emit_fiadd_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DE, 0, (base),   REG_NONE, 1,       (disp))
4665#define emit_fiadd_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 0, REG_NONE, (index),  (scale), (disp))
4666#define emit_fiadd_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DE, 0, (base),   (index),  (scale), (disp))
4667
4668#define emit_fimul_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4669#define emit_fimul_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DE, 1, (base),   REG_NONE, 1,       (disp))
4670#define emit_fimul_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 1, REG_NONE, (index),  (scale), (disp))
4671#define emit_fimul_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DE, 1, (base),   (index),  (scale), (disp))
4672
4673#define emit_ficom_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4674#define emit_ficom_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DE, 2, (base),   REG_NONE, 1,       (disp))
4675#define emit_ficom_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 2, REG_NONE, (index),  (scale), (disp))
4676#define emit_ficom_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DE, 2, (base),   (index),  (scale), (disp))
4677
4678#define emit_ficomp_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4679#define emit_ficomp_m16bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DE, 3, (base),   REG_NONE, 1,       (disp))
4680#define emit_ficomp_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 3, REG_NONE, (index),  (scale), (disp))
4681#define emit_ficomp_m16bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DE, 3, (base),   (index),  (scale), (disp))
4682
4683#define emit_fisub_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4684#define emit_fisub_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DE, 4, (base),   REG_NONE, 1,       (disp))
4685#define emit_fisub_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 4, REG_NONE, (index),  (scale), (disp))
4686#define emit_fisub_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DE, 4, (base),   (index),  (scale), (disp))
4687
4688#define emit_fisubr_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4689#define emit_fisubr_m16bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DE, 5, (base),   REG_NONE, 1,       (disp))
4690#define emit_fisubr_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 5, REG_NONE, (index),  (scale), (disp))
4691#define emit_fisubr_m16bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DE, 5, (base),   (index),  (scale), (disp))
4692
4693#define emit_fidiv_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4694#define emit_fidiv_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DE, 6, (base),   REG_NONE, 1,       (disp))
4695#define emit_fidiv_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 6, REG_NONE, (index),  (scale), (disp))
4696#define emit_fidiv_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DE, 6, (base),   (index),  (scale), (disp))
4697
4698#define emit_fidivr_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DE, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4699#define emit_fidivr_m16bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DE, 7, (base),   REG_NONE, 1,       (disp))
4700#define emit_fidivr_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DE, 7, REG_NONE, (index),  (scale), (disp))
4701#define emit_fidivr_m16bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DE, 7, (base),   (index),  (scale), (disp))
4702
4703
4704#define emit_fild_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 0, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4705#define emit_fild_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 0, (base),   REG_NONE, 1,       (disp))
4706#define emit_fild_m16isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DF, 0, REG_NONE, (index),  (scale), (disp))
4707#define emit_fild_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 0, (base),   (index),  (scale), (disp))
4708
4709#define emit_fisttp_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 1, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4710#define emit_fisttp_m16bd(e, base, disp)               emit_fp_modrm(e, OP_ESC_DF, 1, (base),   REG_NONE, 1,       (disp))
4711#define emit_fisttp_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DF, 1, REG_NONE, (index),  (scale), (disp))
4712#define emit_fisttp_m16bisd(e, base, index, scale, disp)   emit_fp_modrm(e, OP_ESC_DF, 1, (base),   (index),  (scale), (disp))
4713
4714#define emit_fist_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 2, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4715#define emit_fist_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 2, (base),   REG_NONE, 1,       (disp))
4716#define emit_fist_m16isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DF, 2, REG_NONE, (index),  (scale), (disp))
4717#define emit_fist_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 2, (base),   (index),  (scale), (disp))
4718
4719#define emit_fistp_m16abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 3, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4720#define emit_fistp_m16bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 3, (base),   REG_NONE, 1,       (disp))
4721#define emit_fistp_m16isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DF, 3, REG_NONE, (index),  (scale), (disp))
4722#define emit_fistp_m16bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 3, (base),   (index),  (scale), (disp))
4723
4724#define emit_fbld_m80abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 4, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4725#define emit_fbld_m80bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 4, (base),   REG_NONE, 1,       (disp))
4726#define emit_fbld_m80isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DF, 4, REG_NONE, (index),  (scale), (disp))
4727#define emit_fbld_m80bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 4, (base),   (index),  (scale), (disp))
4728
4729#define emit_fild_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 5, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4730#define emit_fild_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 5, (base),   REG_NONE, 1,       (disp))
4731#define emit_fild_m64isd(e, index, scale, disp)            emit_fp_modrm(e, OP_ESC_DF, 5, REG_NONE, (index),  (scale), (disp))
4732#define emit_fild_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 5, (base),   (index),  (scale), (disp))
4733
4734#define emit_fbstp_m80abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 6, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4735#define emit_fbstp_m80bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 6, (base),   REG_NONE, 1,       (disp))
4736#define emit_fbstp_m80isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DF, 6, REG_NONE, (index),  (scale), (disp))
4737#define emit_fbstp_m80bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 6, (base),   (index),  (scale), (disp))
4738
4739#define emit_fistp_m64abs(e, addr)                     emit_fp_modrm(e, OP_ESC_DF, 7, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4740#define emit_fistp_m64bd(e, base, disp)                  emit_fp_modrm(e, OP_ESC_DF, 7, (base),   REG_NONE, 1,       (disp))
4741#define emit_fistp_m64isd(e, index, scale, disp)         emit_fp_modrm(e, OP_ESC_DF, 7, REG_NONE, (index),  (scale), (disp))
4742#define emit_fistp_m64bisd(e, base, index, scale, disp)      emit_fp_modrm(e, OP_ESC_DF, 7, (base),   (index),  (scale), (disp))
4743
4744#endif
4745
4746
4747
4748/***************************************************************************
4749    GROUP16 EMITTERS
4750***************************************************************************/
4751
4752/*------------------------------------------------------------------
4753    emit_ldmxcsr_*
4754------------------------------------------------------------------*/
4755
4756INLINE void emit_ldmxcsr_m32bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4757{
4758   emit_op_modrm_mem(emitptr, OP_G16, OP_32BIT, 2, base, index, scale, disp);
4759}
4760
4761#define emit_ldmxcsr_m32abs(e, addr)               emit_ldmxcsr_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4762#define emit_ldmxcsr_m32bd(e, base, disp)            emit_ldmxcsr_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4763#define emit_ldmxcsr_m32isd(e, index, scale, disp)      emit_ldmxcsr_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4764
4765
4766/*------------------------------------------------------------------
4767    emit_stmxcsr_*
4768------------------------------------------------------------------*/
4769
4770INLINE void emit_stmxcsr_m32bisd(x86code **emitptr, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4771{
4772   emit_op_modrm_mem(emitptr, OP_G16, OP_32BIT, 3, base, index, scale, disp);
4773}
4774
4775#define emit_stmxcsr_m32abs(e, addr)               emit_stmxcsr_m32bisd(e, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4776#define emit_stmxcsr_m32bd(e, base, disp)            emit_stmxcsr_m32bisd(e, (base),   REG_NONE, 1,       (disp))
4777#define emit_stmxcsr_m32isd(e, index, scale, disp)      emit_stmxcsr_m32bisd(e, REG_NONE, (index),  (scale), (disp))
4778
4779
4780
4781/***************************************************************************
4782    SSE EMITTERS
4783***************************************************************************/
4784
4785INLINE void emit_sse_r128_r128(x86code **emitptr, UINT32 op, UINT8 dreg, UINT8 sreg)
4786{
4787   emit_op_modrm_reg(emitptr, op, OP_32BIT, dreg, sreg);
4788}
4789
4790INLINE void emit_sse_r128_mbisd(x86code **emitptr, UINT32 op, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4791{
4792   emit_op_modrm_mem(emitptr, op, OP_32BIT, dreg, base, index, scale, disp);
4793}
4794
4795INLINE void emit_sse_r128_r128_rex(x86code **emitptr, UINT32 op, UINT8 dreg, UINT8 sreg)
4796{
4797   emit_op_modrm_reg(emitptr, op, OP_64BIT, dreg, sreg);
4798}
4799
4800INLINE void emit_sse_r128_mbisd_rex(x86code **emitptr, UINT32 op, UINT8 dreg, UINT8 base, UINT8 index, UINT8 scale, INT32 disp)
4801{
4802   emit_op_modrm_mem(emitptr, op, OP_64BIT, dreg, base, index, scale, disp);
4803}
4804
4805
4806
4807/***************************************************************************
4808    SSE SCALAR SINGLE EMITTERS
4809***************************************************************************/
4810
4811#define emit_movss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MOVSS_Vss_Wss, dreg, sreg)
4812#define emit_movss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MOVSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4813#define emit_movss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MOVSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4814#define emit_movss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_MOVSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4815#define emit_movss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MOVSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4816
4817#define emit_movss_m32abs_r128(e, addr, sreg)                     emit_sse_r128_mbisd(e, OP_MOVSS_Wss_Vss, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4818#define emit_movss_m32bd_r128(e, base, disp, sreg)                  emit_sse_r128_mbisd(e, OP_MOVSS_Wss_Vss, sreg, (base),   REG_NONE, 1,       (disp))
4819#define emit_movss_m32isd_r128(e, index, scale, disp, sreg)            emit_sse_r128_mbisd(e, OP_MOVSS_Wss_Vss, sreg, REG_NONE, (index),  (scale), (disp))
4820#define emit_movss_m32bisd_r128(e, base, index, scale, disp, sreg)      emit_sse_r128_mbisd(e, OP_MOVSS_Wss_Vss, sreg, (base),   (index),  (scale), (disp))
4821
4822#define emit_addss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ADDSS_Vss_Wss, dreg, sreg)
4823#define emit_addss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ADDSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4824#define emit_addss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ADDSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4825#define emit_addss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_ADDSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4826#define emit_addss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ADDSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4827
4828#define emit_subss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_SUBSS_Vss_Wss, dreg, sreg)
4829#define emit_subss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SUBSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4830#define emit_subss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SUBSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4831#define emit_subss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_SUBSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4832#define emit_subss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SUBSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4833
4834#define emit_mulss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MULSS_Vss_Wss, dreg, sreg)
4835#define emit_mulss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MULSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4836#define emit_mulss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MULSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4837#define emit_mulss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_MULSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4838#define emit_mulss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MULSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4839
4840#define emit_divss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_DIVSS_Vss_Wss, dreg, sreg)
4841#define emit_divss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_DIVSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4842#define emit_divss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_DIVSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4843#define emit_divss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_DIVSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4844#define emit_divss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_DIVSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4845
4846#define emit_rcpss_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_RCPSS_Vss_Wss, dreg, sreg)
4847#define emit_rcpss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_RCPSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4848#define emit_rcpss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_RCPSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4849#define emit_rcpss_r128_m32isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_RCPSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4850#define emit_rcpss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_RCPSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4851
4852#define emit_sqrtss_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_SQRTSS_Vss_Wss, dreg, sreg)
4853#define emit_sqrtss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SQRTSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4854#define emit_sqrtss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SQRTSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4855#define emit_sqrtss_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SQRTSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4856#define emit_sqrtss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SQRTSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4857
4858#define emit_rsqrtss_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_RSQRTSS_Vss_Wss, dreg, sreg)
4859#define emit_rsqrtss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_RSQRTSS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4860#define emit_rsqrtss_r128_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_RSQRTSS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4861#define emit_rsqrtss_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_RSQRTSS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4862#define emit_rsqrtss_r128_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_RSQRTSS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4863
4864#define emit_comiss_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_COMISS_Vss_Wss, dreg, sreg)
4865#define emit_comiss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_COMISS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4866#define emit_comiss_r128_m32bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_COMISS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4867#define emit_comiss_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_COMISS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4868#define emit_comiss_r128_m32bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_COMISS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4869
4870#define emit_ucomiss_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_UCOMISS_Vss_Wss, dreg, sreg)
4871#define emit_ucomiss_r128_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_UCOMISS_Vss_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4872#define emit_ucomiss_r128_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_UCOMISS_Vss_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4873#define emit_ucomiss_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_UCOMISS_Vss_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4874#define emit_ucomiss_r128_m32bisd(e, dreg, base, index, scale, disp)    emit_sse_r128_mbisd(e, OP_UCOMISS_Vss_Wss, dreg, (base),   (index),  (scale), (disp))
4875
4876#define emit_cvtsi2ss_r128_r32(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSI2SS_Vss_Ed, dreg, sreg)
4877#define emit_cvtsi2ss_r128_m32abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTSI2SS_Vss_Ed, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4878#define emit_cvtsi2ss_r128_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSI2SS_Vss_Ed, dreg, (base),   REG_NONE, 1,       (disp))
4879#define emit_cvtsi2ss_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSI2SS_Vss_Ed, dreg, REG_NONE, (index),  (scale), (disp))
4880#define emit_cvtsi2ss_r128_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSI2SS_Vss_Ed, dreg, (base),   (index),  (scale), (disp))
4881
4882#ifdef PTR64
4883#define emit_cvtsi2ss_r128_r64(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTSI2SS_Vss_Ed, dreg, sreg)
4884#define emit_cvtsi2ss_r128_m64abs(e, dreg, addr)                  emit_sse_r128_mbisd_rex(e, OP_CVTSI2SS_Vss_Ed, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4885#define emit_cvtsi2ss_r128_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTSI2SS_Vss_Ed, dreg, (base),   REG_NONE, 1,       (disp))
4886#define emit_cvtsi2ss_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTSI2SS_Vss_Ed, dreg, REG_NONE, (index),  (scale), (disp))
4887#define emit_cvtsi2ss_r128_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTSI2SS_Vss_Ed, dreg, (base),   (index),  (scale), (disp))
4888#endif
4889
4890#define emit_cvtsd2ss_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSD2SS_Vss_Wsd, dreg, sreg)
4891#define emit_cvtsd2ss_r128_m64abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTSD2SS_Vss_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4892#define emit_cvtsd2ss_r128_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSD2SS_Vss_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
4893#define emit_cvtsd2ss_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSD2SS_Vss_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
4894#define emit_cvtsd2ss_r128_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSD2SS_Vss_Wsd, dreg, (base),   (index),  (scale), (disp))
4895
4896#define emit_cvtss2si_r32_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSS2SI_Gd_Wss, dreg, sreg)
4897#define emit_cvtss2si_r32_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_CVTSS2SI_Gd_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4898#define emit_cvtss2si_r32_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSS2SI_Gd_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4899#define emit_cvtss2si_r32_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSS2SI_Gd_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4900#define emit_cvtss2si_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSS2SI_Gd_Wss, dreg, (base),   (index),  (scale), (disp))
4901
4902#ifdef PTR64
4903#define emit_cvtss2si_r64_r128(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTSS2SI_Gd_Wss, dreg, sreg)
4904#define emit_cvtss2si_r64_m32abs(e, dreg, addr)                     emit_sse_r128_mbisd_rex(e, OP_CVTSS2SI_Gd_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4905#define emit_cvtss2si_r64_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTSS2SI_Gd_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4906#define emit_cvtss2si_r64_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTSS2SI_Gd_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4907#define emit_cvtss2si_r64_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTSS2SI_Gd_Wss, dreg, (base),   (index),  (scale), (disp))
4908#endif
4909
4910#define emit_cvttss2si_r32_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTTSS2SI_Gd_Wss, dreg, sreg)
4911#define emit_cvttss2si_r32_m32abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTTSS2SI_Gd_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4912#define emit_cvttss2si_r32_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTTSS2SI_Gd_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4913#define emit_cvttss2si_r32_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTTSS2SI_Gd_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4914#define emit_cvttss2si_r32_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTTSS2SI_Gd_Wss, dreg, (base),   (index),  (scale), (disp))
4915
4916#ifdef PTR64
4917#define emit_cvttss2si_r64_r128(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTTSS2SI_Gd_Wss, dreg, sreg)
4918#define emit_cvttss2si_r64_m32abs(e, dreg, addr)                  emit_sse_r128_mbisd_rex(e, OP_CVTTSS2SI_Gd_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4919#define emit_cvttss2si_r64_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTTSS2SI_Gd_Wss, dreg, (base),   REG_NONE, 1,       (disp))
4920#define emit_cvttss2si_r64_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTTSS2SI_Gd_Wss, dreg, REG_NONE, (index),  (scale), (disp))
4921#define emit_cvttss2si_r64_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTTSS2SI_Gd_Wss, dreg, (base),   (index),  (scale), (disp))
4922#endif
4923
4924
4925
4926/***************************************************************************
4927    SSE PACKED SINGLE EMITTERS
4928***************************************************************************/
4929
4930#define emit_movps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MOVPS_Vps_Wps, dreg, sreg)
4931#define emit_movps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MOVPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4932#define emit_movps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MOVPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4933#define emit_movps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_MOVPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4934#define emit_movps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MOVPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4935
4936#define emit_movps_m128abs_r128(e, addr, sreg)                     emit_sse_r128_mbisd(e, OP_MOVPS_Wps_Vps, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4937#define emit_movps_m128bd_r128(e, base, disp, sreg)                  emit_sse_r128_mbisd(e, OP_MOVPS_Wps_Vps, sreg, (base),   REG_NONE, 1,       (disp))
4938#define emit_movps_m128isd_r128(e, index, scale, disp, sreg)         emit_sse_r128_mbisd(e, OP_MOVPS_Wps_Vps, sreg, REG_NONE, (index),  (scale), (disp))
4939#define emit_movps_m128bisd_r128(e, base, index, scale, disp, sreg)      emit_sse_r128_mbisd(e, OP_MOVPS_Wps_Vps, sreg, (base),   (index),  (scale), (disp))
4940
4941#define emit_addps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ADDPS_Vps_Wps, dreg, sreg)
4942#define emit_addps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ADDPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4943#define emit_addps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ADDPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4944#define emit_addps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ADDPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4945#define emit_addps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ADDPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4946
4947#define emit_subps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_SUBPS_Vps_Wps, dreg, sreg)
4948#define emit_subps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SUBPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4949#define emit_subps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SUBPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4950#define emit_subps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SUBPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4951#define emit_subps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SUBPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4952
4953#define emit_mulps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MULPS_Vps_Wps, dreg, sreg)
4954#define emit_mulps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MULPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4955#define emit_mulps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MULPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4956#define emit_mulps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_MULPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4957#define emit_mulps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MULPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4958
4959#define emit_divps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_DIVPS_Vps_Wps, dreg, sreg)
4960#define emit_divps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_DIVPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4961#define emit_divps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_DIVPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4962#define emit_divps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_DIVPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4963#define emit_divps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_DIVPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4964
4965#define emit_rcpps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_RCPPS_Vps_Wps, dreg, sreg)
4966#define emit_rcpps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_RCPPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4967#define emit_rcpps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_RCPPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4968#define emit_rcpps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_RCPPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4969#define emit_rcpps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_RCPPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4970
4971#define emit_sqrtps_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_SQRTPS_Vps_Wps, dreg, sreg)
4972#define emit_sqrtps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SQRTPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4973#define emit_sqrtps_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_SQRTPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4974#define emit_sqrtps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SQRTPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4975#define emit_sqrtps_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SQRTPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4976
4977#define emit_rsqrtps_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_RSQRTPS_Vps_Wps, dreg, sreg)
4978#define emit_rsqrtps_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_RSQRTPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4979#define emit_rsqrtps_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_RSQRTPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4980#define emit_rsqrtps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_RSQRTPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4981#define emit_rsqrtps_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_RSQRTPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4982
4983#define emit_andps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ANDPS_Vps_Wps, dreg, sreg)
4984#define emit_andps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ANDPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4985#define emit_andps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ANDPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4986#define emit_andps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ANDPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4987#define emit_andps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ANDPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4988
4989#define emit_andnps_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_ANDNPS_Vps_Wps, dreg, sreg)
4990#define emit_andnps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ANDNPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4991#define emit_andnps_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_ANDNPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4992#define emit_andnps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ANDNPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4993#define emit_andnps_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDNPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
4994
4995#define emit_orps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ORPS_Vps_Wps, dreg, sreg)
4996#define emit_orps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ORPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4997#define emit_orps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ORPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
4998#define emit_orps_r128_m128isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_ORPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
4999#define emit_orps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ORPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
5000
5001#define emit_xorps_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_XORPS_Vps_Wps, dreg, sreg)
5002#define emit_xorps_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_XORPS_Vps_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5003#define emit_xorps_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_XORPS_Vps_Wps, dreg, (base),   REG_NONE, 1,       (disp))
5004#define emit_xorps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_XORPS_Vps_Wps, dreg, REG_NONE, (index),  (scale), (disp))
5005#define emit_xorps_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_XORPS_Vps_Wps, dreg, (base),   (index),  (scale), (disp))
5006
5007#define emit_cvtdq2ps_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTDQ2PS_Vps_Wdq, dreg, sreg)
5008#define emit_cvtdq2ps_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTDQ2PS_Vps_Wdq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5009#define emit_cvtdq2ps_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTDQ2PS_Vps_Wdq, dreg, (base),   REG_NONE, 1,       (disp))
5010#define emit_cvtdq2ps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTDQ2PS_Vps_Wdq, dreg, REG_NONE, (index),  (scale), (disp))
5011#define emit_cvtdq2ps_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTDQ2PS_Vps_Wdq, dreg, (base),   (index),  (scale), (disp))
5012
5013#define emit_cvtpd2ps_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTPD2PS_Vps_Wpd, dreg, sreg)
5014#define emit_cvtpd2ps_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTPD2PS_Vps_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5015#define emit_cvtpd2ps_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTPD2PS_Vps_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5016#define emit_cvtpd2ps_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTPD2PS_Vps_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5017#define emit_cvtpd2ps_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPD2PS_Vps_Wpd, dreg, (base),   (index),  (scale), (disp))
5018
5019#define emit_cvtps2dq_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTPS2DQ_Vdq_Wps, dreg, sreg)
5020#define emit_cvtps2dq_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTPS2DQ_Vdq_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5021#define emit_cvtps2dq_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTPS2DQ_Vdq_Wps, dreg, (base),   REG_NONE, 1,       (disp))
5022#define emit_cvtps2dq_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTPS2DQ_Vdq_Wps, dreg, REG_NONE, (index),  (scale), (disp))
5023#define emit_cvtps2dq_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPS2DQ_Vdq_Wps, dreg, (base),   (index),  (scale), (disp))
5024
5025#define emit_cvttps2dq_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTTPS2DQ_Vdq_Wps, dreg, sreg)
5026#define emit_cvttps2dq_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTTPS2DQ_Vdq_Wps, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5027#define emit_cvttps2dq_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTTPS2DQ_Vdq_Wps, dreg, (base),   REG_NONE, 1,       (disp))
5028#define emit_cvttps2dq_r128_m128isd(e, dreg, index, scale, disp)      emit_sse_r128_mbisd(e, OP_CVTTPS2DQ_Vdq_Wps, dreg, REG_NONE, (index),  (scale), (disp))
5029#define emit_cvttps2dq_r128_m128bisd(e, dreg, base, index, scale, disp) emit_sse_r128_mbisd(e, OP_CVTTPS2DQ_Vdq_Wps, dreg, (base),   (index),  (scale), (disp))
5030
5031
5032
5033/***************************************************************************
5034    SSE SCALAR DOUBLE EMITTERS
5035***************************************************************************/
5036
5037#define emit_movsd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MOVSD_Vsd_Wsd, dreg, sreg)
5038#define emit_movsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MOVSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5039#define emit_movsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MOVSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5040#define emit_movsd_r128_m64isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_MOVSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5041#define emit_movsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MOVSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5042
5043#define emit_movsd_m64abs_r128(e, addr, sreg)                     emit_sse_r128_mbisd(e, OP_MOVSD_Wsd_Vsd, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5044#define emit_movsd_m64bd_r128(e, base, disp, sreg)                  emit_sse_r128_mbisd(e, OP_MOVSD_Wsd_Vsd, sreg, (base),   REG_NONE, 1,       (disp))
5045#define emit_movsd_m64isd_r128(e, index, scale, disp, sreg)            emit_sse_r128_mbisd(e, OP_MOVSD_Wsd_Vsd, sreg, REG_NONE, (index),  (scale), (disp))
5046#define emit_movsd_m64bisd_r128(e, base, index, scale, disp, sreg)      emit_sse_r128_mbisd(e, OP_MOVSD_Wsd_Vsd, sreg, (base),   (index),  (scale), (disp))
5047
5048#define emit_addsd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ADDSD_Vsd_Wsd, dreg, sreg)
5049#define emit_addsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ADDSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5050#define emit_addsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ADDSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5051#define emit_addsd_r128_m64isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_ADDSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5052#define emit_addsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ADDSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5053
5054#define emit_subsd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_SUBSD_Vsd_Wsd, dreg, sreg)
5055#define emit_subsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SUBSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5056#define emit_subsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SUBSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5057#define emit_subsd_r128_m64isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_SUBSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5058#define emit_subsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SUBSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5059
5060#define emit_mulsd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MULSD_Vsd_Wsd, dreg, sreg)
5061#define emit_mulsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MULSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5062#define emit_mulsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MULSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5063#define emit_mulsd_r128_m64isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_MULSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5064#define emit_mulsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MULSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5065
5066#define emit_divsd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_DIVSD_Vsd_Wsd, dreg, sreg)
5067#define emit_divsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_DIVSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5068#define emit_divsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_DIVSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5069#define emit_divsd_r128_m64isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_DIVSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5070#define emit_divsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_DIVSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5071
5072#define emit_sqrtsd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_SQRTSD_Vsd_Wsd, dreg, sreg)
5073#define emit_sqrtsd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SQRTSD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5074#define emit_sqrtsd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SQRTSD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5075#define emit_sqrtsd_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SQRTSD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5076#define emit_sqrtsd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SQRTSD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5077
5078#define emit_comisd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_COMISD_Vsd_Wsd, dreg, sreg)
5079#define emit_comisd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_COMISD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5080#define emit_comisd_r128_m64bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_COMISD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5081#define emit_comisd_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_COMISD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5082#define emit_comisd_r128_m64bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_COMISD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5083
5084#define emit_ucomisd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_UCOMISD_Vsd_Wsd, dreg, sreg)
5085#define emit_ucomisd_r128_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_UCOMISD_Vsd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5086#define emit_ucomisd_r128_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_UCOMISD_Vsd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5087#define emit_ucomisd_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_UCOMISD_Vsd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5088#define emit_ucomisd_r128_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_UCOMISD_Vsd_Wsd, dreg, (base),   (index),  (scale), (disp))
5089
5090#define emit_cvtsi2sd_r128_r32(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSI2SD_Vsd_Ed, dreg, sreg)
5091#define emit_cvtsi2sd_r128_m32abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTSI2SD_Vsd_Ed, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5092#define emit_cvtsi2sd_r128_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSI2SD_Vsd_Ed, dreg, (base),   REG_NONE, 1,       (disp))
5093#define emit_cvtsi2sd_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSI2SD_Vsd_Ed, dreg, REG_NONE, (index),  (scale), (disp))
5094#define emit_cvtsi2sd_r128_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSI2SD_Vsd_Ed, dreg, (base),   (index),  (scale), (disp))
5095
5096#ifdef PTR64
5097#define emit_cvtsi2sd_r128_r64(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTSI2SD_Vsd_Ed, dreg, sreg)
5098#define emit_cvtsi2sd_r128_m64abs(e, dreg, addr)                  emit_sse_r128_mbisd_rex(e, OP_CVTSI2SD_Vsd_Ed, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5099#define emit_cvtsi2sd_r128_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTSI2SD_Vsd_Ed, dreg, (base),   REG_NONE, 1,       (disp))
5100#define emit_cvtsi2sd_r128_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTSI2SD_Vsd_Ed, dreg, REG_NONE, (index),  (scale), (disp))
5101#define emit_cvtsi2sd_r128_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTSI2SD_Vsd_Ed, dreg, (base),   (index),  (scale), (disp))
5102#endif
5103
5104#define emit_cvtss2sd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSS2SD_Vsd_Wss, dreg, sreg)
5105#define emit_cvtss2sd_r128_m32abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTSS2SD_Vsd_Wss, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5106#define emit_cvtss2sd_r128_m32bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSS2SD_Vsd_Wss, dreg, (base),   REG_NONE, 1,       (disp))
5107#define emit_cvtss2sd_r128_m32isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSS2SD_Vsd_Wss, dreg, REG_NONE, (index),  (scale), (disp))
5108#define emit_cvtss2sd_r128_m32bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSS2SD_Vsd_Wss, dreg, (base),   (index),  (scale), (disp))
5109
5110#define emit_cvtsd2si_r32_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTSD2SI_Gd_Wsd, dreg, sreg)
5111#define emit_cvtsd2si_r32_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_CVTSD2SI_Gd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5112#define emit_cvtsd2si_r32_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTSD2SI_Gd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5113#define emit_cvtsd2si_r32_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTSD2SI_Gd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5114#define emit_cvtsd2si_r32_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTSD2SI_Gd_Wsd, dreg, (base),   (index),  (scale), (disp))
5115
5116#ifdef PTR64
5117#define emit_cvtsd2si_r64_r128(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTSD2SI_Gd_Wsd, dreg, sreg)
5118#define emit_cvtsd2si_r64_m64abs(e, dreg, addr)                     emit_sse_r128_mbisd_rex(e, OP_CVTSD2SI_Gd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5119#define emit_cvtsd2si_r64_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTSD2SI_Gd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5120#define emit_cvtsd2si_r64_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTSD2SI_Gd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5121#define emit_cvtsd2si_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTSD2SI_Gd_Wsd, dreg, (base),   (index),  (scale), (disp))
5122#endif
5123
5124#define emit_cvttsd2si_r32_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTTSD2SI_Gd_Wsd, dreg, sreg)
5125#define emit_cvttsd2si_r32_m64abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTTSD2SI_Gd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5126#define emit_cvttsd2si_r32_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTTSD2SI_Gd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5127#define emit_cvttsd2si_r32_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTTSD2SI_Gd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5128#define emit_cvttsd2si_r32_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTTSD2SI_Gd_Wsd, dreg, (base),   (index),  (scale), (disp))
5129
5130#ifdef PTR64
5131#define emit_cvttsd2si_r64_r128(e, dreg, sreg)                     emit_sse_r128_r128_rex(e, OP_CVTTSD2SI_Gd_Wsd, dreg, sreg)
5132#define emit_cvttsd2si_r64_m64abs(e, dreg, addr)                  emit_sse_r128_mbisd_rex(e, OP_CVTTSD2SI_Gd_Wsd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5133#define emit_cvttsd2si_r64_m64bd(e, dreg, base, disp)               emit_sse_r128_mbisd_rex(e, OP_CVTTSD2SI_Gd_Wsd, dreg, (base),   REG_NONE, 1,       (disp))
5134#define emit_cvttsd2si_r64_m64isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd_rex(e, OP_CVTTSD2SI_Gd_Wsd, dreg, REG_NONE, (index),  (scale), (disp))
5135#define emit_cvttsd2si_r64_m64bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd_rex(e, OP_CVTTSD2SI_Gd_Wsd, dreg, (base),   (index),  (scale), (disp))
5136#endif
5137
5138
5139
5140/***************************************************************************
5141    SSE PACKED DOUBLE EMITTERS
5142***************************************************************************/
5143
5144#define emit_movpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_MOVPD_Vpd_Wpd, dreg, sreg)
5145#define emit_movpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5146#define emit_movpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5147#define emit_movpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5148
5149#define emit_movpd_m128abs_r128(e, addr, sreg)               emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5150#define emit_movpd_m128bd_r128(e, base, disp, sreg)            emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, (base),   REG_NONE, 1,       (disp))
5151#define emit_movpd_m128isd_r128(e, index, scale, disp, sreg)   emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, (index),  (scale), (disp))
5152
5153#define emit_addpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ADDPD_Vpd_Wpd, dreg, sreg)
5154#define emit_addpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5155#define emit_addpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5156#define emit_addpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5157
5158#define emit_subpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_SUBPD_Vpd_Wpd, dreg, sreg)
5159#define emit_subpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5160#define emit_subpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5161#define emit_subpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5162
5163#define emit_mulpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_MULPD_Vpd_Wpd, dreg, sreg)
5164#define emit_mulpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5165#define emit_mulpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5166#define emit_mulpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5167
5168#define emit_divpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_DIVPD_Vpd_Wpd, dreg, sreg)
5169#define emit_divpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5170#define emit_divpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5171#define emit_divpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5172
5173#define emit_sqrtpd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_SQRTPD_Vpd_Wpd, dreg, sreg)
5174#define emit_sqrtpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5175#define emit_sqrtpd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5176#define emit_sqrtpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5177
5178#define emit_andpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ANDPD_Vpd_Wpd, dreg, sreg)
5179#define emit_andpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5180#define emit_andpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5181#define emit_andpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5182
5183#define emit_andnpd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_ANDNPD_Vpd_Wpd, dreg, sreg)
5184#define emit_andnpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5185#define emit_andnpd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5186#define emit_andnpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5187
5188#define emit_orpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ORPD_Vpd_Wpd, dreg, sreg)
5189#define emit_orpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5190#define emit_orpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5191#define emit_orpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5192
5193#define emit_xorpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_XORPD_Vpd_Wpd, dreg, sreg)
5194#define emit_xorpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5195#define emit_xorpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5196#define emit_xorpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5197
5198#define emit_cvtdq2pd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTDQ2PD_Vpd_Wq, dreg, sreg)
5199#define emit_cvtdq2pd_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5200#define emit_cvtdq2pd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
5201#define emit_cvtdq2pd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
5202
5203#define emit_cvtps2pd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTPS2PD_Vpd_Wq, dreg, sreg)
5204#define emit_cvtps2pd_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5205#define emit_cvtps2pd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
5206#define emit_cvtps2pd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
5207
5208#define emit_cvtpd2dq_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, sreg)
5209#define emit_cvtpd2dq_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5210#define emit_cvtpd2dq_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5211#define emit_cvtpd2dq_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5212
5213#define emit_cvttpd2dq_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, sreg)
5214#define emit_cvttpd2dq_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
5215#define emit_cvttpd2dq_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
5216#define emit_cvttpd2dq_r128_m128isd(e, dreg, index, scale, disp) emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
5217/***************************************************************************
5218
5219    x86emit.h
5220
5221    Generic x86/x64 code emitters.
5222
5223    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
5224    Visit http://mamedev.org for licensing and usage restrictions.
5225
5226****************************************************************************
5227
5228    Important note:
5229
5230    It is assumed in 64-bit mode that all byte register accesses are
5231    intended to be to the low 8 bits (SPL,BPL,SIL,DIL) and not to the
5232    upper half (AH,CH,DH,BH).
5233
5234***************************************************************************/
5235
5236
5237/***************************************************************************
5238    CONSTANTS
5239***************************************************************************/
5240
5241/* 32-bit versus 64-bit opcode flag */
5242#define OP_32BIT               0
5243#define OP_64BIT            8
5244
5245
5246/* 16 registers on x64, only 8 on x86 */
5247#ifdef PTR64
5248#define REG_MAX               16
5249#else
5250#define REG_MAX               8
5251#endif
5252
5253
5254/* invalid register index for "none" */
5255#define REG_NONE            REG_MAX
5256
5257
5258/* 64-bit registers */
5259#ifdef PTR64
5260#define REG_RAX               0
5261#define REG_RCX               1
5262#define REG_RDX               2
5263#define REG_RBX               3
5264#define REG_RSP               4
5265#define REG_RBP               5
5266#define REG_RSI               6
5267#define REG_RDI               7
5268#define REG_R8               8
5269#define REG_R9               9
5270#define REG_R10               10
5271#define REG_R11               11
5272#define REG_R12               12
5273#define REG_R13               13
5274#define REG_R14               14
5275#define REG_R15               15
5276#endif
5277
5278/* 32-bit registers */
5279#define REG_EAX               0
5280#define REG_ECX               1
5281#define REG_EDX               2
5282#define REG_EBX               3
5283#define REG_ESP               4
5284#define REG_EBP               5
5285#define REG_ESI               6
5286#define REG_EDI               7
5287#ifdef PTR64
5288#define REG_R8D               8
5289#define REG_R9D               9
5290#define REG_R10D            10
5291#define REG_R11D            11
5292#define REG_R12D            12
5293#define REG_R13D            13
5294#define REG_R14D            14
5295#define REG_R15D            15
5296#endif
5297
5298/* 16-bit registers */
5299#define REG_AX               0
5300#define REG_CX               1
5301#define REG_DX               2
5302#define REG_BX               3
5303#define REG_SP               4
5304#define REG_BP               5
5305#define REG_SI               6
5306#define REG_DI               7
5307#ifdef PTR64
5308#define REG_R8W               8
5309#define REG_R9W               9
5310#define REG_R10W            10
5311#define REG_R11W            11
5312#define REG_R12W            12
5313#define REG_R13W            13
5314#define REG_R14W            14
5315#define REG_R15W            15
5316#endif
5317
5318/* 8-bit registers */
5319#define REG_AL               0
5320#define REG_CL               1
5321#define REG_DL               2
5322#define REG_BL               3
5323#ifndef PTR64
5324#define REG_AH               4
5325#define REG_CH               5
5326#define REG_DH               6
5327#define REG_BH               7
5328#else
5329#define REG_SPL               4
5330#define REG_BPL               5
5331#define REG_SIL               6
5332#define REG_DIL               7
5333#define REG_R8L               8
5334#define REG_R9L               9
5335#define REG_R10L            10
5336#define REG_R11L            11
5337#define REG_R12L            12
5338#define REG_R13L            13
5339#define REG_R14L            14
5340#define REG_R15L            15
5341#endif
5342
5343/* 64-bit MMX registers */
5344#define REG_MM0               0
5345#define REG_MM1               1
5346#define REG_MM2               2
5347#define REG_MM3               3
5348#define REG_MM4               4
5349#define REG_MM5               5
5350#define REG_MM6               6
5351#define REG_MM7               7
5352#ifdef PTR64
5353#define REG_MM8               8
5354#define REG_MM9               9
5355#define REG_MM10            10
5356#define REG_MM11            11
5357#define REG_MM12            12
5358#define REG_MM13            13
5359#define REG_MM14            14
5360#define REG_MM15            15
5361#endif
5362
5363/* 128-bit XMM registers */
5364#define REG_XMM0            0
5365#define REG_XMM1            1
5366#define REG_XMM2            2
5367#define REG_XMM3            3
5368#define REG_XMM4            4
5369#define REG_XMM5            5
5370#define REG_XMM6            6
5371#define REG_XMM7            7
5372#ifdef PTR64
5373#define REG_XMM8            8
5374#define REG_XMM9            9
5375#define REG_XMM10            10
5376#define REG_XMM11            11
5377#define REG_XMM12            12
5378#define REG_XMM13            13
5379#define REG_XMM14            14
5380#define REG_XMM15            15
5381#endif
5382
5383
5384/* conditions */
5385#define COND_A               7
5386#define COND_AE               3
5387#define COND_B               2
5388#define COND_BE               6
5389#define COND_C               2
5390#define COND_E               4
5391#define COND_Z               4
5392#define COND_G               15
5393#define COND_GE               13
5394#define COND_L               12
5395#define COND_LE               14
5396#define COND_NA               6
5397#define COND_NAE            2
5398#define COND_NB               3
5399#define COND_NBE            7
5400#define COND_NC               3
5401#define COND_NE               5
5402#define COND_NG               14
5403#define COND_NGE            12
5404#define COND_NL               13
5405#define COND_NLE            15
5406#define COND_NO               1
5407#define COND_NP               11
5408#define COND_NS               9
5409#define COND_NZ               5
5410#define COND_O               0
5411#define COND_P               10
5412#define COND_PE               10
5413#define COND_PO               11
5414#define COND_S               8
5415#define COND_Z               4
5416
5417
5418/* floating point rounding modes */
2035419#define FPRND_NEAR   0
2045420#define FPRND_DOWN   1
2055421#define FPRND_UP   2
r936r937
45929808    SSE PACKED DOUBLE EMITTERS
45939809***************************************************************************/
45949810
4595#define emit_movpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_MOVPD_Vpd_Wpd, dreg, sreg)
4596#define emit_movpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4597#define emit_movpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4598#define emit_movpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9811#define emit_movpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MOVPD_Vpd_Wpd, dreg, sreg)
9812#define emit_movpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9813#define emit_movpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9814#define emit_movpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9815#define emit_movpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MOVPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
45999816
4600#define emit_movpd_m128abs_r128(e, addr, sreg)               emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4601#define emit_movpd_m128bd_r128(e, base, disp, sreg)            emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, (base),   REG_NONE, 1,       (disp))
4602#define emit_movpd_m128isd_r128(e, index, scale, disp, sreg)   emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, (index),  (scale), (disp))
9817#define emit_movpd_m128abs_r128(e, addr, sreg)                     emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9818#define emit_movpd_m128bd_r128(e, base, disp, sreg)                  emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, (base),   REG_NONE, 1,       (disp))
9819#define emit_movpd_m128isd_r128(e, index, scale, disp, sreg)         emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, REG_NONE, (index),  (scale), (disp))
9820#define emit_movpd_m128bisd_r128(e, base, index, scale, disp, sreg)      emit_sse_r128_mbisd(e, OP_MOVPD_Wpd_Vpd, sreg, (base),   (index),  (scale), (disp))
46039821
4604#define emit_addpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ADDPD_Vpd_Wpd, dreg, sreg)
4605#define emit_addpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4606#define emit_addpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4607#define emit_addpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9822#define emit_addpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ADDPD_Vpd_Wpd, dreg, sreg)
9823#define emit_addpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9824#define emit_addpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9825#define emit_addpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9826#define emit_addpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ADDPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46089827
4609#define emit_subpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_SUBPD_Vpd_Wpd, dreg, sreg)
4610#define emit_subpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4611#define emit_subpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4612#define emit_subpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9828#define emit_subpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_SUBPD_Vpd_Wpd, dreg, sreg)
9829#define emit_subpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9830#define emit_subpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9831#define emit_subpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9832#define emit_subpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_SUBPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46139833
4614#define emit_mulpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_MULPD_Vpd_Wpd, dreg, sreg)
4615#define emit_mulpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4616#define emit_mulpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4617#define emit_mulpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9834#define emit_mulpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_MULPD_Vpd_Wpd, dreg, sreg)
9835#define emit_mulpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9836#define emit_mulpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9837#define emit_mulpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9838#define emit_mulpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_MULPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46189839
4619#define emit_divpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_DIVPD_Vpd_Wpd, dreg, sreg)
4620#define emit_divpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4621#define emit_divpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4622#define emit_divpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9840#define emit_divpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_DIVPD_Vpd_Wpd, dreg, sreg)
9841#define emit_divpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9842#define emit_divpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9843#define emit_divpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9844#define emit_divpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_DIVPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46239845
4624#define emit_sqrtpd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_SQRTPD_Vpd_Wpd, dreg, sreg)
4625#define emit_sqrtpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4626#define emit_sqrtpd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4627#define emit_sqrtpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9846#define emit_sqrtpd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_SQRTPD_Vpd_Wpd, dreg, sreg)
9847#define emit_sqrtpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9848#define emit_sqrtpd_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9849#define emit_sqrtpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9850#define emit_sqrtpd_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_SQRTPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46289851
4629#define emit_andpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ANDPD_Vpd_Wpd, dreg, sreg)
4630#define emit_andpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4631#define emit_andpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4632#define emit_andpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9852#define emit_andpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ANDPD_Vpd_Wpd, dreg, sreg)
9853#define emit_andpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9854#define emit_andpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9855#define emit_andpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9856#define emit_andpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ANDPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46339857
4634#define emit_andnpd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_ANDNPD_Vpd_Wpd, dreg, sreg)
4635#define emit_andnpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4636#define emit_andnpd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4637#define emit_andnpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9858#define emit_andnpd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_ANDNPD_Vpd_Wpd, dreg, sreg)
9859#define emit_andnpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9860#define emit_andnpd_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9861#define emit_andnpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9862#define emit_andnpd_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ANDNPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46389863
4639#define emit_orpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_ORPD_Vpd_Wpd, dreg, sreg)
4640#define emit_orpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4641#define emit_orpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4642#define emit_orpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9864#define emit_orpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_ORPD_Vpd_Wpd, dreg, sreg)
9865#define emit_orpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9866#define emit_orpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9867#define emit_orpd_r128_m128isd(e, dreg, index, scale, disp)            emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9868#define emit_orpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_ORPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46439869
4644#define emit_xorpd_r128_r128(e, dreg, sreg)                  emit_sse_r128_r128(e, OP_XORPD_Vpd_Wpd, dreg, sreg)
4645#define emit_xorpd_r128_m128abs(e, dreg, addr)               emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4646#define emit_xorpd_r128_m128bd(e, dreg, base, disp)            emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4647#define emit_xorpd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9870#define emit_xorpd_r128_r128(e, dreg, sreg)                        emit_sse_r128_r128(e, OP_XORPD_Vpd_Wpd, dreg, sreg)
9871#define emit_xorpd_r128_m128abs(e, dreg, addr)                     emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9872#define emit_xorpd_r128_m128bd(e, dreg, base, disp)                  emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9873#define emit_xorpd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9874#define emit_xorpd_r128_m128bisd(e, dreg, base, index, scale, disp)      emit_sse_r128_mbisd(e, OP_XORPD_Vpd_Wpd, dreg, (base),   (index),  (scale), (disp))
46489875
4649#define emit_cvtdq2pd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTDQ2PD_Vpd_Wq, dreg, sreg)
4650#define emit_cvtdq2pd_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4651#define emit_cvtdq2pd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
4652#define emit_cvtdq2pd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
9876#define emit_cvtdq2pd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTDQ2PD_Vpd_Wq, dreg, sreg)
9877#define emit_cvtdq2pd_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9878#define emit_cvtdq2pd_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
9879#define emit_cvtdq2pd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
9880#define emit_cvtdq2pd_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTDQ2PD_Vpd_Wq, dreg, (base),   (index),  (scale), (disp))
46539881
4654#define emit_cvtps2pd_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTPS2PD_Vpd_Wq, dreg, sreg)
4655#define emit_cvtps2pd_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4656#define emit_cvtps2pd_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
4657#define emit_cvtps2pd_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
9882#define emit_cvtps2pd_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTPS2PD_Vpd_Wq, dreg, sreg)
9883#define emit_cvtps2pd_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9884#define emit_cvtps2pd_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, (base),   REG_NONE, 1,       (disp))
9885#define emit_cvtps2pd_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, REG_NONE, (index),  (scale), (disp))
9886#define emit_cvtps2pd_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPS2PD_Vpd_Wq, dreg, (base),   (index),  (scale), (disp))
46589887
4659#define emit_cvtpd2dq_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, sreg)
4660#define emit_cvtpd2dq_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4661#define emit_cvtpd2dq_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4662#define emit_cvtpd2dq_r128_m128isd(e, dreg, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9888#define emit_cvtpd2dq_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, sreg)
9889#define emit_cvtpd2dq_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9890#define emit_cvtpd2dq_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9891#define emit_cvtpd2dq_r128_m128isd(e, dreg, index, scale, disp)         emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9892#define emit_cvtpd2dq_r128_m128bisd(e, dreg, base, index, scale, disp)   emit_sse_r128_mbisd(e, OP_CVTPD2DQ_Vdq_Wpd, dreg, (base),   (index),  (scale), (disp))
46639893
4664#define emit_cvttpd2dq_r128_r128(e, dreg, sreg)               emit_sse_r128_r128(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, sreg)
4665#define emit_cvttpd2dq_r128_m128abs(e, dreg, addr)            emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
4666#define emit_cvttpd2dq_r128_m128bd(e, dreg, base, disp)         emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
4667#define emit_cvttpd2dq_r128_m128isd(e, dreg, index, scale, disp) emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9894#define emit_cvttpd2dq_r128_r128(e, dreg, sreg)                     emit_sse_r128_r128(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, sreg)
9895#define emit_cvttpd2dq_r128_m128abs(e, dreg, addr)                  emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, REG_NONE, 1,       (INT32)(addr))
9896#define emit_cvttpd2dq_r128_m128bd(e, dreg, base, disp)               emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, (base),   REG_NONE, 1,       (disp))
9897#define emit_cvttpd2dq_r128_m128isd(e, dreg, index, scale, disp)       emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, REG_NONE, (index),  (scale), (disp))
9898#define emit_cvttpd2dq_r128_m128bisd(e, dreg, base, index, scale, disp) emit_sse_r128_mbisd(e, OP_CVTTPD2DQ_Vdq_Wpd, dreg, (base),   (index),  (scale), (disp))
src/emu/cpu/arm7/arm7dasm.c
r936r937
4444   return pBuf;
4545}
4646
47static char *DasmCoProc_RT( char *pBuf, UINT32 opcode, char *pConditionCode, char *pBuf0)
47static char *DasmCoProc_RT( char *pBuf, UINT32 opcode, const char *pConditionCode, const char *pBuf0)
4848{
4949   /* co processor register transfer */
5050   /* xxxx 1110 oooL nnnn dddd cccc ppp1 mmmm */
r936r937
6464   return pBuf;
6565}
6666
67static char *DasmCoProc_DT( char *pBuf, UINT32 opcode, char *pConditionCode, char *pBuf0 )
67static char *DasmCoProc_DT( char *pBuf, UINT32 opcode, const char *pConditionCode, const char *pBuf0 )
6868{
6969   /* co processor data transfer */
7070   /* xxxx 111P UNWL nnnn dddd pppp oooooooo */
r936r937
8989   return pBuf;
9090}
9191
92static char *DasmCoProc_DO( char *pBuf, UINT32 opcode, char *pConditionCode, char *pBuf0 )
92static char *DasmCoProc_DO( char *pBuf, UINT32 opcode, const char *pConditionCode, const char *pBuf0 )
9393{
9494   /* co processor data operation */
9595   /* xxxx 1110 oooo nnnn dddd cccc ppp0 mmmm */
r936r937
601601         if(arm7_dasm_cop_rt_callback)
602602            arm7_dasm_cop_rt_callback(pBuf,opcode,(char*)pConditionCode,(char*)pBuf0);
603603         else
604            DasmCoProc_RT(pBuf,opcode,(char*)pConditionCode,(char*)pBuf0);
604            DasmCoProc_RT(pBuf,opcode,pConditionCode,pBuf0);
605605      }
606606      //Data Op
607607      else
r936r937
609609         if(arm7_dasm_cop_do_callback)
610610            arm7_dasm_cop_do_callback(pBuf,opcode,(char*)pConditionCode,(char*)pBuf0);
611611         else
612            DasmCoProc_DO(pBuf,opcode,(char*)pConditionCode,(char*)pBuf0);
612            DasmCoProc_DO(pBuf,opcode,pConditionCode,pBuf0);
613613      }
614614   }
615615   else if( (opcode&0x0f000000) == 0x0f000000 )   //bits 27-24 == 1111
src/emu/memconv.h
r936r937
77    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
88    Visit http://mamedev.org for licensing and usage restrictions.
99
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
1080***************************************************************************/
1181
82/*************************************
83 *
84 *  16-bit BE using 8-bit handlers
85 *
86 *************************************/
1287
88INLINE UINT16 read16be_with_read8_handler(read8_handler handler, offs_t offset, UINT16 mem_mask)
89{
90   UINT16 result = 0;
91   if ((mem_mask & 0xff00) != 0xff00)
92      result |= ((UINT16)(*handler)(offset * 2 + 0)) << 8;
93   if ((mem_mask & 0x00ff) != 0x00ff)
94      result |= ((UINT16)(*handler)(offset * 2 + 1)) << 0;
95   return result;
96}
97
98
99INLINE void write16be_with_write8_handler(write8_handler handler, offs_t offset, UINT16 data, UINT16 mem_mask)
100{
101   if ((mem_mask & 0xff00) != 0xff00)
102      (*handler)(offset * 2 + 0, data >> 8);
103   if ((mem_mask & 0x00ff) != 0x00ff)
104      (*handler)(offset * 2 + 1, data >> 0);
105}
106
107
13108/*************************************
14109 *
15110 *  16-bit LE using 8-bit handlers
r936r937
20115{
21116   UINT16 result = 0;
22117   if ((mem_mask & 0x00ff) != 0x00ff)
23      result |= ((UINT16) handler(offset * 2 + 0)) << 0;
118      result |= ((UINT16) (*handler)(offset * 2 + 0)) << 0;
24119   if ((mem_mask & 0xff00) != 0xff00)
25      result |= ((UINT16) handler(offset * 2 + 1)) << 8;
120      result |= ((UINT16) (*handler)(offset * 2 + 1)) << 8;
26121   return result;
27122}
28123
r936r937
30125INLINE void write16le_with_write8_handler(write8_handler handler, offs_t offset, UINT16 data, UINT16 mem_mask)
31126{
32127   if ((mem_mask & 0x00ff) != 0x00ff)
33      handler(offset * 2 + 0, data >> 0);
128      (*handler)(offset * 2 + 0, data >> 0);
34129   if ((mem_mask & 0xff00) != 0xff00)
35      handler(offset * 2 + 1, data >> 8);
130      (*handler)(offset * 2 + 1, data >> 8);
36131}
37132
38133
134/*************************************
135 *
136 *  32-bit BE using 8-bit handlers
137 *
138 *************************************/
39139
140INLINE UINT32 read32be_with_read8_handler(read8_handler handler, offs_t offset, UINT32 mem_mask)
141{
142   UINT32 result = 0;
143   if ((mem_mask & 0xffff0000) != 0xffff0000)
144      result |= read16be_with_read8_handler(handler, offset * 2 + 0, mem_mask >> 16) << 16;
145   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
146      result |= read16be_with_read8_handler(handler, offset * 2 + 1, mem_mask) << 0;
147   return result;
148}
149
150
151INLINE void write32be_with_write8_handler(write8_handler handler, offs_t offset, UINT32 data, UINT32 mem_mask)
152{
153   if ((mem_mask & 0xffff0000) != 0xffff0000)
154      write16be_with_write8_handler(handler, offset * 2 + 0, data >> 16, mem_mask >> 16);
155   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
156      write16be_with_write8_handler(handler, offset * 2 + 1, data, mem_mask);
157}
158
159
40160/*************************************
41161 *
42162 *  32-bit LE using 8-bit handlers
r936r937
63183}
64184
65185
186/*************************************
187 *
188 *  32-bit BE using 16-bit BE handlers
189 *
190 *************************************/
66191
192INLINE UINT32 read32be_with_16be_handler(read16_handler handler, offs_t offset, UINT32 mem_mask)
193{
194   UINT32 result = 0;
195   if ((mem_mask & 0xffff0000) != 0xffff0000)
196      result |= (*handler)(offset * 2 + 0, mem_mask >> 16) << 16;
197   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
198      result |= (*handler)(offset * 2 + 1, mem_mask) << 0;
199   return result;
200}
201
202
203INLINE void write32be_with_16be_handler(write16_handler handler, offs_t offset, UINT32 data, UINT32 mem_mask)
204{
205   if ((mem_mask & 0xffff0000) != 0xffff0000)
206      (*handler)(offset * 2 + 0, data >> 16, mem_mask >> 16);
207   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
208      (*handler)(offset * 2 + 1, data, mem_mask);
209}
210
211
67212/*************************************
68213 *
214 *  32-bit LE using 16-bit LE handlers
215 *
216 *************************************/
217
218INLINE UINT32 read32le_with_16le_handler(read16_handler handler, offs_t offset, UINT32 mem_mask)
219{
220   UINT32 result = 0;
221   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
222      result |= (*handler)(offset * 2 + 0, mem_mask) << 0;
223   if ((mem_mask & 0xffff0000) != 0xffff0000)
224      result |= (*handler)(offset * 2 + 1, mem_mask >> 16) << 16;
225   return result;
226}
227
228
229INLINE void write32le_with_16le_handler(write16_handler handler, offs_t offset, UINT32 data, UINT32 mem_mask)
230{
231   if ((mem_mask & 0x0000ffff) != 0x0000ffff)
232      (*handler)(offset * 2 + 0, data, mem_mask);
233   if ((mem_mask & 0xffff0000) != 0xffff0000)
234      (*handler)(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_handler handler, 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, offset, mem_mask);
249   return FLIPENDIAN_INT32(result);
250}
251
252
253INLINE void write32be_with_16le_handler(write16_handler handler, 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, 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_handler handler, 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, offset, mem_mask);
272   return FLIPENDIAN_INT32(result);
273}
274
275
276INLINE void write32le_with_16be_handler(write16_handler handler, 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, offset, data, mem_mask);
281}
282
283
284/*************************************
285 *
69286 *  64-bit BE using 8-bit handlers
70287 *
71288 *************************************/
r936r937
73290INLINE UINT64 read64be_with_read8_handler(read8_handler handler, offs_t offset, UINT64 mem_mask)
74291{
75292   UINT64 result = 0;
76   int i;
77
78   for (i = 0; i < 8; i++)
79   {
80      if (((mem_mask >> (56 - i * 8)) & 0xff) == 0)
81         result |= ((UINT64) handler(offset * 8 + i)) << (56 - i * 8);
82   }
293   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
294      result |= (UINT64)read32be_with_read8_handler(handler, offset * 2 + 0, mem_mask >> 32) << 32;
295   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
296      result |= (UINT64)read32be_with_read8_handler(handler, offset * 2 + 1, mem_mask) << 0;
83297   return result;
84298}
85299
300
86301INLINE void write64be_with_write8_handler(write8_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
87302{
88   int i;
303   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
304      write32be_with_write8_handler(handler, offset * 2 + 0, data >> 32, mem_mask >> 32);
305   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
306      write32be_with_write8_handler(handler, offset * 2 + 1, data, mem_mask);
307}
89308
90   for (i = 0; i < 8; i++)
91   {
92      if (((mem_mask >> (56 - i * 8)) & 0xff) == 0)
93         handler(offset * 8 + i, data >> (56 - i * 8));
94   }
309
310/*************************************
311 *
312 *  64-bit LE using 8-bit handlers
313 *
314 *************************************/
315
316INLINE UINT64 read64le_with_read8_handler(read8_handler handler, offs_t offset, UINT64 mem_mask)
317{
318   UINT64 result = 0;
319   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
320      result |= (UINT64)read32le_with_read8_handler(handler, offset * 2 + 0, mem_mask >> 0) << 0;
321   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
322      result |= (UINT64)read32le_with_read8_handler(handler, offset * 2 + 1, mem_mask >> 32) << 32;
323   return result;
95324}
96325
97326
327INLINE void write64le_with_write8_handler(write8_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
328{
329   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
330      write32le_with_write8_handler(handler, offset * 2 + 0, data >> 0, mem_mask >> 0);
331   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
332      write32le_with_write8_handler(handler, offset * 2 + 1, data >> 32, mem_mask >> 32);
333}
98334
335
99336/*************************************
100337 *
338 *  64-bit BE using 16-bit BE handlers
339 *
340 *************************************/
341
342INLINE UINT32 read64be_with_16be_handler(read16_handler handler, offs_t offset, UINT64 mem_mask)
343{
344   UINT64 result = 0;
345   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
346      result |= (UINT64)read32be_with_16be_handler(handler, offset * 2 + 0, mem_mask >> 32) << 32;
347   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
348      result |= (UINT64)read32be_with_16be_handler(handler, offset * 2 + 1, mem_mask >> 0) << 0;
349   return result;
350}
351
352
353INLINE void write64be_with_16be_handler(write16_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
354{
355   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
356      write32be_with_16be_handler(handler, offset * 2 + 0, data >> 32, mem_mask >> 32);
357   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
358      write32be_with_16be_handler(handler, 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_handler handler, offs_t offset, UINT64 mem_mask)
369{
370   UINT64 result = 0;
371   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
372      result |= (UINT64)read32le_with_16le_handler(handler, offset * 2 + 0, mem_mask >> 0) << 0;
373   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
374      result |= (UINT64)read32le_with_16le_handler(handler, offset * 2 + 1, mem_mask >> 32) << 32;
375   return result;
376}
377
378
379INLINE void write64le_with_16le_handler(write16_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
380{
381   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
382      write32le_with_16le_handler(handler, offset * 2 + 0, data >> 0, mem_mask >> 0);
383   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
384      write32le_with_16le_handler(handler, 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_handler handler, offs_t offset, UINT64 mem_mask)
395{
396   UINT64 result = 0;
397   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
398      result |= (UINT64)read32be_with_16le_handler(handler, offset * 2 + 0, mem_mask >> 32) << 32;
399   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
400      result |= (UINT64)read32be_with_16le_handler(handler, offset * 2 + 1, mem_mask >> 0) << 0;
401   return result;
402}
403
404
405INLINE void write64be_with_16le_handler(write16_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
406{
407   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
408      write32be_with_16le_handler(handler, offset * 2 + 0, data >> 32, mem_mask >> 32);
409   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
410      write32be_with_16le_handler(handler, 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_handler handler, offs_t offset, UINT64 mem_mask)
421{
422   UINT64 result = 0;
423   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
424      result |= (UINT64)read32le_with_16be_handler(handler, offset * 2 + 0, mem_mask >> 0) << 0;
425   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
426      result |= (UINT64)read32le_with_16be_handler(handler, offset * 2 + 1, mem_mask >> 32) << 32;
427   return result;
428}
429
430
431INLINE void write64le_with_16be_handler(write16_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
432{
433   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
434      write32le_with_16be_handler(handler, offset * 2 + 0, data >> 0, mem_mask >> 0);
435   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
436      write32le_with_16be_handler(handler, 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_handler handler, offs_t offset, UINT64 mem_mask)
447{
448   UINT64 result = 0;
449   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
450      result |= (UINT64)(*handler)(offset * 2 + 0, mem_mask >> 32) << 32;
451   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
452      result |= (UINT64)(*handler)(offset * 2 + 1, mem_mask >> 0) << 0;
453   return result;
454}
455
456
457INLINE void write64be_with_32be_handler(write32_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
458{
459   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
460      (*handler)(offset * 2 + 0, data >> 32, mem_mask >> 32);
461   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
462      (*handler)(offset * 2 + 1, data >>  0, mem_mask >>  0);
463}
464
465
466/*************************************
467 *
101468 *  64-bit LE using 32-bit LE handlers
102469 *
103470 *************************************/
r936r937
106473{
107474   UINT64 result = 0;
108475   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
109      result |= ((UINT64) handler(offset * 2 + 0, (UINT32) (mem_mask >> 0))) << 0;
476      result |= (UINT64)(*handler)(offset * 2 + 0, mem_mask >> 0) << 0;
110477   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
111      result |= ((UINT64) handler(offset * 2 + 1, (UINT32) (mem_mask >> 32))) << 32;
478      result |= (UINT64)(*handler)(offset * 2 + 1, mem_mask >> 32) << 32;
112479   return result;
113480}
114481
482
115483INLINE void write64le_with_32le_handler(write32_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
116484{
117485   if ((mem_mask & U64(0x00000000ffffffff)) != U64(0x00000000ffffffff))
118      handler(offset * 2 + 0, data >> 0, mem_mask >> 0);
486      (*handler)(offset * 2 + 0, data >> 0, mem_mask >> 0);
119487   if ((mem_mask & U64(0xffffffff00000000)) != U64(0xffffffff00000000))
120      handler(offset * 2 + 1, data >> 32, mem_mask >> 32);
488      (*handler)(offset * 2 + 1, data >> 32, mem_mask >> 32);
121489}
122490
123491
124
125492/*************************************
126493 *
127494 *  64-bit BE using 32-bit LE handlers
r936r937
136503   return FLIPENDIAN_INT64(result);
137504}
138505
506
139507INLINE void write64be_with_32le_handler(write32_handler handler, offs_t offset, UINT64 data, UINT64 mem_mask)
140508{
141509   data = FLIPENDIAN_INT64(data);
142510   mem_mask = FLIPENDIAN_INT64(mem_mask);
143511   write64le_with_32le_handler(handler, offset, data, mem_mask);
144512}
513
514
515/*************************************
516 *
517 *  64-bit LE using 32-bit BE handlers
518 *
519 *************************************/
520
521INLINE UINT64 read64le_with_32be_handler(read32_handler handler, offs_t offset, UINT64 mem_mask)
522{
523   UINT64 result;
524   mem_mask = FLIPENDIAN_INT64(mem_mask);
525   result = read64be_with_32be_handler(handler, offset, mem_mask);
526   return FLIPENDIAN_INT64(result);
527}
528
529
530INLINE void write64le_with_32be_handler(write32_handler handler, 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, 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, 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, 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, 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      return func(handler, 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_MSB )
621
622
623#define WRITE8TO16BE_MSB( name, write8 ) \
624WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_handler, ACCESSING_MSB )
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_MSB )
638
639
640#define WRITE8TO16LE_MSB( name, write8 ) \
641WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_handler, ACCESSING_MSB )
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_LSB )
655
656
657#define WRITE8TO16BE_LSB( name, write8 ) \
658WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_handler, ACCESSING_LSB )
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_LSB )
672
673
674#define WRITE8TO16LE_LSB( name, write8 ) \
675WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_handler, ACCESSING_LSB )
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_MSB32 )
723
724
725#define WRITE8TO32BE_MSB( name, write8 ) \
726WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_handler, ACCESSING_MSB32 )
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_MSB32 )
740
741
742#define WRITE8TO32LE_MSB( name, write8 ) \
743WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_handler, ACCESSING_MSB32 )
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_LSB32 )
757
758
759#define WRITE8TO32BE_LSB( name, write8 ) \
760WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_handler, ACCESSING_LSB32 )
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_LSB32 )
774
775
776#define WRITE8TO32LE_LSB( name, write8 ) \
777WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_handler, ACCESSING_LSB32 )
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_MSW32 )
893
894
895#define WRITE16BETO32BE_MSW( name, write16 ) \
896WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_handler, ACCESSING_MSW32 )
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_MSW32 )
910
911
912#define WRITE16LETO32BE_MSW( name, write16 ) \
913WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_handler, ACCESSING_MSW32 )
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_MSW32 )
927
928
929#define WRITE16BETO32LE_MSW( name, write16 ) \
930WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_handler, ACCESSING_MSW32 )
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_MSW32 )
944
945
946#define WRITE16LETO32LE_MSW( name, write16 ) \
947WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_handler, ACCESSING_MSW32 )
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_LSW32 )
960
961
962#define WRITE16BETO32BE_LSW( name, write16 ) \
963WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_handler, ACCESSING_LSW32 )
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_LSW32 )
977
978
979#define WRITE16LETO32BE_LSW( name, write16 ) \
980WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_handler, ACCESSING_LSW32 )
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_LSW32 )
994
995
996#define WRITE16BETO32LE_LSW( name, write16 ) \
997WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_handler, ACCESSING_LSW32 )
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_LSW32 )
1011
1012
1013#define WRITE16LETO32LE_LSW( name, write16 ) \
1014WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_handler, ACCESSING_LSW32 )
1015
1016
1017#define READWRITE16LETO32LE_LSW( name, read16, write16 ) \
1018READ16LETO32LE_LSW(name,read16) \
1019WRITE16LETO32LE_LSW(name,write16)
1020
src/emu/uigfx.c
r936r937
234234static void palette_handler(ui_gfx_state *state)
235235{
236236   int total = state->palette.which ? Machine->drv->color_table_len : Machine->drv->total_colors;
237   UINT16 *pens = state->palette.which ? Machine->game_colortable : NULL;
237   const UINT16 *pens = state->palette.which ? Machine->game_colortable : NULL;
238238   const char *title = state->palette.which ? "COLORTABLE" : "PALETTE";
239   rgb_t *raw_color = palette_get_raw_colors(Machine);
239   const rgb_t *raw_color = palette_entry_list_raw(Machine->palette);
240240   render_font *ui_font = ui_get_font();
241241   float cellwidth, cellheight;
242242   float chwidth, chheight;
r936r937
769769   };
770770   int width = (rotate & ORIENTATION_SWAP_XY) ? gfx->height : gfx->width;
771771   int height = (rotate & ORIENTATION_SWAP_XY) ? gfx->width : gfx->height;
772   const pen_t *palette = (Machine->drv->total_colors != 0) ? palette_get_raw_colors(Machine) : NULL;
772   const pen_t *palette = (Machine->drv->total_colors != 0) ? palette_entry_list_raw(Machine->palette) : NULL;
773773   UINT32 rowpixels = bitmap->rowpixels;
774774   const UINT16 *colortable = NULL;
775775   UINT32 palette_mask = ~0;
r936r937
777777
778778   /* select either the raw palette or the colortable */
779779   if (Machine->game_colortable != NULL)
780      colortable = &Machine->game_colortable[(gfx->colortable - Machine->remapped_colortable) + color * gfx->color_granularity];
781   else if (palette != NULL && gfx->colortable != NULL)
782      palette += (gfx->colortable - Machine->remapped_colortable) + color * gfx->color_granularity;
780      colortable = &Machine->game_colortable[gfx->color_base + color * gfx->color_granularity];
781   else if (palette != NULL)
782      palette += gfx->color_base + color * gfx->color_granularity;
783783   else
784784   {
785785      palette = default_palette;
r936r937
821821         s = src + effy * gfx->line_modulo;
822822
823823         /* extract the pixel */
824         if (gfx->flags & GFX_PACKED)
824         if (gfx->flags & GFX_ELEMENT_PACKED)
825825            pixel = (s[effx/2] >> ((effx & 1) * 4)) & 0xf;
826826         else
827827            pixel = s[effx];
src/emu/info.c
r936r937
496496               case REGION_GFX7: fprintf(out, " region=\"gfx7\""); break;
497497               case REGION_GFX8: fprintf(out, " region=\"gfx8\""); break;
498498               case REGION_PROMS: fprintf(out, " region=\"proms\""); break;
499               case REGION_PLDS: fprintf(out, " region=\"plds\""); break;
499500               case REGION_SOUND1: fprintf(out, " region=\"sound1\""); break;
500501               case REGION_SOUND2: fprintf(out, " region=\"sound2\""); break;
501502               case REGION_SOUND3: fprintf(out, " region=\"sound3\""); break;
r936r937
545546
546547   expand_machine_driver(game->drv, &drv);
547548
548   for( i = 0; i < MAX_SOUND && drv.sound[i].sound_type; i++ )
549   for( i = 0; i < MAX_SOUND && drv.sound[i].sound_type != SOUND_DUMMY; i++ )
549550   {
550551      const char **samplenames = NULL;
551552      if( drv.sound[i].sound_type == SOUND_SAMPLES )
r936r937
572573
573574   expand_machine_driver(game->drv, &drv);
574575
575   for( i = 0; i < MAX_SOUND && drv.sound[i].sound_type; i++ )
576   for( i = 0; i < MAX_SOUND && drv.sound[i].sound_type != SOUND_DUMMY; i++ )
576577   {
577578      const char **samplenames = NULL;
578579      if( drv.sound[i].sound_type == SOUND_SAMPLES )
r936r937
613614
614615   for(j=0;j<MAX_CPU;++j)
615616   {
616      if (cpu[j].cpu_type!=0)
617      if (cpu[j].cpu_type != CPU_DUMMY)
617618      {
618619         fprintf(out, "\t\t<chip");
619620         fprintf(out, " type=\"cpu\"");
r936r937
627628
628629   for(j=0;j<MAX_SOUND;++j)
629630   {
630      if (sound[j].sound_type)
631      if (sound[j].sound_type != SOUND_DUMMY)
631632      {
632633         fprintf(out, "\t\t<chip");
633634         fprintf(out, " type=\"audio\"");
r936r937
715716   i = 0;
716717   while (i < MAX_SOUND && !has_sound)
717718   {
718      if (sound[i].sound_type)
719      if (sound[i].sound_type != SOUND_DUMMY)
719720         has_sound = 1;
720721      ++i;
721722   }
src/emu/emuopts.c
r936r937
7575   { "throttle",                    "1",         OPTION_BOOLEAN,    "enable throttling to keep game running in sync with real time" },
7676   { "sleep",                       "1",         OPTION_BOOLEAN,    "enable sleeping, which gives time back to other applications when idle" },
7777   { "speed(0.01-100)",             "1.0",       0,                 "controls the speed of gameplay, relative to realtime; smaller numbers are slower" },
78   { "refreshspeed;rs",             "0",         OPTION_BOOLEAN,    "automatically adjusts the speed of gameplay to keep the refresh rate lower than the screen" },
7879
7980   /* rotation options */
8081   { NULL,                          NULL,        OPTION_HEADER,     "CORE ROTATION OPTIONS" },
src/emu/tilemap.h
r936r937
248248        into just two types now. Here is how to replicate that
249249        functionality with the new system:
250250
251        TILEMAP_TYPE_PEN: If you want a tilemap with no transparency,
251        TILEMAP_OPAQUE: If you want a tilemap with no transparency,
252252            you don't need to do anything; by default all pens map to
253253            layer 0 and are thus non-transparent. Note that a lot of
254254            code used to create OPAQUE tilemaps and then set the
255255            transparent pen for them; this no longer works.
256256
257        TILEMAP_TYPE_PEN: This described a tilemap with a single
257        TILEMAP_TRANSPARENT: This described a tilemap with a single
258258            transparent pen. To create the same effect, make a new tilemap
259259            of type TILEMAP_TYPE_PEN, and then call
260260            tilemap_set_transparent_pen() to specify which pen is
261261            transparent; all other pens will map to layer 0.
262262
263        TILEMAP_TYPE_COLORTABLE: This works just like before and
263        TILEMAP_TRANSPARENT_COLOR: This works just like before and
264264            even has the same type name. Create a tilemap of type
265265            TILEMAP_TYPE_COLORTABLE and call
266266            tilemap_set_transparent_pen() to specify which remapped pen
267267            is transparent.
268268
269        TILEMAP_TYPE_PEN: This type is no longer special; with the new
269        TILEMAP_BITMASK: This type is no longer special; with the new
270270            code, any tile_get_info callback can specify a bitmask which
271271            will be processed after rendering to make some pixels
272272            transparent.
273273
274        TILEMAP_TYPE_PEN: This type used to let you map pens into two
274        TILEMAP_SPLIT: This type used to let you map pens into two
275275            layers (called "front" and "back") based on their pens. It
276276            also allowed for you to choose one of 4 mappings on a per-tile
277277            basis. All of this functionality is now expanded: you can
r936r937
281281            which still exists but maps onto the new behavior. The "front"
282282            layer is now "layer 0" and the "back" layer is now "layer 1".
283283
284        TILEMAP_TYPE_PEN: This type was only used in one driver
284        TILEMAP_SPLIT_PENBIT: This type was only used in one driver
285285            and is not worth describing in detail how the new mapping
286286            works. :)
287287
r936r937
589589   const gfx_element *   gfx = machine->gfx[gfxnum];
590590   int code = rawcode % gfx->total_elements;
591591   tileinfo->pen_data = gfx->gfxdata + code * gfx->char_modulo;
592   tileinfo->palette_base = (gfx->colortable - machine->remapped_colortable) + gfx->color_granularity * rawcolor;
592   tileinfo->palette_base = gfx->color_base + gfx->color_granularity * rawcolor;
593593   tileinfo->flags = flags;
594   if (gfx->flags & GFX_PACKED)
594   if (gfx->flags & GFX_ELEMENT_PACKED)
595595      tileinfo->flags |= TILE_4BPP;
596596}
597597
src/emu/emuopts.h
r936r937
7373#define OPTION_THROTTLE            "throttle"
7474#define OPTION_SLEEP            "sleep"
7575#define OPTION_SPEED            "speed"
76#define OPTION_REFRESHSPEED         "refreshspeed"
7677
7778/* core rotation options */
7879#define OPTION_ROTATE            "rotate"
src/emu/audit.c
r936r937
1919
2020
2121/***************************************************************************
22    GLOBAL VARIABLES
23***************************************************************************/
24
25static const game_driver *chd_gamedrv;
26
27
28
29/***************************************************************************
3022    FUNCTION PROTOTYPES
3123***************************************************************************/
3224
r936r937
3426static int audit_one_disk(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record);
3527static int rom_used_by_parent(const game_driver *gamedrv, const rom_entry *romentry, const game_driver **parent);
3628
37static chd_interface_file *audit_chd_open(const char *filename, const char *mode);
38static void audit_chd_close(chd_interface_file *file);
39static UINT32 audit_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
40static UINT32 audit_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
41static UINT64 audit_chd_length(chd_interface_file *file);
4229
4330
44
4531/***************************************************************************
46    HARD DISK INTERFACE
47***************************************************************************/
48
49static chd_interface audit_chd_interface =
50{
51   audit_chd_open,
52   audit_chd_close,
53   audit_chd_read,
54   audit_chd_write,
55   audit_chd_length
56};
57
58
59
60/***************************************************************************
6132    INLINE FUNCTIONS
6233***************************************************************************/
6334
r936r937
442413
443414static int audit_one_disk(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record)
444415{
416   mame_file *source_file;
445417   chd_file *source;
446418   chd_error err;
447419
r936r937
451423   record->exphash = ROM_GETHASHDATA(rom);
452424
453425   /* open the disk */
454   chd_gamedrv = gamedrv;
455   chd_set_interface(&audit_chd_interface);
456   err = open_disk_image(gamedrv, rom, &source);
426   err = open_disk_image(gamedrv, rom, &source_file, &source);
457427
458428   /* if we failed, report the error */
459429   if (err != CHDERR_NONE)
r936r937
496466         set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD);
497467
498468      chd_close(source);
469      mame_fclose(source_file);
499470   }
500471
501472   /* return TRUE if we found anything at all */
r936r937
532503
533504   return FALSE;
534505}
535
536
537
538/***************************************************************************
539    CHD INTERFACES
540***************************************************************************/
541
542/*-------------------------------------------------
543    audit_chd_open - interface for opening
544    a hard disk image
545-------------------------------------------------*/
546
547static chd_interface_file *audit_chd_open(const char *filename, const char *mode)
548{
549   const game_driver *drv;
550
551   /* attempt reading up the chain through the parents */
552   for (drv = chd_gamedrv; drv != NULL; drv = driver_get_clone(drv))
553   {
554      file_error filerr;
555      mame_file *file;
556      astring *fname;
557
558      fname = astring_assemble_3(astring_alloc(), drv->name, PATH_SEPARATOR, filename);
559      filerr = mame_fopen(SEARCHPATH_IMAGE, astring_c(fname), OPEN_FLAG_READ, &file);
560      astring_free(fname);
561
562      if (filerr == FILERR_NONE)
563         return (chd_interface_file *)file;
564   }
565   return NULL;
566}
567
568
569/*-------------------------------------------------
570    audit_chd_close - interface for closing
571    a hard disk image
572-------------------------------------------------*/
573
574static void audit_chd_close(chd_interface_file *file)
575{
576   mame_fclose((mame_file *)file);
577}
578
579
580/*-------------------------------------------------
581    audit_chd_read - interface for reading
582    from a hard disk image
583-------------------------------------------------*/
584
585static UINT32 audit_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
586{
587   mame_fseek((mame_file *)file, offset, SEEK_SET);
588   return mame_fread((mame_file *)file, buffer, count);
589}
590
591
592/*-------------------------------------------------
593    audit_chd_write - interface for writing
594    to a hard disk image
595-------------------------------------------------*/
596
597static UINT32 audit_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
598{
599   return 0;
600}
601
602
603/*-------------------------------------------------
604    audit_chd_length - interface for getting
605    the length a hard disk image
606-------------------------------------------------*/
607
608static UINT64 audit_chd_length(chd_interface_file *file)
609{
610   return mame_fsize((mame_file *)file);
611}
src/emu/video.c
r936r937
120120   UINT32               seconds_to_run;      /* number of seconds to run before quitting */
121121   UINT8               auto_frameskip;      /* flag: TRUE if we're automatically frameskipping */
122122   UINT32               speed;            /* overall speed (*100) */
123   UINT32               original_speed;      /* originally-specified speed */
124   UINT8               refresh_speed;      /* flag: TRUE if we max out our speed according to the refresh */
123125
124126   /* frameskipping */
125127   UINT8               frameskip_level;   /* current frameskip level */
r936r937
166168static void init_buffered_spriteram(void);
167169
168170/* graphics decoding */
169static void allocate_graphics(const gfx_decode *gfxdecodeinfo);
170static void decode_graphics(const gfx_decode *gfxdecodeinfo);
171static void allocate_graphics(running_machine *machine, const gfx_decode *gfxdecodeinfo);
172static void decode_graphics(running_machine *machine, const gfx_decode *gfxdecodeinfo);
171173
172174/* global rendering */
173175static TIMER_CALLBACK( scanline0_callback );
r936r937
280282   global.auto_frameskip = options_get_bool(mame_options(), OPTION_AUTOFRAMESKIP);
281283   global.frameskip_level = options_get_int(mame_options(), OPTION_FRAMESKIP);
282284   global.seconds_to_run = options_get_int(mame_options(), OPTION_SECONDS_TO_RUN);
283   global.speed = (options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5);
285   global.original_speed = global.speed = (options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5);
286   global.refresh_speed = options_get_bool(mame_options(), OPTION_REFRESHSPEED);
284287
285288   /* allocate memory for our private data */
286289   viddata = machine->video_data = auto_malloc(sizeof(*viddata));
r936r937
331334   /* convert the gfx ROMs into character sets. This is done BEFORE calling the driver's */
332335   /* palette_init() routine because it might need to check the machine->gfx[] data */
333336   if (machine->drv->gfxdecodeinfo != NULL)
334      allocate_graphics(machine->drv->gfxdecodeinfo);
337      allocate_graphics(machine, machine->drv->gfxdecodeinfo);
335338
336339   /* configure the palette */
337340   palette_config(machine);
338341
339342   /* actually decode the graphics */
340343   if (machine->drv->gfxdecodeinfo != NULL)
341      decode_graphics(machine->drv->gfxdecodeinfo);
344      decode_graphics(machine, machine->drv->gfxdecodeinfo);
342345
343346   /* reset video statics and get out of here */
344347   pdrawgfx_shadow_lowpri = 0;
r936r937
482485    graphics
483486-------------------------------------------------*/
484487
485static void allocate_graphics(const gfx_decode *gfxdecodeinfo)
488static void allocate_graphics(running_machine *machine, const gfx_decode *gfxdecodeinfo)
486489{
487490   int i;
488491
r936r937
578581      }
579582
580583      /* allocate the graphics */
581      Machine->gfx[i] = allocgfx(&glcopy);
584      machine->gfx[i] = allocgfx(&glcopy);
582585
583586      /* if we have a remapped colortable, point our local colortable to it */
584      if (Machine->remapped_colortable != NULL)
585         Machine->gfx[i]->colortable = &Machine->remapped_colortable[gfxdecodeinfo[i].color_codes_start];
586      Machine->gfx[i]->total_colors = gfxdecodeinfo[i].total_color_codes;
587      machine->gfx[i]->total_colors = gfxdecodeinfo[i].total_color_codes;
588      machine->gfx[i]->color_base = machine->drv->gfxdecodeinfo[i].color_codes_start;
587589   }
588590}
589591
r936r937
592594    decode_graphics - decode the graphics
593595-------------------------------------------------*/
594596
595static void decode_graphics(const gfx_decode *gfxdecodeinfo)
597static void decode_graphics(running_machine *machine, const gfx_decode *gfxdecodeinfo)
596598{
597599   int totalgfx = 0, curgfx = 0;
598600   char buffer[200];
r936r937
600602
601603   /* count total graphics elements */
602604   for (i = 0; i < MAX_GFX_ELEMENTS; i++)
603      if (Machine->gfx[i])
604         totalgfx += Machine->gfx[i]->total_elements;
605      if (machine->gfx[i])
606         totalgfx += machine->gfx[i]->total_elements;
605607
606608   /* loop over all elements */
607609   for (i = 0; i < MAX_GFX_ELEMENTS; i++)
608      if (Machine->gfx[i])
610      if (machine->gfx[i] != NULL)
609611      {
610612         /* if we have a valid region, decode it now */
611613         if (gfxdecodeinfo[i].memory_region > REGION_INVALID)
612614         {
613615            UINT8 *region_base = memory_region(gfxdecodeinfo[i].memory_region);
614            gfx_element *gfx = Machine->gfx[i];
616            gfx_element *gfx = machine->gfx[i];
615617            int j;
616618
617619            /* now decode the actual graphics */
r936r937
629631
630632         /* otherwise, clear the target region */
631633         else
632            memset(Machine->gfx[i]->gfxdata, 0, Machine->gfx[i]->char_modulo * Machine->gfx[i]->total_elements);
634            memset(machine->gfx[i]->gfxdata, 0, machine->gfx[i]->char_modulo * machine->gfx[i]->total_elements);
633635      }
634636}
635637
r936r937
694696            default:                  fatalerror("Invalid bitmap format!");   break;
695697         }
696698
697         /* allocate new stuff */
699         /* allocate bitmaps */
698700         info->bitmap[0] = bitmap_alloc(curwidth, curheight, screen_format);
701         bitmap_set_palette(info->bitmap[0], Machine->palette);
699702         info->bitmap[1] = bitmap_alloc(curwidth, curheight, screen_format);
703         bitmap_set_palette(info->bitmap[1], Machine->palette);
704
705         /* allocate textures */
700706         info->texture[0] = render_texture_alloc(NULL, NULL);
701707         render_texture_set_bitmap(info->texture[0], info->bitmap[0], visarea, info->config->palette_base, info->format);
702708         info->texture[1] = render_texture_alloc(NULL, NULL);
r936r937
714720   info->scantime = refresh / height;
715721   info->pixeltime = refresh / (height * width);
716722
723   /* adjust speed if necessary */
724   if (global.refresh_speed)
725   {
726      float minrefresh = render_get_max_update_rate();
727      if (minrefresh != 0)
728      {
729         UINT32 target_speed = floor(minrefresh * 100.0 / SUBSECONDS_TO_HZ(refresh));
730         target_speed = MIN(target_speed, global.original_speed);
731         if (target_speed != global.speed)
732         {
733            mame_printf_verbose("Adjusting target speed to %d%%\n", target_speed);
734            global.speed = target_speed;
735         }
736      }
737   }
738
717739   /* recompute the VBLANK timing */
718740   cpu_compute_vblank_timing();
719741
r936r937
16231645
16241646void video_screen_save_snapshot(running_machine *machine, mame_file *fp, int scrnum)
16251647{
1648   const rgb_t *palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL;
16261649   png_info pnginfo = { 0 };
16271650   mame_bitmap *bitmap;
16281651   png_error error;
r936r937
16401663   png_add_text(&pnginfo, "System", text);
16411664
16421665   /* now do the actual work */
1643   error = png_write_bitmap(mame_core_file(fp), &pnginfo, machine->video_data->snap_bitmap, machine->drv->total_colors, palette_get_adjusted_colors(machine));
1666   error = png_write_bitmap(mame_core_file(fp), &pnginfo, machine->video_data->snap_bitmap, machine->drv->total_colors, palette);
16441667
16451668   /* free any data allocated */
16461669   png_free(&pnginfo);
r936r937
18601883      }
18611884
18621885      /* write the next frame */
1863      error = mng_capture_frame(mame_core_file(info->movie_file), &pnginfo, bitmap, machine->drv->total_colors, palette_get_adjusted_colors(machine));
1886      error = mng_capture_frame(mame_core_file(info->movie_file), &pnginfo, bitmap, machine->drv->total_colors, palette_entry_list_adjusted(machine->palette));
18641887      png_free(&pnginfo);
18651888      if (error != PNGERR_NONE)
18661889      {
r936r937
20372060
20382061/*-------------------------------------------------
20392062    video_crosshair_set_screenmask_callback -
2040   install a callback to determine to which screen
2041   crosshairs should be rendered
2063    install a callback to determine to which screen
2064    crosshairs should be rendered
20422065-------------------------------------------------*/
20432066
20442067void video_crosshair_set_screenmask_callback(running_machine *machine, UINT32 (*get_screen_mask)(int player))
src/emu/emu.mak
r936r937
4040   $(EMUOBJ)/drawgfx.o \
4141   $(EMUOBJ)/driver.o \
4242   $(EMUOBJ)/emuopts.o \
43   $(EMUOBJ)/emupal.o \
4344   $(EMUOBJ)/fileio.o \
4445   $(EMUOBJ)/hash.o \
4546   $(EMUOBJ)/info.o \
r936r937
5051   $(EMUOBJ)/mamecore.o \
5152   $(EMUOBJ)/memory.o \
5253   $(EMUOBJ)/output.o \
53   $(EMUOBJ)/palette.o \
5454   $(EMUOBJ)/render.o \
5555   $(EMUOBJ)/rendfont.o \
5656   $(EMUOBJ)/rendlay.o \
src/emu/mame.h
r936r937
168168   /* video-related information */
169169   gfx_element *         gfx[MAX_GFX_ELEMENTS];/* array of pointers to graphic sets (chars, sprites) */
170170   screen_state         screen[MAX_SCREENS];/* current screen state */
171   palette_t *            palette;         /* global palette object */
171172
172173   /* palette-related information */
173   pen_t *               pens;            /* remapped palette pen numbers */
174   UINT16 *            game_colortable;   /* lookup table used to map gfx pen numbers to color numbers */
175   pen_t *               remapped_colortable;/* the above, already remapped through Machine->pens */
174/* fix me - some games try to modify remapped_colortable directly */
175/* search for "palette hack" to find instances */
176   const pen_t *         pens;            /* remapped palette pen numbers */
177   const UINT16 *         game_colortable;   /* lookup table used to map gfx pen numbers to color numbers */
178   const pen_t *         remapped_colortable;/* the above, already remapped through Machine->pens */
176179   pen_t *               shadow_table;      /* table for looking up a shadowed pen */
177180
178181   /* audio-related information */
src/emu/cpuintrf.c
r936r937
160160void m37702_get_info(UINT32 state, cpuinfo *info);
161161void m37710_get_info(UINT32 state, cpuinfo *info);
162162void ppc403_get_info(UINT32 state, cpuinfo *info);
163void ppc601_get_info(UINT32 state, cpuinfo *info);
163164void ppc602_get_info(UINT32 state, cpuinfo *info);
164165void ppc603_get_info(UINT32 state, cpuinfo *info);
165166void mpc8240_get_info(UINT32 state, cpuinfo *info);
r936r937
671672#if (HAS_PPC403)
672673   { CPU_PPC403, ppc403_get_info },
673674#endif
675#if (HAS_PPC601)
676   { CPU_PPC601, ppc601_get_info },
677#endif
674678#if (HAS_PPC602)
675679   { CPU_PPC602, ppc602_get_info },
676680#endif
src/emu/mamecore.h
r936r937
7474/* pen_t is used to represent pixel values in bitmaps */
7575typedef UINT32 pen_t;
7676
77/* rgb_t is used to represent 32-bit (A)RGB values */
78typedef UINT32 rgb_t;
79
8077/* stream_sample_t is used to represent a single sample in a sound stream */
8178typedef INT32 stream_sample_t;
8279
src/emu/rendlay.c
r936r937
972972   bitmap_free(tempbitmap);
973973}
974974
975
975976/*-------------------------------------------------
976977    layout_element_draw_led14segsc - draw a
977978    14-segment LCD with semicolon (2 extra segments)
r936r937
12021203   bitmap_free(tempbitmap);
12031204}
12041205
1206
12051207/*-------------------------------------------------
12061208    layout_element_draw_led16segsc - draw a
12071209    16-segment LCD with semicolon (2 extra segments)
12081210-------------------------------------------------*/
1211
12091212static void layout_element_draw_led16segsc(mame_bitmap *dest, const rectangle *bounds, const render_color *color, int pattern)
12101213{
12111214   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
r936r937
13251328   bitmap_free(tempbitmap);
13261329}
13271330
1331
1332
13281333/***************************************************************************
13291334    LAYOUT FILE PARSING
13301335***************************************************************************/
src/emu/cpuintrf.h
r936r937
171171   CPU_M37702,
172172   CPU_M37710,
173173   CPU_PPC403,
174   CPU_PPC601,
174175   CPU_PPC602,
175176   CPU_PPC603,
176177   CPU_MPC8240,
src/emu/ui.c
r936r937
10841084   bufptr += sprintf(bufptr, "%s\n%s %s\n\n%s:\n", Machine->gamedrv->description, Machine->gamedrv->year, Machine->gamedrv->manufacturer, ui_getstring(UI_cpu));
10851085
10861086   /* loop over all CPUs */
1087   for (cpunum = 0; cpunum < MAX_CPU && Machine->drv->cpu[cpunum].cpu_type; cpunum += count)
1087   for (cpunum = 0; cpunum < MAX_CPU && Machine->drv->cpu[cpunum].cpu_type != CPU_DUMMY; cpunum += count)
10881088   {
10891089      int type = Machine->drv->cpu[cpunum].cpu_type;
10901090      int clock = Machine->drv->cpu[cpunum].cpu_clock;
r936r937
11111111   bufptr += sprintf(bufptr, "\n%s:\n", ui_getstring(UI_sound));
11121112
11131113   /* loop over all sound chips */
1114   for (sndnum = 0; sndnum < MAX_SOUND && Machine->drv->sound[sndnum].sound_type; sndnum += count)
1114   for (sndnum = 0; sndnum < MAX_SOUND && Machine->drv->sound[sndnum].sound_type != SOUND_DUMMY; sndnum += count)
11151115   {
11161116      int type = Machine->drv->sound[sndnum].sound_type;
11171117      int clock = sndnum_clock(sndnum);
src/emu/sound.c
r936r937
259259
260260   /* stop all the sound chips */
261261   for (sndnum = 0; sndnum < MAX_SOUND; sndnum++)
262      if (Machine->drv->sound[sndnum].sound_type != 0)
262      if (Machine->drv->sound[sndnum].sound_type != SOUND_DUMMY)
263263         sndintrf_exit_sound(sndnum);
264264
265265   /* reset variables */
r936r937
296296      int index;
297297
298298      /* stop when we hit an empty entry */
299      if (msound->sound_type == 0)
299      if (msound->sound_type == SOUND_DUMMY)
300300         break;
301301      totalsnd++;
302302
r936r937
517517
518518   /* reset all the sound chips */
519519   for (sndnum = 0; sndnum < MAX_SOUND; sndnum++)
520      if (Machine->drv->sound[sndnum].sound_type != 0)
520      if (Machine->drv->sound[sndnum].sound_type != SOUND_DUMMY)
521521         sndnum_reset(sndnum);
522522}
523523
src/emu/driver.c
r936r937
7676   int cpunum;
7777
7878   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
79      if (machine->cpu[cpunum].cpu_type == 0)
79      if (machine->cpu[cpunum].cpu_type == CPU_DUMMY)
8080      {
8181         machine->cpu[cpunum].tag = tag;
8282         machine->cpu[cpunum].cpu_type = type;
r936r937
201201   int soundnum;
202202
203203   for (soundnum = 0; soundnum < MAX_SOUND; soundnum++)
204      if (machine->sound[soundnum].sound_type == 0)
204      if (machine->sound[soundnum].sound_type == SOUND_DUMMY)
205205      {
206206         machine->sound[soundnum].tag = tag;
207207         machine->sound[soundnum].sound_type = type;
src/emu/driver.h
r936r937
6262#include "sndintrf.h"
6363#include "fileio.h"
6464#include "drawgfx.h"
65#include "palette.h"
65#include "emupal.h"
6666#include "sound.h"
6767#include "input.h"
6868#include "inptport.h"
src/emu/drawgfx.c
r936r937
128128      return;
129129
130130   /* packed case */
131   if (gfx->flags & GFX_PACKED)
131   if (gfx->flags & GFX_ELEMENT_PACKED)
132132   {
133133      for (y = 0; y < gfx->height; y++)
134134      {
r936r937
172172   memset(dp, 0, gfx->char_modulo);
173173
174174   /* packed case */
175   if (gfx->flags & GFX_PACKED)
175   if (gfx->flags & GFX_ELEMENT_PACKED)
176176   {
177177      for (plane = 0; plane < gl->planes; plane++)
178178      {
r936r937
257257   gfx->width = gl->width;
258258   gfx->height = gl->height;
259259   gfx->total_elements = gl->total;
260   gfx->color_depth = 1 << gl->planes;
260261   gfx->color_granularity = 1 << gl->planes;
261262   if (gfx->color_granularity <= 32)
262263      gfx->pen_usage = malloc_or_die(gfx->total_elements * sizeof(*gfx->pen_usage));
r936r937
269270      gfx->char_modulo = gl->charincrement / 8;
270271
271272      /* don't free the data because we will get a pointer at decode time */
272      gfx->flags |= GFX_DONT_FREE_GFXDATA;
273      gfx->flags |= GFX_ELEMENT_DONT_FREE;
273274      if (gl->planes <= 4)
274         gfx->flags |= GFX_PACKED;
275         gfx->flags |= GFX_ELEMENT_PACKED;
275276   }
276277
277278   /* decoded graphics case */
r936r937
304305   assert(last < gfx->total_elements);
305306
306307   /* if this is raw graphics data, just set the pointer and compute pen usage */
307   if (gfx->flags & GFX_DONT_FREE_GFXDATA)
308   if (gfx->flags & GFX_ELEMENT_DONT_FREE)
308309   {
309310      /* if we got a pointer, set it */
310311      if (first == 0 && src)
r936r937
341342      free((void *)gfx->layout.extxoffs);
342343   if (gfx->pen_usage)
343344      free(gfx->pen_usage);
344   if (!(gfx->flags & GFX_DONT_FREE_GFXDATA))
345   if (!(gfx->flags & GFX_ELEMENT_DONT_FREE))
345346      free(gfx->gfxdata);
346347   free(gfx);
347348}
r936r937
915916      mame_bitmap *pri_buffer,UINT32 pri_mask)
916917{
917918   assert_always(gfx, "drawgfx() gfx == 0");
918   assert_always(gfx->colortable || is_raw[transparency], "drawgfx() gfx->colortable == 0");
919919
920920   code %= gfx->total_elements;
921921   if (!is_raw[transparency])
r936r937
14021402   /* ASG 980209 -- added 16-bit version */
14031403   if (dest_bmp->bpp == 8)
14041404   {
1405      if( gfx && gfx->colortable )
1405      if( gfx )
14061406      {
1407         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
1407         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
14081408         UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
14091409
14101410         int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
r936r937
14781478               {
14791479                  if (pri_buffer)
14801480                  {
1481                     if (gfx->flags & GFX_PACKED)
1481                     if (gfx->flags & GFX_ELEMENT_PACKED)
14821482                     {
14831483                        for( y=sy; y<ey; y++ )
14841484                        {
r936r937
15201520                  }
15211521                  else
15221522                  {
1523                     if (gfx->flags & GFX_PACKED)
1523                     if (gfx->flags & GFX_ELEMENT_PACKED)
15241524                     {
15251525                        for( y=sy; y<ey; y++ )
15261526                        {
r936r937
15621562               {
15631563                  if (pri_buffer)
15641564                  {
1565                     if (gfx->flags & GFX_PACKED)
1565                     if (gfx->flags & GFX_ELEMENT_PACKED)
15661566                     {
15671567                        for( y=sy; y<ey; y++ )
15681568                        {
r936r937
16131613                  }
16141614                  else
16151615                  {
1616                     if (gfx->flags & GFX_PACKED)
1616                     if (gfx->flags & GFX_ELEMENT_PACKED)
16171617                     {
16181618                        for( y=sy; y<ey; y++ )
16191619                        {
r936r937
19961996   /* ASG 980209 -- new 16-bit part */
19971997   else if (dest_bmp->bpp == 16)
19981998   {
1999      if( gfx && gfx->colortable )
1999      if( gfx )
20002000      {
2001         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2001         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
20022002         UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
20032003
20042004         int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
r936r937
20722072               {
20732073                  if (pri_buffer)
20742074                  {
2075                     if (gfx->flags & GFX_PACKED)
2075                     if (gfx->flags & GFX_ELEMENT_PACKED)
20762076                     {
20772077                        for( y=sy; y<ey; y++ )
20782078                        {
r936r937
21152115                  }
21162116                  else
21172117                  {
2118                     if (gfx->flags & GFX_PACKED)
2118                     if (gfx->flags & GFX_ELEMENT_PACKED)
21192119                     {
21202120                        for( y=sy; y<ey; y++ )
21212121                        {
r936r937
21572157               {
21582158                  if (pri_buffer)
21592159                  {
2160                     if (gfx->flags & GFX_PACKED)
2160                     if (gfx->flags & GFX_ELEMENT_PACKED)
21612161                     {
21622162                        for( y=sy; y<ey; y++ )
21632163                        {
r936r937
22082208                  }
22092209                  else
22102210                  {
2211                     if (gfx->flags & GFX_PACKED)
2211                     if (gfx->flags & GFX_ELEMENT_PACKED)
22122212                     {
22132213                        for( y=sy; y<ey; y++ )
22142214                        {
r936r937
26972697   }
26982698   else
26992699   {
2700      if( gfx && gfx->colortable )
2700      if( gfx )
27012701      {
2702         const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
2702         const pen_t *pal = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (color % gfx->total_colors)];
27032703         UINT8 *source_base = gfx->gfxdata + (code % gfx->total_elements) * gfx->char_modulo;
27042704
27052705         int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
r936r937
49504950      int dw = ex-sx+1;                              /* dest width */
49514951      int dh = ey-sy+1;                              /* dest height */
49524952      int dm = dest->rowpixels;                        /* dest modulo */
4953      const pen_t *paldata = &gfx->colortable[gfx->color_granularity * color];
4953      const pen_t *paldata = &Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * color];
49544954      UINT8 *pribuf = (pri_buffer) ? BITMAP_ADDR8(pri_buffer, sy, sx) : NULL;
49554955
49564956      /* optimizations for 1:1 mapping */
r936r937
49834983      switch (transparency)
49844984      {
49854985         case TRANSPARENCY_NONE:
4986            if (gfx->flags & GFX_PACKED)
4986            if (gfx->flags & GFX_ELEMENT_PACKED)
49874987            {
49884988               if (pribuf)
49894989                  BLOCKMOVEPRI(4toN_opaque,(sd,sw,sh,sm,ls,ts,flipx,flipy,dd,dw,dh,dm,paldata,pribuf,pri_mask));
r936r937
50005000            break;
50015001
50025002         case TRANSPARENCY_NONE_RAW:
5003            if (gfx->flags & GFX_PACKED)
5003            if (gfx->flags & GFX_ELEMENT_PACKED)
50045004            {
50055005               if (pribuf)
50065006                  BLOCKMOVERAWPRI(4toN_opaque,(sd,sw,sh,sm,ls,ts,flipx,flipy,dd,dw,dh,dm,color,pribuf,pri_mask));
r936r937
50175017            break;
50185018
50195019         case TRANSPARENCY_PEN:
5020            if (gfx->flags & GFX_PACKED)
5020            if (gfx->flags & GFX_ELEMENT_PACKED)
50215021            {
50225022               if (pribuf)
50235023                  BLOCKMOVEPRI(4toN_transpen,(sd,sw,sh,sm,ls,ts,flipx,flipy,dd,dw,dh,dm,paldata,pribuf,pri_mask,transparent_color));
r936r937
50345034            break;
50355035
50365036         case TRANSPARENCY_PEN_RAW:
5037            if (gfx->flags & GFX_PACKED)
5037            if (gfx->flags & GFX_ELEMENT_PACKED)
50385038            {
50395039               if (pribuf)
50405040                  BLOCKMOVERAWPRI(4toN_transpen,(sd,sw,sh,sm,ls,ts,flipx,flipy,dd,dw,dh,dm,color,pribuf,pri_mask,transparent_color));
r936r937
50655065            break;
50665066
50675067         case TRANSPARENCY_COLOR:
5068            if (gfx->flags & GFX_PACKED)
5068            if (gfx->flags & GFX_ELEMENT_PACKED)
50695069            {
50705070               if (pribuf)
50715071                  BLOCKMOVEPRI(4toN_transcolor,(sd,sw,sh,sm,ls,ts,flipx,flipy,dd,dw,dh,dm,paldata,pribuf,pri_mask,Machine->game_colortable + (paldata - Machine->remapped_colortable),transparent_color));
r936r937
54935493
54945494DECLAREG(draw_scanline, (
54955495      mame_bitmap *bitmap,int x,int y,int length,
5496      const DATA_TYPE *src,pen_t *pens,int transparent_pen),
5496      const DATA_TYPE *src,const pen_t *pens,int transparent_pen),
54975497{
54985498   /* 8bpp destination */
54995499   if (bitmap->bpp == 8)
r936r937
56335633
56345634DECLAREG(pdraw_scanline, (
56355635      mame_bitmap *bitmap,int x,int y,int length,
5636      const DATA_TYPE *src,pen_t *pens,int transparent_pen,int pri),
5636      const DATA_TYPE *src,const pen_t *pens,int transparent_pen,int pri),
56375637{
56385638   /* 8bpp destination */
56395639   if (bitmap->bpp == 8)
src/emu/drawgfx.h
r936r937
1616
1717#include "mamecore.h"
1818
19#define MAX_GFX_PLANES      8
20#define MAX_GFX_SIZE      32
21#define MAX_ABS_GFX_SIZE   1024
2219
23#define EXTENDED_XOFFS      { 0 }
24#define EXTENDED_YOFFS      { 0 }
2520
26#define RGN_FRAC(num,den) (0x80000000 | (((num) & 0x0f) << 27) | (((den) & 0x0f) << 23))
27#define IS_FRAC(offset) ((offset) & 0x80000000)
28#define FRAC_NUM(offset) (((offset) >> 27) & 0x0f)
29#define FRAC_DEN(offset) (((offset) >> 23) & 0x0f)
30#define FRAC_OFFSET(offset) ((offset) & 0x007fffff)
21/***************************************************************************
22    CONSTANTS
23***************************************************************************/
3124
32#define STEP2(START,STEP)  (START),(START)+(STEP)
33#define STEP4(START,STEP)  STEP2(START,STEP),STEP2((START)+2*(STEP),STEP)
34#define STEP8(START,STEP)  STEP4(START,STEP),STEP4((START)+4*(STEP),STEP)
35#define STEP16(START,STEP) STEP8(START,STEP),STEP8((START)+8*(STEP),STEP)
36#define STEP32(START,STEP) STEP16(START,STEP),STEP16((START)+16*(STEP),STEP)
25#define MAX_GFX_PLANES         8
26#define MAX_GFX_SIZE         32
27#define MAX_ABS_GFX_SIZE      1024
3728
29#define EXTENDED_XOFFS         { 0 }
30#define EXTENDED_YOFFS         { 0 }
3831
39struct _gfx_layout
40{
41   UINT16 width,height;            /* width and height (in pixels) of chars/sprites */
42   UINT32 total;                  /* total number of chars/sprites in the rom */
43   UINT16 planes;                  /* number of bitplanes */
44   UINT32 planeoffset[MAX_GFX_PLANES]; /* start of every bitplane (in bits) */
45   UINT32 xoffset[MAX_GFX_SIZE];      /* position of the bit corresponding to the pixel */
46   UINT32 yoffset[MAX_GFX_SIZE];      /* of the given coordinates */
47   UINT32 charincrement;            /* distance between two consecutive characters/sprites (in bits) */
48   const UINT32 *extxoffs;            /* extended X offset array for really big layouts */
49   const UINT32 *extyoffs;            /* extended Y offset array for really big layouts */
50};
51typedef struct _gfx_layout gfx_layout;
32#define GFX_ELEMENT_PACKED      1   /* two 4bpp pixels are packed in one byte of gfxdata */
33#define GFX_ELEMENT_DONT_FREE   2   /* gfxdata was not malloc()ed, so don't free it on exit */
5234
53#define GFX_RAW 0x12345678
35#define GFX_RAW             0x12345678
5436/* When planeoffset[0] is set to GFX_RAW, the gfx data is left as-is, with no conversion.
5537   No buffer is allocated for the decoded data, and gfxdata is set to point to the source
5638   data; therefore, you must not use ROMREGION_DISPOSE.
5739   xoffset[0] is an optional displacement (*8) from the beginning of the source data, while
5840   yoffset[0] is the line modulo (*8) and charincrement the char modulo (*8). They are *8
5941   for consistency with the usual behaviour, but the bottom 3 bits are not used.
60   GFX_PACKED is automatically set if planes is <= 4.
42   GFX_ELEMENT_PACKED is automatically set if planes is <= 4.
6143
6244   This special mode can be used to save memory in games that require several different
6345   handlings of the same ROM data (e.g. metro.c can use both 4bpp and 8bpp tiles, and both
r936r937
6648   not be prerotated and will rely on GFX_SWAPXY.
6749*/
6850
69struct _gfx_element
51enum
7052{
71   UINT16 width,height;
53   TRANSPARENCY_NONE,         /* opaque with remapping */
54   TRANSPARENCY_NONE_RAW,      /* opaque with no remapping */
55   TRANSPARENCY_PEN,         /* single pen transparency with remapping */
56   TRANSPARENCY_PEN_RAW,      /* single pen transparency with no remapping */
57   TRANSPARENCY_PENS,         /* multiple pen transparency with remapping */
58   TRANSPARENCY_PENS_RAW,      /* multiple pen transparency with no remapping */
59   TRANSPARENCY_COLOR,         /* single remapped pen transparency with remapping */
60   TRANSPARENCY_PEN_TABLE,      /* special pen remapping modes (see DRAWMODE_xxx below) with remapping */
61   TRANSPARENCY_PEN_TABLE_RAW,   /* special pen remapping modes (see DRAWMODE_xxx below) with no remapping */
62   TRANSPARENCY_BLEND,         /* blend two bitmaps, shifting the source and ORing to the dest with remapping */
63   TRANSPARENCY_BLEND_RAW,      /* blend two bitmaps, shifting the source and ORing to the dest with no remapping */
64   TRANSPARENCY_ALPHA,         /* single pen transparency, other pens alpha */
65   TRANSPARENCY_ALPHARANGE,   /* single pen transparency, multiple pens alpha depending on array, see psikyosh.c */
7266
73   UINT32 total_elements;   /* total number of characters/sprites */
74   UINT16 color_granularity;   /* number of colors for each color code */
75                     /* (for example, 4 for 2 bitplanes gfx) */
76   UINT32 total_colors;
77   pen_t *colortable;   /* map color codes to screen pens */
78   UINT32 *pen_usage;   /* an array of total_elements entries. */
79                  /* It is a table of the pens each character uses */
80                  /* (bit 0 = pen 0, and so on). This is used by */
81                  /* drawgfgx() to do optimizations like skipping */
82                  /* drawing of a totally transparent character */
83   UINT8 *gfxdata;      /* pixel data */
84   UINT32 line_modulo;   /* amount to add to get to the next line (usually = width) */
85   UINT32 char_modulo;   /* = line_modulo * height */
86   UINT32 flags;
87   gfx_layout layout;   /* references the original layout */
67   TRANSPARENCY_MODES         /* total number of modes; must be last */
8868};
69
70enum
71{
72   DRAWMODE_NONE,
73   DRAWMODE_SOURCE,
74   DRAWMODE_SHADOW
75};
76
77
78
79/***************************************************************************
80    MACROS
81***************************************************************************/
82
83/* map old fillbitmap to new shared bitmap_fill code */
84#define fillbitmap(dest, pen, clip) bitmap_fill(dest, clip, pen)
85
86/* these macros describe gfx_layouts in terms of fractions of a region */
87/* they can be used for total, planeoffset, xoffset, yoffset */
88#define RGN_FRAC(num,den)      (0x80000000 | (((num) & 0x0f) << 27) | (((den) & 0x0f) << 23))
89#define IS_FRAC(offset)         ((offset) & 0x80000000)
90#define FRAC_NUM(offset)      (((offset) >> 27) & 0x0f)
91#define FRAC_DEN(offset)      (((offset) >> 23) & 0x0f)
92#define FRAC_OFFSET(offset)      ((offset) & 0x007fffff)
93
94/* these macros are useful in gfx_layouts */
95#define STEP2(START,STEP)      (START),(START)+(STEP)
96#define STEP4(START,STEP)      STEP2(START,STEP),STEP2((START)+2*(STEP),STEP)
97#define STEP8(START,STEP)      STEP4(START,STEP),STEP4((START)+4*(STEP),STEP)
98#define STEP16(START,STEP)      STEP8(START,STEP),STEP8((START)+8*(STEP),STEP)
99#define STEP32(START,STEP)      STEP16(START,STEP),STEP16((START)+16*(STEP),STEP)
100
101
102
103/***************************************************************************
104    TYPE DEFINITIONS
105***************************************************************************/
106
107typedef struct _gfx_layout gfx_layout;
108struct _gfx_layout
109{
110   UINT16         width;            /* pixel width of each element */
111   UINT16         height;            /* pixel height of each element */
112   UINT32         total;            /* total number of elements, or RGN_FRAC() */
113   UINT16         planes;            /* number of bitplanes */
114   UINT32         planeoffset[MAX_GFX_PLANES]; /* bit offset of each bitplane */
115   UINT32         xoffset[MAX_GFX_SIZE]; /* bit offset of each horizontal pixel */
116   UINT32         yoffset[MAX_GFX_SIZE]; /* bit offset of each vertical pixel */
117   UINT32         charincrement;      /* distance between two consecutive elements (in bits) */
118   const UINT32 *   extxoffs;         /* extended X offset array for really big layouts */
119   const UINT32 *   extyoffs;         /* extended Y offset array for really big layouts */
120};
121
122
89123/* In mamecore.h: typedef struct _gfx_element gfx_element; */
124struct _gfx_element
125{
126   UINT16         width;            /* pixel width of each element */
127   UINT16         height;            /* pixel height of each element */
128   UINT8         flags;            /* one of the GFX_ELEMENT_* flags above */
129   UINT32          total_elements;      /* total number of decoded elements */
90130
91#define GFX_PACKED            1   /* two 4bpp pixels are packed in one byte of gfxdata */
92#define GFX_SWAPXY            2   /* characters are mirrored along the top-left/bottom-right diagonal */
93#define GFX_DONT_FREE_GFXDATA   4   /* gfxdata was not malloc()ed, so don't free it on exit */
131   UINT32         color_base;         /* base color for rendering */
132   UINT16         color_depth;      /* number of colors each pixel can represent */
133   UINT16         color_granularity;   /* number of colors for each color code */
134   UINT32         total_colors;      /* number of color codes */
94135
136   UINT32 *      pen_usage;         /* bitmask of pens that are used (pens 0-31 only) */
95137
138   UINT8 *         gfxdata;         /* pixel data, 8bpp or 4bpp (if GFX_ELEMENT_PACKED) */
139   UINT32         line_modulo;      /* bytes between each row of data */
140   UINT32         char_modulo;      /* bytes between each element */
141   gfx_layout      layout;            /* copy of the original layout */
142};
143
144
96145typedef struct _gfx_decode gfx_decode;
97146struct _gfx_decode
98147{
99   int memory_region;   /* memory region where the data resides (usually 1) */
100                  /* -1 marks the end of the array */
101   UINT32 start;   /* beginning of data to decode */
102   const gfx_layout *gfxlayout;
103   UINT16 color_codes_start;   /* offset in the color lookup table where color codes start */
104   UINT16 total_color_codes;   /* total number of color codes */
105   UINT8 xscale, yscale;      /* optional pixel scaling factors */
148   int            memory_region;      /* memory region where the data resides; -1 marks the end of array */
149   UINT32          start;            /* offset of beginning of data to decode */
150   const gfx_layout *gfxlayout;      /* pointer to gfx_layout describing the layout */
151   UINT16          color_codes_start;   /* offset in the color lookup table where color codes start */
152   UINT16          total_color_codes;   /* total number of color codes */
153   UINT8          xscale;            /* optional horizontal scaling factor; 0 means 1x */
154   UINT8         yscale;            /* optional vertical scaling factor; 0 means 1x */
106155};
107156
108157
r936r937
113162   int      alphad;
114163};
115164
116enum
117{
118   TRANSPARENCY_NONE,         /* opaque with remapping */
119   TRANSPARENCY_NONE_RAW,      /* opaque with no remapping */
120   TRANSPARENCY_PEN,         /* single pen transparency with remapping */
121   TRANSPARENCY_PEN_RAW,      /* single pen transparency with no remapping */
122   TRANSPARENCY_PENS,         /* multiple pen transparency with remapping */
123   TRANSPARENCY_PENS_RAW,      /* multiple pen transparency with no remapping */
124   TRANSPARENCY_COLOR,         /* single remapped pen transparency with remapping */
125   TRANSPARENCY_PEN_TABLE,      /* special pen remapping modes (see DRAWMODE_xxx below) with remapping */
126   TRANSPARENCY_PEN_TABLE_RAW,   /* special pen remapping modes (see DRAWMODE_xxx below) with no remapping */
127   TRANSPARENCY_BLEND,         /* blend two bitmaps, shifting the source and ORing to the dest with remapping */
128   TRANSPARENCY_BLEND_RAW,      /* blend two bitmaps, shifting the source and ORing to the dest with no remapping */
129   TRANSPARENCY_ALPHA,         /* single pen transparency, other pens alpha */
130   TRANSPARENCY_ALPHARANGE,   /* single pen transparency, multiple pens alpha depending on array, see psikyosh.c */
131165
132   TRANSPARENCY_MODES         /* total number of modes; must be last */
133};
134166
167/***************************************************************************
168    GLOBAL VARIABLES
169***************************************************************************/
170
135171/* drawing mode case TRANSPARENCY_ALPHARANGE */
136172extern UINT8 gfx_alpharange_table[256];
137173
138174/* drawing mode case TRANSPARENCY_PEN_TABLE */
139175extern UINT8 gfx_drawmode_table[256];
140enum
141{
142   DRAWMODE_NONE,
143   DRAWMODE_SOURCE,
144   DRAWMODE_SHADOW
145};
146176
147177/* By default, when drawing sprites with pdrawgfx, shadows affect the sprites below them. */
148178/* Set this flag to 1 to make shadows only affect the background, leaving sprites at full brightness. */
149179extern int pdrawgfx_shadow_lowpri;
150180
151181
182
183/***************************************************************************
184    FUNCTION PROTOTYPES
185***************************************************************************/
186
152187void drawgfx_init(running_machine *machine);
153188
189
154190void decodechar(gfx_element *gfx,int num,const unsigned char *src,const gfx_layout *gl);
155191gfx_element *allocgfx(const gfx_layout *gl);
156192void decodegfx(gfx_element *gfx, const UINT8 *src, UINT32 first, UINT32 count);
157193void freegfx(gfx_element *gfx);
194
195
158196void drawgfx(mame_bitmap *dest,const gfx_element *gfx,
159197      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
160198      const rectangle *clip,int transparency,int transparent_color);
r936r937
166204      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
167205      const rectangle *clip,int transparency,int transparent_color,
168206      UINT32 priority_mask);
207
208
209void drawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
210      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
211      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley);
212void pdrawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
213      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
214      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley,
215      UINT32 priority_mask);
216void mdrawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
217      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
218      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley,
219      UINT32 priority_mask);
220
221
222void draw_scanline8(mame_bitmap *bitmap,int x,int y,int length,const UINT8 *src,const pen_t *pens,int transparent_pen);
223void draw_scanline16(mame_bitmap *bitmap,int x,int y,int length,const UINT16 *src,const pen_t *pens,int transparent_pen);
224void pdraw_scanline8(mame_bitmap *bitmap,int x,int y,int length,const UINT8 *src,const pen_t *pens,int transparent_pen,int pri);
225void pdraw_scanline16(mame_bitmap *bitmap,int x,int y,int length,const UINT16 *src,const pen_t *pens,int transparent_pen,int pri);
226void extract_scanline8(mame_bitmap *bitmap,int x,int y,int length,UINT8 *dst);
227void extract_scanline16(mame_bitmap *bitmap,int x,int y,int length,UINT16 *dst);
228
229
169230void copybitmap(mame_bitmap *dest,mame_bitmap *src,int flipx,int flipy,int sx,int sy,
170231      const rectangle *clip,int transparency,int transparent_color);
171232void copybitmap_remap(mame_bitmap *dest,mame_bitmap *src,int flipx,int flipy,int sx,int sy,
r936r937
176237void copyscrollbitmap_remap(mame_bitmap *dest,mame_bitmap *src,
177238      int rows,const int *rowscroll,int cols,const int *colscroll,
178239      const rectangle *clip,int transparency,int transparent_color);
179void draw_scanline8(mame_bitmap *bitmap,int x,int y,int length,const UINT8 *src,pen_t *pens,int transparent_pen);
180void draw_scanline16(mame_bitmap *bitmap,int x,int y,int length,const UINT16 *src,pen_t *pens,int transparent_pen);
181void pdraw_scanline8(mame_bitmap *bitmap,int x,int y,int length,const UINT8 *src,pen_t *pens,int transparent_pen,int pri);
182void pdraw_scanline16(mame_bitmap *bitmap,int x,int y,int length,const UINT16 *src,pen_t *pens,int transparent_pen,int pri);
183void extract_scanline8(mame_bitmap *bitmap,int x,int y,int length,UINT8 *dst);
184void extract_scanline16(mame_bitmap *bitmap,int x,int y,int length,UINT16 *dst);
185240
186
187241/*
188242  Copy a bitmap applying rotation, zooming, and arbitrary distortion.
189243  This function works in a way that mimics some real hardware like the Konami
r936r937
216270      UINT32 startx,UINT32 starty,int incxx,int incxy,int incyx,int incyy,int wraparound,
217271      const rectangle *clip,int transparency,int transparent_color,UINT32 priority);
218272
219#define fillbitmap(dest, pen, clip) bitmap_fill(dest, clip, pen)
220273
221void fillbitmap(mame_bitmap *dest,pen_t pen,const rectangle *clip);
222void drawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
223      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
224      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley);
225void pdrawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
226      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
227      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley,
228      UINT32 priority_mask);
229void mdrawgfxzoom( mame_bitmap *dest_bmp,const gfx_element *gfx,
230      unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
231      const rectangle *clip,int transparency,int transparent_color,int scalex,int scaley,
232      UINT32 priority_mask);
233274
275/***************************************************************************
276    INLINE FUNCTIONS
277***************************************************************************/
234278
235
236279/* Alpha blending functions */
237280INLINE void alpha_set_level(int level)
238281{
src/emu/fileio.c
r936r937
8484static file_error fopen_internal(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 flags, mame_file **file);
8585static file_error fopen_attempt_zipped(astring *fullname, UINT32 crc, UINT32 openflags, mame_file *file);
8686
87/* CHD callbacks */
88static chd_interface_file *chd_open_cb(const char *filename, const char *mode);
89static void chd_close_cb(chd_interface_file *file);
90static UINT32 chd_read_cb(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
91static UINT32 chd_write_cb(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
92static UINT64 chd_length_cb(chd_interface_file *file);
93
9487/* path iteration */
9588static void path_iterator_init(path_iterator *iterator, core_options *opts, const char *searchpath);
9689static int path_iterator_get_next(path_iterator *iterator, astring *buffer);
r936r937
10295
10396
10497/***************************************************************************
105    HARD DISK INTERFACE
106***************************************************************************/
107
108static chd_interface mame_chd_interface =
109{
110   chd_open_cb,
111   chd_close_cb,
112   chd_read_cb,
113   chd_write_cb,
114   chd_length_cb
115};
116
117
118
119/***************************************************************************
12098    CORE FUNCTIONS
12199***************************************************************************/
122100
r936r937
128106
129107void fileio_init(running_machine *machine)
130108{
131   chd_set_interface(&mame_chd_interface);
132109   add_exit_callback(machine, fileio_exit);
133110}
134111
r936r937
752729
753730
754731/***************************************************************************
755    CHD CALLBACKS
756***************************************************************************/
757
758/*-------------------------------------------------
759    chd_open_cb - interface for opening
760    a hard disk image
761-------------------------------------------------*/
762
763chd_interface_file *chd_open_cb(const char *filename, const char *mode)
764{
765   file_error filerr;
766   mame_file *file;
767
768   /* look for read-only drives first in the ROM path */
769   if (mode[0] == 'r' && !strchr(mode, '+'))
770   {
771      astring *path = astring_alloc();
772      const game_driver *drv;
773
774      /* attempt reading up the chain through the parents */
775      for (drv = Machine->gamedrv; drv != NULL; drv = driver_get_clone(drv))
776      {
777         /* build up drv->name/filename in the path */
778         astring_cpyc(path, drv->name);
779         astring_catc(path, PATH_SEPARATOR);
780         astring_catc(path, filename);
781
782         /* attempt to open */
783         filerr = mame_fopen(SEARCHPATH_IMAGE, astring_c(path), OPEN_FLAG_READ, &file);
784         if (filerr == FILERR_NONE)
785         {
786            astring_free(path);
787            return (chd_interface_file *)file;
788         }
789      }
790      astring_free(path);
791      return NULL;
792   }
793
794   /* look for read/write drives in the diff area */
795   filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE, &file);
796   if (filerr != FILERR_NONE)
797      filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
798   return (filerr == FILERR_NONE) ? (chd_interface_file *)file : NULL;
799}
800
801
802/*-------------------------------------------------
803    chd_close_cb - interface for closing
804    a hard disk image
805-------------------------------------------------*/
806
807void chd_close_cb(chd_interface_file *file)
808{
809   mame_fclose((mame_file *)file);
810}
811
812
813/*-------------------------------------------------
814    chd_read_cb - interface for reading
815    from a hard disk image
816-------------------------------------------------*/
817
818UINT32 chd_read_cb(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
819{
820   mame_fseek((mame_file *)file, offset, SEEK_SET);
821   return mame_fread((mame_file *)file, buffer, count);
822}
823
824
825/*-------------------------------------------------
826    chd_write_cb - interface for writing
827    to a hard disk image
828-------------------------------------------------*/
829
830UINT32 chd_write_cb(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
831{
832   mame_fseek((mame_file *)file, offset, SEEK_SET);
833   return mame_fwrite((mame_file *)file, buffer, count);
834}
835
836
837/*-------------------------------------------------
838    chd_length_cb - interface for getting
839    the length a hard disk image
840-------------------------------------------------*/
841
842UINT64 chd_length_cb(chd_interface_file *file)
843{
844   return mame_fsize((mame_file *)file);
845}
846
847
848
849/***************************************************************************
850732    PATH ITERATION
851733***************************************************************************/
852734
src/emu/render.c
r936r937
155155   INT32            height;            /* height in pixels */
156156   render_bounds      bounds;            /* bounds of the target */
157157   float            pixel_aspect;      /* aspect ratio of individual pixels */
158   float            max_refresh;      /* maximum refresh rate, 0 or if none */
158159   int               orientation;      /* orientation */
159160   int               layerconfig;      /* layer configuration */
160161   layout_view *      base_view;         /* the view at the time of first frame */
r936r937
194195   float            yoffset;         /* Y offset of the container */
195196   mame_bitmap *      overlaybitmap;      /* overlay bitmap */
196197   render_texture *   overlaytexture;      /* overlay texture */
198   palette_client *   palclient;         /* client to the system palette */
197199   rgb_t            bcglookup256[0x400];/* lookup table for brightness/contrast/gamma */
198200   rgb_t            bcglookup32[0x80];   /* lookup table for brightness/contrast/gamma */
199201   rgb_t            bcglookup[0x10000];   /* full palette lookup with bcg adjustements */
r936r937
254256/* render targets */
255257static void release_render_list(render_primitive_list *list);
256258static int load_layout_files(render_target *target, const char *layoutfile, int singlefile);
257static void add_container_primitives(render_target *target, render_primitive_list *list, const object_transform *xform, const render_container *container, int blendmode);
259static void add_container_primitives(render_target *target, render_primitive_list *list, const object_transform *xform, render_container *container, int blendmode);
258260static void add_element_primitives(render_target *target, render_primitive_list *list, const object_transform *xform, const layout_element *element, int state, int blendmode);
259261static void add_clear_and_optimize_primitive_list(render_target *target, render_primitive_list *list);
260262
r936r937
270272static container_item *render_container_item_add_generic(render_container *container, UINT8 type, float x0, float y0, float x1, float y1, rgb_t argb);
271273static void render_container_overlay_scale(mame_bitmap *dest, const mame_bitmap *source, const rectangle *sbounds, void *param);
272274static void render_container_recompute_lookups(render_container *container);
273static void render_container_update_palette(void *param, int entry, rgb_t newval);
275static void render_container_update_palette(render_container *container);
274276
275277
276278
r936r937
875877
876878
877879/*-------------------------------------------------
878    render_set_ui_target - return the UI target
880    render_get_max_update_rate - return the
881    smallest maximum update rate across all targets
879882-------------------------------------------------*/
880883
884float render_get_max_update_rate(void)
885{
886   render_target *target;
887   float minimum = 0;
888
889   /* iterate over all live targets and or together their screen masks */
890   for (target = targetlist; target != NULL; target = target->next)
891      if (target->max_refresh != 0)
892      {
893         if (minimum == 0)
894            minimum = target->max_refresh;
895         else
896            minimum = MIN(target->max_refresh, minimum);
897      }
898
899   return minimum;
900}
901
902
903/*-------------------------------------------------
904    render_set_ui_target - select the UI target
905-------------------------------------------------*/
906
881907void render_set_ui_target(render_target *target)
882908{
883909   assert(target != NULL);
r936r937
11431169
11441170
11451171/*-------------------------------------------------
1172    render_target_get_max_update_rate - get the
1173    maximum update rate (refresh rate) of a target,
1174    or 0 if no maximum
1175-------------------------------------------------*/
1176
1177float render_target_get_max_update_rate(render_target *target)
1178{
1179   return target->max_refresh;
1180}
1181
1182
1183/*-------------------------------------------------
1184    render_target_set_max_update_rate - set the
1185    maximum update rate (refresh rate) of a target,
1186    or 0 if no maximum
1187-------------------------------------------------*/
1188
1189void render_target_set_max_update_rate(render_target *target, float updates_per_second)
1190{
1191   target->max_refresh = updates_per_second;
1192}
1193
1194
1195/*-------------------------------------------------
11461196    render_target_get_orientation - get the
11471197    orientation of a target
11481198-------------------------------------------------*/
r936r937
16161666    based on the container
16171667-------------------------------------------------*/
16181668
1619static void add_container_primitives(render_target *target, render_primitive_list *list, const object_transform *xform, const render_container *container, int blendmode)
1669static void add_container_primitives(render_target *target, render_primitive_list *list, const object_transform *xform, render_container *container, int blendmode)
16201670{
16211671   object_transform container_xform;
16221672   render_bounds cliprect;
16231673   render_primitive *prim;
16241674   container_item *item;
16251675
1676   /* first update the palette for the container, if it is dirty */
1677   render_container_update_palette(container);
1678
16261679   /* compute the clip rect */
16271680   cliprect.x0 = xform->xoffs;
16281681   cliprect.y0 = xform->yoffs;
r936r937
17221775                  /* override the palette with our adjusted palette */
17231776                  switch (item->texture->format)
17241777                  {
1725                     case TEXFORMAT_PALETTE16:   prim->texture.palette = &container->bcglookup[prim->texture.palette - palette_get_adjusted_colors(Machine)]; break;
1726                     case TEXFORMAT_PALETTEA16:   prim->texture.palette = &container->bcglookup[prim->texture.palette - palette_get_adjusted_colors(Machine)]; break;
1778                     case TEXFORMAT_PALETTE16:   prim->texture.palette = &container->bcglookup[prim->texture.palette - palette_entry_list_adjusted(Machine->palette)]; break;
1779                     case TEXFORMAT_PALETTEA16:   prim->texture.palette = &container->bcglookup[prim->texture.palette - palette_entry_list_adjusted(Machine->palette)]; break;
17271780                     case TEXFORMAT_RGB15:      prim->texture.palette = &container->bcglookup32[0];      break;
17281781                     case TEXFORMAT_RGB32:      prim->texture.palette = &container->bcglookup256[0];   break;
17291782                     case TEXFORMAT_ARGB32:      prim->texture.palette = &container->bcglookup256[0];   break;
r936r937
22732326static int render_texture_get_scaled(render_texture *texture, UINT32 dwidth, UINT32 dheight, render_texinfo *texinfo, render_ref **reflist)
22742327{
22752328   UINT8 bpp = (texture->format == TEXFORMAT_PALETTE16 || texture->format == TEXFORMAT_PALETTEA16 || texture->format == TEXFORMAT_RGB15 || texture->format == TEXFORMAT_YUY16) ? 16 : 32;
2276   const rgb_t *palbase = (texture->format == TEXFORMAT_PALETTE16 || texture->format == TEXFORMAT_PALETTEA16) ? palette_get_adjusted_colors(Machine) + texture->palettebase : NULL;
2329   const rgb_t *palbase = (texture->format == TEXFORMAT_PALETTE16 || texture->format == TEXFORMAT_PALETTEA16) ? palette_entry_list_adjusted(Machine->palette) + texture->palettebase : NULL;
22772330   scaled_texture *scaled = NULL;
22782331   int swidth, sheight;
22792332   int scalenum;
r936r937
23982451   /* make sure it is empty */
23992452   render_container_empty(container);
24002453
2401   /* allocate a notifier */
2454   /* allocate a client to the main palette */
2455   if (Machine->palette != NULL)
2456      container->palclient = palette_client_alloc(Machine->palette);
24022457   render_container_recompute_lookups(container);
2403   palette_add_notifier(Machine, render_container_update_palette, container);
24042458   return container;
24052459}
24062460
r936r937
24192473   if (container->overlaytexture != NULL)
24202474      render_texture_free(container->overlaytexture);
24212475
2476   /* release our palette client */
2477   if (container->palclient != NULL)
2478      palette_client_free(container->palclient);
2479
24222480   /* free the container itself */
24232481   free(container);
24242482}
r936r937
26362694
26372695/*-------------------------------------------------
26382696    render_container_set_overlay - set the
2639    orientation of a container
2697    overlay bitmap for the container
26402698-------------------------------------------------*/
26412699
26422700void render_container_set_overlay(render_container *container, mame_bitmap *bitmap)
r936r937
28032861
28042862static void render_container_recompute_lookups(render_container *container)
28052863{
2806   pen_t *adjusted_palette = palette_get_adjusted_colors(Machine);
2807   int colors = palette_get_total_colors_with_ui(Machine);
28082864   int i;
28092865
28102866   /* recompute the 256 entry lookup table */
r936r937
28282884   }
28292885
28302886   /* recompute the palette entries */
2831   for (i = 0; i < colors; i++)
2887   if (container->palclient != NULL)
28322888   {
2833      pen_t newval = adjusted_palette[i];
2834      container->bcglookup[i] = (container->bcglookup[i] & 0xff000000) |
2835                          container->bcglookup256[0x200 + RGB_RED(newval)] |
2836                          container->bcglookup256[0x100 + RGB_GREEN(newval)] |
2837                          container->bcglookup256[0x000 + RGB_BLUE(newval)];
2889      palette_t *palette = palette_client_get_palette(container->palclient);
2890      const pen_t *adjusted_palette = palette_entry_list_adjusted(palette);
2891      int colors = palette_get_num_colors(palette) * palette_get_num_groups(palette);
2892
2893      for (i = 0; i < colors; i++)
2894      {
2895         pen_t newval = adjusted_palette[i];
2896         container->bcglookup[i] = (container->bcglookup[i] & 0xff000000) |
2897                             container->bcglookup256[0x200 + RGB_RED(newval)] |
2898                             container->bcglookup256[0x100 + RGB_GREEN(newval)] |
2899                             container->bcglookup256[0x000 + RGB_BLUE(newval)];
2900      }
28382901   }
28392902}
28402903
28412904
28422905/*-------------------------------------------------
28432906    render_container_update_palette - update
2844    a single palette entry
2907    any dirty palette entries
28452908-------------------------------------------------*/
28462909
2847static void render_container_update_palette(void *param, int entry, rgb_t newval)
2910static void render_container_update_palette(render_container *container)
28482911{
2849   render_container *container = param;
2850   assert(entry < ARRAY_LENGTH(container->bcglookup));
2851   container->bcglookup[entry] = (container->bcglookup[entry] & 0xff000000) |
2852                          container->bcglookup256[0x200 + RGB_RED(newval)] |
2853                          container->bcglookup256[0x100 + RGB_GREEN(newval)] |
2854                          container->bcglookup256[0x000 + RGB_BLUE(newval)];
2912   UINT32 mindirty, maxdirty;
2913   const UINT32 *dirty;
2914
2915   /* skip if no client */
2916   if (container->palclient == NULL)
2917      return;
2918
2919   /* get the dirty list */
2920   dirty = palette_client_get_dirty_list(container->palclient, &mindirty, &maxdirty);
2921
2922   /* iterate over dirty items and update them */
2923   if (dirty != NULL)
2924   {
2925      palette_t *palette = palette_client_get_palette(container->palclient);
2926      const pen_t *adjusted_palette = palette_entry_list_adjusted(palette);
2927      UINT32 entry32, entry;
2928
2929      /* loop over chunks of 32 entries, since we can quickly examine 32 at a time */
2930      for (entry32 = mindirty / 32; entry32 <= maxdirty / 32; entry32++)
2931      {
2932         UINT32 dirtybits = dirty[entry32];
2933         if (dirtybits != 0)
2934
2935            /* this chunk of 32 has dirty entries; fix them up */
2936            for (entry = 0; entry < 32; entry++)
2937               if (dirtybits & (1 << entry))
2938               {
2939                  UINT32 finalentry = entry32 * 32 + entry;
2940                  rgb_t newval = adjusted_palette[finalentry];
2941                  container->bcglookup[finalentry] = (container->bcglookup[finalentry] & 0xff000000) |
2942                                         container->bcglookup256[0x200 + RGB_RED(newval)] |
2943                                         container->bcglookup256[0x100 + RGB_GREEN(newval)] |
2944                                         container->bcglookup256[0x000 + RGB_BLUE(newval)];
2945               }
2946      }
2947   }
28552948}
src/emu/clifront.c
r936r937
562562         expand_machine_driver(drivers[drvindex]->drv, &drv);
563563
564564         /* find samples interfaces */
565         for (sndnum = 0; sndnum < MAX_SOUND && drv.sound[sndnum].sound_type; sndnum++)
565         for (sndnum = 0; sndnum < MAX_SOUND && drv.sound[sndnum].sound_type != SOUND_DUMMY; sndnum++)
566566            if (drv.sound[sndnum].sound_type == SOUND_SAMPLES)
567567            {
568568               const char **samplenames = ((struct Samplesinterface *)drv.sound[sndnum].config)->samplenames;
src/emu/emupal.c
r0r937
1/******************************************************************************
2
3    emupal.c
4
5    Emulator palette handling functions.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10******************************************************************************/
11
12#include "driver.h"
13#include <math.h>
14
15#define VERBOSE 0
16
17
18/***************************************************************************
19    CONSTANTS
20***************************************************************************/
21
22#define PEN_BRIGHTNESS_BITS      8
23#define MAX_PEN_BRIGHTNESS      (4 << PEN_BRIGHTNESS_BITS)
24#define MAX_SHADOW_PRESETS       4
25
26
27
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
32/* information about a shadow table */
33typedef struct _shadow_table_data shadow_table_data;
34struct _shadow_table_data
35{
36   UINT32 *         base;            /* pointer to the base of the table */
37   INT16            dr;               /* delta red value */
38   INT16            dg;               /* delta green value */
39   INT16            db;               /* delta blue value */
40   UINT8            noclip;            /* clip? */
41};
42
43
44/* typedef struct _palette_private palette_private; */
45struct _palette_private
46{
47   bitmap_format      format;            /* format assumed for palette data */
48
49   UINT32             shadow_group;      /* index of the shadow group, or 0 if none */
50   UINT32            hilight_group;      /* index of the hilight group, or 0 if none */
51
52   pen_t             black_pen;         /* precomputed black pen value */
53   pen_t            white_pen;         /* precomputed white pen value */
54
55   shadow_table_data   shadow_table[MAX_SHADOW_PRESETS]; /* array of shadow table data */
56
57   pen_t *            save_pen;         /* pens for save/restore */
58   float *            save_bright;      /* brightness for save/restore */
59};
60
61
62/* typedef struct _colortable colortable; */
63struct _colortable
64{
65   running_machine *   machine;         /* associated machine */
66   UINT32            entries;         /* number of entries */
67   UINT32            palentries;         /* number of palette entries */
68   UINT16 *         raw;            /* raw data about each entry */
69   rgb_t *            palette;         /* palette entries */
70};
71
72
73
74/***************************************************************************
75    FUNCTION PROTOTYPES
76***************************************************************************/
77
78static void palette_presave(void);
79static void palette_postload(void);
80static void palette_exit(running_machine *machine);
81static void allocate_palette(running_machine *machine, palette_private *palette);
82static void allocate_color_tables(running_machine *machine, palette_private *palette);
83static void allocate_shadow_tables(running_machine *machine, palette_private *palette);
84static void configure_rgb_shadows(running_machine *machine, int mode, float factor);
85
86
87
88/***************************************************************************
89    INITIALIZATION AND CONFIGURATION
90***************************************************************************/
91
92/*-------------------------------------------------
93    palette_init - palette initialization that
94    takes place before the display is created
95-------------------------------------------------*/
96
97void palette_init(running_machine *machine)
98{
99   palette_private *palette = auto_malloc(sizeof(*palette));
100
101   /* request cleanup */
102   machine->palette_data = palette;
103   add_exit_callback(machine, palette_exit);
104
105   /* reset all our data */
106   memset(palette, 0, sizeof(*palette));
107   palette->format = machine->screen[0].format;
108
109   /* determine the color mode */
110   switch (palette->format)
111   {
112      case BITMAP_FORMAT_INDEXED16:
113         /* indexed modes are fine for everything */
114         break;
115
116      case BITMAP_FORMAT_RGB15:
117      case BITMAP_FORMAT_RGB32:
118         /* RGB modes can't use color tables */
119         assert(machine->drv->color_table_len == 0);
120         break;
121
122      case BITMAP_FORMAT_INVALID:
123         /* invalid format means no palette - or at least it should */
124         assert(machine->drv->total_colors == 0);
125         assert(machine->drv->color_table_len == 0);
126         return;
127
128      default:
129         fatalerror("Unsupported screen bitmap format!");
130         break;
131   }
132
133   /* allocate all the data structures */
134   if (machine->drv->total_colors > 0)
135   {
136      int numcolors;
137
138      allocate_palette(machine, palette);
139      allocate_color_tables(machine, palette);
140      allocate_shadow_tables(machine, palette);
141
142      /* set up save/restore of the palette */
143      numcolors = palette_get_num_colors(machine->palette);
144      palette->save_pen = auto_malloc(sizeof(*palette->save_pen) * numcolors);
145      palette->save_bright = auto_malloc(sizeof(*palette->save_bright) * numcolors);
146      state_save_register_global_pointer(palette->save_pen, numcolors);
147      state_save_register_global_pointer(palette->save_bright, numcolors);
148      state_save_register_func_presave(palette_presave);
149      state_save_register_func_postload(palette_postload);
150   }
151}
152
153
154/*-------------------------------------------------
155    palette_config - palette initialization that
156    takes place after the display is created
157-------------------------------------------------*/
158
159void palette_config(running_machine *machine)
160{
161   int total_colors = (machine->palette == NULL) ? 0 : palette_get_num_colors(machine->palette) * palette_get_num_groups(machine->palette);
162   pen_t *remapped_colortable = NULL;
163   UINT16 *colortable = NULL;
164   int i;
165
166   /* allocate memory for the colortables, if needed */
167   if (machine->drv->color_table_len > 0)
168   {
169      /* first for the raw colortable */
170      colortable = auto_malloc(machine->drv->color_table_len * sizeof(colortable[0]));
171      for (i = 0; i < machine->drv->color_table_len; i++)
172         colortable[i] = i % total_colors;
173
174      /* then for the remapped colortable */
175      remapped_colortable = auto_malloc(machine->drv->color_table_len * sizeof(remapped_colortable[0]));
176   }
177
178   /* now let the driver modify the initial palette and colortable */
179   if (machine->drv->init_palette)
180      (*machine->drv->init_palette)(machine, colortable, memory_region(REGION_PROMS));
181
182   /* now compute the remapped_colortable */
183   for (i = 0; i < machine->drv->color_table_len; i++)
184   {
185      pen_t color = colortable[i];
186
187      /* check for invalid colors set by machine->drv->init_palette */
188      assert(color < total_colors);
189      remapped_colortable[i] = machine->pens[color];
190   }
191
192   /* now we can set the final colortables */
193   machine->game_colortable = colortable;
194   machine->remapped_colortable = (remapped_colortable != NULL) ? remapped_colortable : machine->pens;
195
196   /* set the color table base for each graphics element */
197   for (i = 0; i < MAX_GFX_ELEMENTS; i++)
198      if (machine->gfx[i] != NULL)
199         machine->gfx[i]->color_base = machine->drv->gfxdecodeinfo[i].color_codes_start;
200}
201
202
203
204/***************************************************************************
205    SHADOW/HIGHLIGHT CONFIGURATION
206***************************************************************************/
207
208/*-------------------------------------------------
209    palette_set_shadow_factor - set the global
210    shadow brightness factor
211-------------------------------------------------*/
212
213void palette_set_shadow_factor(running_machine *machine, double factor)
214{
215   palette_private *palette = machine->palette_data;
216
217   assert(palette->shadow_group != 0);
218   palette_group_set_contrast(machine->palette, palette->shadow_group, factor);
219}
220
221
222/*-------------------------------------------------
223    palette_set_highlight_factor - set the global
224    highlight brightness factor
225-------------------------------------------------*/
226
227void palette_set_highlight_factor(running_machine *machine, double factor)
228{
229   palette_private *palette = machine->palette_data;
230
231   assert(palette->hilight_group != 0);
232   palette_group_set_contrast(machine->palette, palette->hilight_group, factor);
233}
234
235
236
237/***************************************************************************
238    SHADOW TABLE CONFIGURATION
239***************************************************************************/
240
241/*-------------------------------------------------
242    palette_set_shadow_mode(mode)
243
244        mode: 0 = use preset 0 (default shadow)
245              1 = use preset 1 (default highlight)
246              2 = use preset 2 *
247              3 = use preset 3 *
248
249    * Preset 2 & 3 work independently under 32bpp,
250      supporting up to four different types of
251      shadows at one time. They mirror preset 1 & 2
252      in lower depth settings to maintain
253      compatibility.
254
255
256    palette_set_shadow_dRGB32(mode, dr, dg, db, noclip)
257
258        mode:    0 to   3 (which preset to configure)
259
260          dr: -255 to 255 ( red displacement )
261          dg: -255 to 255 ( green displacement )
262          db: -255 to 255 ( blue displacement )
263
264        noclip: 0 = resultant RGB clipped at 0x00/0xff
265                1 = resultant RGB wraparound 0x00/0xff
266
267
268    * Color shadows only work under 32bpp.
269      This function has no effect in lower color
270      depths where
271
272        palette_set_shadow_factor() or
273        palette_set_highlight_factor()
274
275      should be used instead.
276
277    * 32-bit shadows are lossy. Even with zero RGB
278      displacements the affected area will still look
279      slightly darkened.
280
281      Drivers should ensure all shadow pens in
282      gfx_drawmode_table[] are set to DRAWMODE_NONE
283      when RGB displacements are zero to avoid the
284      darkening effect.
285-------------------------------------------------*/
286
287/*-------------------------------------------------
288    palette_set_shadow_mode - select 1 of 4
289    different live shadow tables
290-------------------------------------------------*/
291
292void palette_set_shadow_mode(running_machine *machine, int mode)
293{
294   palette_private *palette = machine->palette_data;
295   assert(mode >= 0 && mode < MAX_SHADOW_PRESETS);
296   machine->shadow_table = palette->shadow_table[mode].base;
297}
298
299
300/*-------------------------------------------------
301    palette_set_shadow_dRGB32 - configure delta
302    RGB values for 1 of 4 shadow tables
303-------------------------------------------------*/
304
305void palette_set_shadow_dRGB32(running_machine *machine, int mode, int dr, int dg, int db, int noclip)
306{
307   palette_private *palette = machine->palette_data;
308   shadow_table_data *stable = &palette->shadow_table[mode];
309   int i;
310
311   /* only applies to RGB direct modes */
312   assert(palette->format != BITMAP_FORMAT_INDEXED16);
313   assert(stable->base != NULL);
314
315   /* clamp the deltas (why?) */
316   if (dr < -0xff) dr = -0xff; else if (dr > 0xff) dr = 0xff;
317   if (dg < -0xff) dg = -0xff; else if (dg > 0xff) dg = 0xff;
318   if (db < -0xff) db = -0xff; else if (db > 0xff) db = 0xff;
319
320   /* early exit if nothing changed */
321   if (dr == stable->dr && dg == stable->dg && db == stable->db && noclip == stable->noclip)
322      return;
323   stable->dr = dr;
324   stable->dg = dg;
325   stable->db = db;
326   stable->noclip = noclip;
327
328   #if VERBOSE
329      popmessage("shadow %d recalc %d %d %d %02x", mode, dr, dg, db, noclip);
330   #endif
331
332   /* regenerate the table */
333   for (i = 0; i < 32768; i++)
334   {
335      int r = pal5bit(i >> 10) + dr;
336      int g = pal5bit(i >> 5) + dg;
337      int b = pal5bit(i >> 0) + db;
338      pen_t final;
339
340      /* apply clipping */
341      if (!noclip)
342      {
343         r = rgb_clamp(r);
344         g = rgb_clamp(g);
345         b = rgb_clamp(b);
346      }
347      final = MAKE_RGB(r, g, b);
348
349      /* store either 16 or 32 bit */
350      if (palette->format == BITMAP_FORMAT_RGB32)
351         stable->base[i] = final;
352      else
353         stable->base[i] = rgb_to_rgb15(final);
354   }
355}
356
357
358
359/***************************************************************************
360    COLORTABLE MANAGEMENT
361***************************************************************************/
362
363/*-------------------------------------------------
364    colortable_alloc - allocate a new colortable
365    with the given number of entries
366-------------------------------------------------*/
367
368colortable *colortable_alloc(running_machine *machine, UINT32 palettesize)
369{
370   colortable *ctable;
371   UINT32 index;
372
373   /* allocate the colortable */
374   ctable = auto_malloc(sizeof(*ctable));
375   memset(ctable, 0, sizeof(*ctable));
376
377   /* fill in the basics */
378   ctable->machine = machine;
379   ctable->entries = machine->drv->total_colors;
380   ctable->palentries = palettesize;
381
382   /* allocate the raw colortable */
383   ctable->raw = auto_malloc(ctable->entries * sizeof(*ctable->raw));
384   for (index = 0; index < ctable->entries; index++)
385      ctable->raw[index] = index % ctable->palentries;
386
387   /* allocate the palette */
388   ctable->palette = auto_malloc(ctable->palentries * sizeof(*ctable->palette));
389   for (index = 0; index < ctable->palentries; index++)
390      ctable->palette[index] = RGB_BLACK;
391
392   return ctable;
393}
394
395
396/*-------------------------------------------------
397    colortable_entry_set_value - set the value
398    of a colortable entry
399-------------------------------------------------*/
400
401void colortable_entry_set_value(colortable *ctable, UINT32 entry, UINT16 value)
402{
403   /* ensure values are within range */
404   assert(entry < ctable->entries);
405   assert(value < ctable->palentries);
406
407   /* update if it has changed */
408   if (ctable->raw[entry] != value)
409   {
410      ctable->raw[entry] = value;
411      palette_set_color(ctable->machine, entry, ctable->palette[value]);
412   }
413}
414
415
416/*-------------------------------------------------
417    colortable_entry_get_value - return the value
418    of a colortable entry
419-------------------------------------------------*/
420
421UINT16 colortable_entry_get_value(colortable *ctable, UINT32 entry)
422{
423   assert(entry < ctable->entries);
424   return ctable->raw[entry];
425}
426
427
428/*-------------------------------------------------
429    colortable_palette_set_color - change the
430    color of a colortable palette entry
431-------------------------------------------------*/
432
433void colortable_palette_set_color(colortable *ctable, UINT32 entry, rgb_t color)
434{
435   /* ensure values are within range */
436   assert(entry < ctable->palentries);
437
438   /* update if it has changed */
439   if (ctable->palette[entry] != color)
440   {
441      UINT32 index;
442
443      ctable->palette[entry] = color;
444
445      /* update the palette for any colortable entries that reference it */
446      for (index = 0; index < ctable->entries; index++)
447         if (ctable->raw[index] == entry)
448            palette_set_color(ctable->machine, index, color);
449   }
450}
451
452
453/*-------------------------------------------------
454    colortable_entry_get_value - return the color
455    of a colortable palette entry
456-------------------------------------------------*/
457
458rgb_t colortable_palette_get_color(colortable *ctable, UINT32 entry)
459{
460   assert(entry < ctable->palentries);
461   return ctable->palette[entry];
462}
463
464
465/*-------------------------------------------------
466    colortable_get_transpen_mask - return a 32-bit
467    transparency mask for a given gfx element and
468    color
469-------------------------------------------------*/
470
471UINT32 colortable_get_transpen_mask(colortable *ctable, const gfx_element *gfx, int color, int transcolor)
472{
473   UINT32 entry = gfx->color_base + (color % gfx->total_colors) * gfx->color_granularity;
474   UINT32 mask = 0;
475   UINT32 count, bit;
476
477   /* make sure we are in range */
478   assert(entry < ctable->entries);
479   assert(gfx->color_depth <= 32);
480
481   /* either gfx->color_depth entries or as many as we can get up until the end */
482   count = MIN(gfx->color_depth, ctable->entries - entry);
483
484   /* set a bit anywhere the transcolor matches */
485   for (bit = 0; bit < count; bit++)
486      if (ctable->raw[entry++] == transcolor)
487         mask |= 1 << bit;
488
489   /* return the final mask */
490   return mask;
491}
492
493
494/*-------------------------------------------------
495    colortable_configure_tilemap_groups -
496    configure groups in a tilemap to represent
497    transparency based on colortable entries
498    (each group maps to a gfx color)
499-------------------------------------------------*/
500
501void colortable_configure_tilemap_groups(colortable *ctable, tilemap *tmap, const gfx_element *gfx, int transcolor)
502{
503   int color;
504
505   assert(gfx->total_colors <= TILEMAP_NUM_GROUPS);
506
507   /* iterate over all colors in the tilemap */
508   for (color = 0; color < gfx->total_colors; color++)
509      tilemap_set_transmask(tmap, color, colortable_get_transpen_mask(ctable, gfx, color, transcolor), 0);
510}
511
512
513
514/***************************************************************************
515    UTILITIES
516***************************************************************************/
517
518/*-------------------------------------------------
519    get_black_pen - return the pen for a fixed
520    black color
521-------------------------------------------------*/
522
523pen_t get_black_pen(running_machine *machine)
524{
525   palette_private *palette = machine->palette_data;
526   return palette->black_pen;
527}
528
529
530/*-------------------------------------------------
531    get_white_pen - return the pen for a fixed
532    white color
533-------------------------------------------------*/
534
535pen_t get_white_pen(running_machine *machine)
536{
537   palette_private *palette = machine->palette_data;
538   return palette->white_pen;
539}
540
541
542
543/***************************************************************************
544    INTERNAL FUNCTIONS
545***************************************************************************/
546
547/*-------------------------------------------------
548    palette_presave - prepare the save arrays
549    for saving
550-------------------------------------------------*/
551
552static void palette_presave(void)
553{
554   int numcolors = palette_get_num_colors(Machine->palette);
555   palette_private *palette = Machine->palette_data;
556   int index;
557
558   /* fill the save arrays with updated pen and brightness information */
559   for (index = 0; index < numcolors; index++)
560   {
561      palette->save_pen[index] = palette_entry_get_color(Machine->palette, index);
562      palette->save_bright[index] = palette_entry_get_contrast(Machine->palette, index);
563   }
564}
565
566
567/*-------------------------------------------------
568    palette_postload - called after restore to
569    actually update the palette
570-------------------------------------------------*/
571
572static void palette_postload(void)
573{
574   int numcolors = palette_get_num_colors(Machine->palette);
575   palette_private *palette = Machine->palette_data;
576   int index;
577
578   /* reset the pen and brightness for each entry */
579   for (index = 0; index < numcolors; index++)
580   {
581      palette_entry_set_color(Machine->palette, index, palette->save_pen[index]);
582      palette_entry_set_contrast(Machine->palette, index, palette->save_bright[index]);
583   }
584}
585
586
587/*-------------------------------------------------
588    palette_exit - free any allocated memory
589-------------------------------------------------*/
590
591static void palette_exit(running_machine *machine)
592{
593   /* dereference the palette */
594   if (machine->palette != NULL)
595      palette_deref(machine->palette);
596}
597
598
599/*-------------------------------------------------
600    allocate_palette - allocate and configure the
601    palette object itself
602-------------------------------------------------*/
603
604static void allocate_palette(running_machine *machine, palette_private *palette)
605{
606   int numgroups, index;
607
608   /* determine the number of groups we need */
609   numgroups = 1;
610   if (machine->drv->video_attributes & VIDEO_HAS_SHADOWS)
611      palette->shadow_group = numgroups++;
612   if (machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS)
613      palette->hilight_group = numgroups++;
614   assert_always(machine->drv->total_colors * numgroups <= 65536, "Error: palette has more than 65536 colors.");
615
616   /* allocate a palette object containing all the colors and groups */
617   machine->palette = palette_alloc(machine->drv->total_colors, numgroups);
618   assert_always(machine->palette != NULL, "Failed to allocate system palette");
619
620   /* configure the groups */
621   if (palette->shadow_group != 0)
622      palette_group_set_contrast(machine->palette, palette->shadow_group, PALETTE_DEFAULT_SHADOW_FACTOR);
623   if (palette->hilight_group != 0)
624      palette_group_set_contrast(machine->palette, palette->hilight_group, PALETTE_DEFAULT_HIGHLIGHT_FACTOR);
625
626   /* set the initial colors to a standard rainbow */
627   for (index = 0; index < machine->drv->total_colors; index++)
628      palette_entry_set_color(machine->palette, index, MAKE_RGB(pal1bit(index >> 0), pal1bit(index >> 1), pal1bit(index >> 2)));
629
630   /* switch off the color mode */
631   switch (palette->format)
632   {
633      /* 16-bit paletteized case */
634      case BITMAP_FORMAT_INDEXED16:
635         palette->black_pen = palette_get_black_entry(machine->palette);
636         palette->white_pen = palette_get_white_entry(machine->palette);
637         if (palette->black_pen >= 65536)
638            palette->black_pen = 0;
639         if (palette->white_pen >= 65536)
640            palette->white_pen = 65536;
641         break;
642
643      /* 15-bit direct case */
644      case BITMAP_FORMAT_RGB15:
645         palette->black_pen = rgb_to_rgb15(MAKE_RGB(0x00,0x00,0x00));
646         palette->white_pen = rgb_to_rgb15(MAKE_RGB(0xff,0xff,0xff));
647         break;
648
649      /* 32-bit direct case */
650      case BITMAP_FORMAT_RGB32:
651         palette->black_pen = MAKE_RGB(0x00,0x00,0x00);
652         palette->white_pen = MAKE_RGB(0xff,0xff,0xff);
653         break;
654
655      /* screenless case */
656      case BITMAP_FORMAT_INVALID:
657      default:
658         break;
659   }
660}
661
662
663/*-------------------------------------------------
664    allocate_color_tables - allocate memory for
665    pen and color tables
666-------------------------------------------------*/
667
668static void allocate_color_tables(running_machine *machine, palette_private *palette)
669{
670   int total_colors = palette_get_num_colors(machine->palette) * palette_get_num_groups(machine->palette);
671   pen_t *pentable;
672   int i;
673
674   /* allocate memory for the pen table */
675   switch (palette->format)
676   {
677      case BITMAP_FORMAT_INDEXED16:
678         /* create a dummy 1:1 mapping */
679         machine->pens = pentable = auto_malloc((total_colors + 2) * sizeof(machine->pens[0]));
680         for (i = 0; i < total_colors + 2; i++)
681            pentable[i] = i;
682         break;
683
684      case BITMAP_FORMAT_RGB15:
685         machine->pens = palette_entry_list_adjusted_rgb15(machine->palette);
686         break;
687
688      case BITMAP_FORMAT_RGB32:
689         machine->pens = palette_entry_list_adjusted(machine->palette);
690         break;
691
692      default:
693         machine->pens = NULL;
694         break;
695   }
696}
697
698
699/*-------------------------------------------------
700    allocate_shadow_tables - allocate memory for
701    shadow tables
702-------------------------------------------------*/
703
704static void allocate_shadow_tables(running_machine *machine, palette_private *palette)
705{
706   /* if we have shadows, allocate shadow tables */
707   if (machine->drv->video_attributes & VIDEO_HAS_SHADOWS)
708   {
709      pen_t *table = auto_malloc(65536 * sizeof(*table));
710      int i;
711
712      /* palettized mode gets a single 64k table in slots 0 and 2 */
713      if (palette->format == BITMAP_FORMAT_INDEXED16)
714      {
715         palette->shadow_table[0].base = palette->shadow_table[2].base = table;
716         for (i = 0; i < 65536; i++)
717            table[i] = (i < machine->drv->total_colors) ? (i + machine->drv->total_colors) : i;
718      }
719
720      /* RGB mode gets two 32k tables in slots 0 and 2 */
721      else
722      {
723         palette->shadow_table[0].base = table;
724         palette->shadow_table[2].base = table + 32768;
725         configure_rgb_shadows(machine, 0, PALETTE_DEFAULT_SHADOW_FACTOR);
726      }
727   }
728
729   /* if we have hilights, allocate shadow tables */
730   if (machine->drv->video_attributes & VIDEO_HAS_HIGHLIGHTS)
731   {
732      pen_t *table = auto_malloc(65536 * sizeof(*table));
733      int i;
734
735      /* palettized mode gets a single 64k table in slots 1 and 3 */
736      if (palette->format == BITMAP_FORMAT_INDEXED16)
737      {
738         palette->shadow_table[1].base = palette->shadow_table[3].base = table;
739         for (i = 0; i < 65536; i++)
740            table[i] = (i < machine->drv->total_colors) ? (i + 2 * machine->drv->total_colors) : i;
741      }
742
743      /* RGB mode gets two 32k tables in slots 1 and 3 */
744      else
745      {
746         palette->shadow_table[1].base = table;
747         palette->shadow_table[3].base = table + 32768;
748         configure_rgb_shadows(machine, 1, PALETTE_DEFAULT_HIGHLIGHT_FACTOR);
749      }
750   }
751
752   /* set the default table */
753   machine->shadow_table = palette->shadow_table[0].base;
754}
755
756
757/*-------------------------------------------------
758    configure_rgb_shadows - configure shadows
759    for the RGB tables
760-------------------------------------------------*/
761
762static void configure_rgb_shadows(running_machine *machine, int mode, float factor)
763{
764   palette_private *palette = machine->palette_data;
765   shadow_table_data *stable = &palette->shadow_table[mode];
766   int ifactor = (int)(factor * 256.0f);
767   int i;
768
769   /* only applies to RGB direct modes */
770   assert(palette->format != BITMAP_FORMAT_INDEXED16);
771   assert(stable->base != NULL);
772
773   #if VERBOSE
774      popmessage("shadow %d recalc %d %d %d %02x", mode, dr, dg, db, noclip);
775   #endif
776
777   /* regenerate the table */
778   for (i = 0; i < 32768; i++)
779   {
780      UINT8 r = rgb_clamp((pal5bit(i >> 10) * ifactor) >> 8);
781      UINT8 g = rgb_clamp((pal5bit(i >> 5) * ifactor) >> 8);
782      UINT8 b = rgb_clamp((pal5bit(i >> 0) * ifactor) >> 8);
783      pen_t final = MAKE_RGB(r, g, b);
784
785      /* store either 16 or 32 bit */
786      if (palette->format == BITMAP_FORMAT_RGB32)
787         stable->base[i] = final;
788      else
789         stable->base[i] = rgb_to_rgb15(final);
790   }
791}
src/emu/render.h
r936r937
293293    FUNCTION PROTOTYPES
294294***************************************************************************/
295295
296
297/* ----- core implementation ----- */
298
299/* allocate base structures for the rendering system */
296300void render_init(running_machine *machine);
301
302/* set a notifier that we call before doing long scaling operations */
297303void render_set_rescale_notify(running_machine *machine, int (*notifier)(running_machine *, int, int));
304
305/* return a bitmask indicating the live screens */
298306UINT32 render_get_live_screens_mask(void);
299float render_get_ui_aspect(void);
307
308/* return the smallest maximum update rate across all targets */
309float render_get_max_update_rate(void);
310
311/* select the UI target */
300312void render_set_ui_target(render_target *target);
313
314/* return the UI target */
301315render_target *render_get_ui_target(void);
302316
317/* return the aspect ratio for UI fonts */
318float render_get_ui_aspect(void);
303319
320
321
304322/* ----- render target management ----- */
305323
324/* allocate a new render target */
306325render_target *render_target_alloc(const char *layout, UINT32 flags);
326
327/* free memory for a render target */
307328void render_target_free(render_target *target);
329
330/* get a render_target by index */
308331render_target *render_target_get_indexed(int index);
332
333/* return the name of the indexed view, or NULL if it doesn't exist */
309334const char *render_target_get_view_name(render_target *target, int viewindex);
335
336/* return a bitmask of which screens are visible on a given view */
310337UINT32 render_target_get_view_screens(render_target *target, int viewindex);
338
339/* get the bounds and pixel aspect of a target */
311340void render_target_get_bounds(render_target *target, INT32 *width, INT32 *height, float *pixel_aspect);
341
342/* set the bounds and pixel aspect of a target */
312343void render_target_set_bounds(render_target *target, INT32 width, INT32 height, float pixel_aspect);
344
345/* get the maximum update rate (refresh rate) of a target, or 0 if no maximum */
346float render_target_get_max_update_rate(render_target *target);
347
348/* set the maximum update rate (refresh rate) of a target, or 0 if no maximum */
349void render_target_set_max_update_rate(render_target *target, float updates_per_second);
350
351/* get the orientation of a target */
313352int render_target_get_orientation(render_target *target);
353
354/* set the orientation of a target */
314355void render_target_set_orientation(render_target *target, int orientation);
356
357/* get the layer config of a target */
315358int render_target_get_layer_config(render_target *target);
359
360/* set the layer config of a target */
316361void render_target_set_layer_config(render_target *target, int layerconfig);
362
363/* return the currently selected view index */
317364int render_target_get_view(render_target *target);
365
366/* dynamically change the view for a target */
318367void render_target_set_view(render_target *target, int viewindex);
368
369/* set the upper bound on the texture size */
319370void render_target_set_max_texture_size(render_target *target, int maxwidth, int maxheight);
371
372/* compute the visible area for the given target with the current layout and proposed new parameters */
320373void render_target_compute_visible_area(render_target *target, INT32 target_width, INT32 target_height, float target_pixel_aspect, UINT8 target_orientation, INT32 *visible_width, INT32 *visible_height);
374
375/* get the "minimum" size of a target, which is the smallest bounds that will ensure at least
376   1 target pixel per source pixel for all included screens */
321377void render_target_get_minimum_size(render_target *target, INT32 *minwidth, INT32 *minheight);
378
379/* return a list of primitives for a given render target */
322380const render_primitive_list *render_target_get_primitives(render_target *target);
323381
324382
383
325384/* ----- render texture management ----- */
326385
386/* allocate a new texture */
327387render_texture *render_texture_alloc(texture_scaler scaler, void *param);
388
389/* free an allocated texture */
328390void render_texture_free(render_texture *texture);
391
392/* set a new source bitmap */
329393void render_texture_set_bitmap(render_texture *texture, mame_bitmap *bitmap, const rectangle *sbounds, UINT32 palettebase, int format);
394
395/* generic high quality resampling scaler */
330396void render_texture_hq_scale(mame_bitmap *dest, const mame_bitmap *source, const rectangle *sbounds, void *param);
331397
332398
399
333400/* ----- render containers ----- */
334401
402/* empty a container in preparation for new stuff */
335403void render_container_empty(render_container *container);
404
405/* return true if a container has nothing in it */
336406int render_container_is_empty(render_container *container);
407
408/* return the orientation of a container */
337409int render_container_get_orientation(render_container *container);
410
411/* set the orientation of a container */
338412void render_container_set_orientation(render_container *container, int orientation);
413
414/* return the brightness of a container */
339415float render_container_get_brightness(render_container *container);
416
417/* set the brightness of a container */
340418void render_container_set_brightness(render_container *container, float brightness);
419
420/* return the contrast of a container */
341421float render_container_get_contrast(render_container *container);
422
423/* set the contrast of a container */
342424void render_container_set_contrast(render_container *container, float contrast);
425
426/* return the gamma of a container */
343427float render_container_get_gamma(render_container *container);
428
429/* set the gamma of a container */
344430void render_container_set_gamma(render_container *container, float gamma);
431
432/* return the X scale of a container */
345433float render_container_get_xscale(render_container *container);
434
435/* set the X scale of a container */
346436void render_container_set_xscale(render_container *container, float xscale);
437
438/* return the Y scale of a container */
347439float render_container_get_yscale(render_container *container);
440
441/* set the Y scale of a container */
348442void render_container_set_yscale(render_container *container, float yscale);
443
444/* return the X offset of a container */
349445float render_container_get_xoffset(render_container *container);
446
447/* set the X offset of a container */
350448void render_container_set_xoffset(render_container *container, float xoffset);
449
450/* return the Y offset of a container */
351451float render_container_get_yoffset(render_container *container);
452
453/* set the Y offset of a container */
352454void render_container_set_yoffset(render_container *container, float yoffset);
455
456/* set the overlay bitmap for the container */
353457void render_container_set_overlay(render_container *container, mame_bitmap *bitmap);
458
459/* return a pointer to the UI container */
354460render_container *render_container_get_ui(void);
461
462/* return a pointer to the indexed screen container */
355463render_container *render_container_get_screen(int screen);
464
465/* set the opacity of a given palette entry */
356466void render_container_set_palette_alpha(render_container *container, UINT32 entry, UINT8 alpha);
467
468/* add a line item to the specified container */
357469void render_container_add_line(render_container *container, float x0, float y0, float x1, float y1, float width, rgb_t argb, UINT32 flags);
470
471/* add a quad item to the specified container */
358472void render_container_add_quad(render_container *container, float x0, float y0, float x1, float y1, rgb_t argb, render_texture *texture, UINT32 flags);
473
474/* add a char item to the specified container */
359475void render_container_add_char(render_container *container, float x0, float y0, float height, float aspect, rgb_t argb, render_font *font, UINT16 ch);
360476
361477
src/emu/validity.c
r936r937
264264
265265#ifndef MESS
266266   /* make sure sound-less drivers are flagged */
267   if ((driver->flags & GAME_IS_BIOS_ROOT) == 0 && drv->sound[0].sound_type == 0 && (driver->flags & GAME_NO_SOUND) == 0 && strcmp(driver->name, "minivadr"))
267   if ((driver->flags & GAME_IS_BIOS_ROOT) == 0 && drv->sound[0].sound_type == SOUND_DUMMY && (driver->flags & GAME_NO_SOUND) == 0 && strcmp(driver->name, "minivadr"))
268268   {
269269      mame_printf_error("%s: %s missing GAME_NO_SOUND flag\n", driver->source_file, driver->name);
270270      error = TRUE;
r936r937
471471      int spacenum;
472472
473473      /* skip empty entries */
474      if (cpu->cpu_type == 0)
474      if (cpu->cpu_type == CPU_DUMMY)
475475         continue;
476476
477477      /* checks to see if this driver is using a dummy CPU */
src/emu/emupal.h
r0r937
1/******************************************************************************
2
3    emupal.h
4
5    Emulator palette handling functions.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10    There are several levels of abstraction in the way MAME handles the palette,
11    and several display modes which can be used by the drivers.
12
13    Palette
14    -------
15    Note: in the following text, "color" refers to a color in the emulated
16    game's virtual palette. For example, a game might be able to display 1024
17    colors at the same time. If the game uses RAM to change the available
18    colors, the term "palette" refers to the colors available at any given time,
19    not to the whole range of colors which can be produced by the hardware. The
20    latter is referred to as "color space".
21    The term "pen" refers to one of the maximum MAX_PENS colors that can be
22    used to generate the display.
23
24    So, to summarize, the three layers of palette abstraction are:
25
26    P1) The game virtual palette (the "colors")
27    P2) MAME's MAX_PENS colors palette (the "pens")
28    P3) The OS specific hardware color registers (the "OS specific pens")
29
30    The array Machine->pens[] is a lookup table which maps game colors to OS
31    specific pens (P1 to P3). When you are working on bitmaps at the pixel level,
32    *always* use Machine->pens to map the color numbers. *Never* use constants.
33    For example if you want to make pixel (x,y) of color 3, do:
34    *BITMAP_ADDR(bitmap, <type>, y, x) = Machine->pens[3];
35
36
37    Lookup table
38    ------------
39    Palettes are only half of the story. To map the gfx data to colors, the
40    graphics routines use a lookup table. For example if we have 4bpp tiles,
41    which can have 256 different color codes, the lookup table for them will have
42    256 * 2^4 = 4096 elements. For games using a palette RAM, the lookup table is
43    usually a 1:1 map. For games using PROMs, the lookup table is often larger
44    than the palette itself so for example the game can display 256 colors out
45    of a palette of 16.
46
47    The palette and the lookup table are initialized to default values by the
48    main core, but can be initialized by the driver using the function
49    MachineDriver->vh_init_palette(). For games using palette RAM, that
50    function is usually not needed, and the lookup table can be set up by
51    properly initializing the color_codes_start and total_color_codes fields in
52    the GfxDecodeInfo array.
53    When vh_init_palette() initializes the lookup table, it maps gfx codes
54    to game colors (P1 above). The lookup table will be converted by the core to
55    map to OS specific pens (P3 above), and stored in Machine->remapped_colortable.
56
57
58    Display modes
59    -------------
60    The available display modes can be summarized in three categories:
61    1) Static palette. Use this for games which use PROMs for color generation.
62        The palette is initialized by palette_init(), and never changed
63        again.
64    2) Dynamic palette. Use this for games which use RAM for color generation.
65        The palette can be dynamically modified by the driver using the function
66        palette_set_color().
67    3) Direct mapped 16-bit or 32-bit color. This should only be used in special
68        cases, e.g. to support alpha blending.
69        MachineDriver->video_attributes must contain VIDEO_RGB_DIRECT.
70
71
72    Shadows(Highlights) Quick Reference
73    -----------------------------------
74
75    1) declare MDRV_VIDEO_ATTRIBUTES( ... VIDEO_HAS_SHADOWS | VIDEO_HAS_HIGHLIGHTS ... )
76
77    2) set gfx_drawmode_table[0-n] to DRAWMODE_NONE, DRAWMODE_SOURCE or DRAWMODE_SHADOW
78
79    3) (optional) set shadow darkness or highlight brightness by
80        palette_set_shadow_factor(0.0-1.0) or
81        palette_set_highlight_factor(1.0-n.n)
82
83    4) before calling drawgfx use
84        palette_set_shadow_mode(0) to arm shadows or
85        palette_set_shadow_mode(1) to arm highlights
86
87    5) call drawgfx with the TRANSPARENCY_PEN_TABLE flag
88        drawgfx( ..., cliprect, TRANSPARENCY_PEN_TABLE, transparent_color )
89
90******************************************************************************/
91
92#pragma once
93
94#ifndef __EMUPAL_H__
95#define __EMUPAL_H__
96
97#include "palette.h"
98#include "memory.h"
99#include "tilemap.h"
100
101
102/***************************************************************************
103    CONSTANTS
104***************************************************************************/
105
106#define PALETTE_DEFAULT_SHADOW_FACTOR (0.6)
107#define PALETTE_DEFAULT_HIGHLIGHT_FACTOR (1/PALETTE_DEFAULT_SHADOW_FACTOR)
108
109
110
111/***************************************************************************
112    TYPE DEFINITIONS
113***************************************************************************/
114
115typedef struct _colortable colortable;
116
117
118
119/***************************************************************************
120    FUNCTION PROTOTYPES
121***************************************************************************/
122
123
124/* ----- initialization and configuration ----- */
125
126/* palette initialization that takes place before the display is created */
127void palette_init(running_machine *machine);
128
129/* palette initialization that takes place after the display is created */
130void palette_config(running_machine *machine);
131
132
133
134/* ----- shadow/hilight configuration ----- */
135
136/* set the global shadow brightness factor */
137void palette_set_shadow_factor(running_machine *machine, double factor);
138
139/* set the global highlight brightness factor */
140void palette_set_highlight_factor(running_machine *machine, double factor);
141
142
143
144/* ----- shadow table configuration ----- */
145
146/* select 1 of 4 different live shadow tables */
147void palette_set_shadow_mode(running_machine *machine, int mode);
148
149/* configure delta RGB values for 1 of 4 shadow tables */
150void palette_set_shadow_dRGB32(running_machine *machine, int mode, int dr, int dg, int db, int noclip);
151
152
153
154/* ----- colortable management ----- */
155
156/* allocate a new colortable with the given number of entries */
157colortable *colortable_alloc(running_machine *machine, UINT32 palettesize);
158
159/* set the value of a colortable entry */
160void colortable_entry_set_value(colortable *ctable, UINT32 entry, UINT16 value);
161
162/* return the value of a colortable entry */
163UINT16 colortable_entry_get_value(colortable *ctable, UINT32 entry);
164
165/* change the color of a colortable palette entry */
166void colortable_palette_set_color(colortable *ctable, UINT32 entry, rgb_t color);
167
168/* return the color of a colortable palette entry */
169rgb_t colortable_palette_get_color(colortable *ctable, UINT32 entry);
170
171/* return a 32-bit transparency mask for a given gfx element and color */
172UINT32 colortable_get_transpen_mask(colortable *ctable, const gfx_element *gfx, int color, int transcolor);
173
174/* configure groups in a tilemap to represent transparency based on colortable entries (each group maps to a gfx color) */
175void colortable_configure_tilemap_groups(colortable *ctable, tilemap *tmap, const gfx_element *gfx, int transcolor);
176
177
178
179/* ----- utilities ----- */
180
181/* return the pen for a fixed black color */
182pen_t get_black_pen(running_machine *machine);
183
184/* return the pen for a fixed white color */
185pen_t get_white_pen(running_machine *machine);
186
187
188
189
190/***************************************************************************
191    INLINE FUNCTIONS
192***************************************************************************/
193
194/*-------------------------------------------------
195    palette_set_color - set a single palette
196    entry
197-------------------------------------------------*/
198
199INLINE void palette_set_color(running_machine *machine, pen_t pen, rgb_t rgb)
200{
201   palette_entry_set_color(machine->palette, pen, rgb);
202}
203
204
205/*-------------------------------------------------
206    palette_set_color_rgb - set a single palette
207    entry with individual R,G,B components
208-------------------------------------------------*/
209
210INLINE void palette_set_color_rgb(running_machine *machine, pen_t pen, UINT8 r, UINT8 g, UINT8 b)
211{
212   palette_entry_set_color(machine->palette, pen, MAKE_RGB(r, g, b));
213}
214
215
216/*-------------------------------------------------
217    palette_get_color - return a single palette
218    entry
219-------------------------------------------------*/
220
221INLINE rgb_t palette_get_color(running_machine *machine, pen_t pen)
222{
223   return palette_entry_get_color(machine->palette, pen);
224}
225
226
227/*-------------------------------------------------
228    palette_set_brightness - set the per-pen
229    brightness factor
230-------------------------------------------------*/
231
232INLINE void palette_set_brightness(running_machine *machine, pen_t pen, double bright)
233{
234   palette_entry_set_contrast(machine->palette, pen, bright);
235}
236
237
238/*-------------------------------------------------
239    palette_set_colors - set multiple palette
240    entries from an array of rgb_t values
241-------------------------------------------------*/
242
243INLINE void palette_set_colors(running_machine *machine, pen_t color_base, const rgb_t *colors, int color_count)
244{
245   while (color_count--)
246      palette_entry_set_color(machine->palette, color_base++, *colors++);
247}
248
249
250#endif   /* __PALETTE_H__ */
src/emu/drivers/empty.c
r936r937
4141   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
4242
4343   MDRV_SCREEN_ADD("main", 0)
44   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
44   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
4545   MDRV_SCREEN_SIZE(640,480)
4646   MDRV_SCREEN_VISIBLE_AREA(0,639, 0,479)
4747   MDRV_SCREEN_REFRESH_RATE(30)
src/emu/romload.c
r936r937
2525
2626
2727/***************************************************************************
28    TYPE DEFINITIONS
29***************************************************************************/
30
31typedef struct _open_chd open_chd;
32struct _open_chd
33{
34   open_chd *         next;               /* pointer to next in the list */
35   chd_file *         origchd;            /* handle to the original CHD */
36   mame_file *         origfile;            /* file handle to the original CHD file */
37   chd_file *         diffchd;            /* handle to the diff CHD */
38   mame_file *         difffile;            /* file handle to the diff CHD file */
39};
40
41
42
43/***************************************************************************
2844    GLOBAL VARIABLES
2945***************************************************************************/
3046
3147/* disks */
32static chd_file *disk_handle[4];
48static open_chd *chd_list;
49static open_chd **chd_list_tailptr;
3350
3451/* system BIOS */
3552int system_bios;
r936r937
4461
4562chd_file *get_disk_handle(int diskindex)
4663{
47   return disk_handle[diskindex];
64   open_chd *curdisk;
65   for (curdisk = chd_list; curdisk != NULL && diskindex-- != 0; curdisk = curdisk->next) ;
66   return (curdisk->diffchd != NULL) ? curdisk->diffchd : curdisk->origchd;
4867}
4968
5069
r936r937
424443   if (type >= REGION_CPU1 && type < REGION_CPU1 + MAX_CPU)
425444   {
426445      int cputype = Machine->drv->cpu[type - REGION_CPU1].cpu_type;
427      if (cputype != 0)
446      if (cputype != CPU_DUMMY)
428447      {
429448         datawidth = cputype_databus_width(cputype, ADDRESS_SPACE_PROGRAM) / 8;
430449         littleendian = (cputype_endianness(cputype) == CPU_IS_LE);
r936r937
795814    up the parent and loading by checksum
796815-------------------------------------------------*/
797816
798chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, chd_file **image)
817chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd)
799818{
800819   const game_driver *drv;
801820   const rom_entry *region, *rom;
802821   astring *fname;
822   file_error filerr;
803823   chd_error err;
804824
825   *image_file = NULL;
826   *image_chd = NULL;
827
805828   /* attempt to open the properly named file */
806   fname = astring_assemble_2(astring_alloc(), ROM_GETNAME(romp), ".chd");
807   err = chd_open(astring_c(fname), CHD_OPEN_READ, NULL, image);
829   fname = astring_assemble_4(astring_alloc(), gamedrv->name, PATH_SEPARATOR, ROM_GETNAME(romp), ".chd");
830   filerr = mame_fopen(SEARCHPATH_IMAGE, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_WRITE, image_file);
808831   astring_free(fname);
809832
810   /* if that worked, we're done */
811   if (err == CHDERR_NONE)
812      return err;
833   /* did the file open succeed? */
834   if (filerr == FILERR_NONE)
835   {
836      /* try to open the CHD */
837      err = chd_open_file(mame_core_file(*image_file), CHD_OPEN_READ, NULL, image_chd);
838      if (err == CHDERR_NONE)
839         return err;
813840
841      /* close the file on failure */
842      mame_fclose(*image_file);
843      *image_file = NULL;
844   }
845   else
846      err = CHDERR_FILE_NOT_FOUND;
847
814848   /* otherwise, look at our parents for a CHD with an identical checksum */
815849   /* and try to open that */
816850   for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv))
r936r937
822856               if (strcmp(ROM_GETNAME(romp), ROM_GETNAME(rom)) != 0 &&
823857                  hash_data_is_equal(ROM_GETHASHDATA(romp), ROM_GETHASHDATA(rom), 0))
824858               {
825                  fname = astring_assemble_2(astring_alloc(), ROM_GETNAME(rom), ".chd");
826                  err = chd_open(astring_c(fname), CHD_OPEN_READ, NULL, image);
859                  fname = astring_assemble_4(astring_alloc(), drv->name, PATH_SEPARATOR, ROM_GETNAME(rom), ".chd");
860                  filerr = mame_fopen(SEARCHPATH_IMAGE, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_WRITE, image_file);
827861                  astring_free(fname);
828862
829                  /* if that worked, we're done */
830                  if (err == CHDERR_NONE)
831                     return err;
863                  /* did the file open succeed? */
864                  if (filerr == FILERR_NONE)
865                  {
866                     /* try to open the CHD */
867                     err = chd_open_file(mame_core_file(*image_file), CHD_OPEN_READ, NULL, image_chd);
868                     if (err == CHDERR_NONE)
869                        return err;
870
871                     /* close the file on failure */
872                     mame_fclose(*image_file);
873                     *image_file = NULL;
874                  }
832875               }
833876
834877   return err;
r936r937
836879
837880
838881/*-------------------------------------------------
882    open_disk_diff - open a DISK diff file
883-------------------------------------------------*/
884
885static chd_error open_disk_diff(const game_driver *drv, const rom_entry *romp, chd_file *source, mame_file **diff_file, chd_file **diff_chd)
886{
887   astring *fname = astring_assemble_2(astring_alloc(), ROM_GETNAME(romp), ".dif");
888   file_error filerr;
889   chd_error err;
890
891   *diff_file = NULL;
892   *diff_chd = NULL;
893
894   /* try to open the diff */
895   debugload("Opening differencing image file: %s\n", astring_c(fname));
896   filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_WRITE, diff_file);
897   if (filerr != FILERR_NONE)
898   {
899      /* didn't work; try creating it instead */
900      debugload("Creating differencing image: %s\n", astring_c(fname));
901      filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, diff_file);
902      if (filerr != FILERR_NONE)
903      {
904         err = CHDERR_FILE_NOT_FOUND;
905         goto done;
906      }
907
908      /* create the CHD */
909      err = chd_create_file(mame_core_file(*diff_file), 0, 0, CHDCOMPRESSION_NONE, source);
910      if (err != CHDERR_NONE)
911         goto done;
912   }
913
914   debugload("Opening differencing image file: %s\n", astring_c(fname));
915   err = chd_open_file(mame_core_file(*diff_file), CHD_OPEN_READWRITE, source, diff_chd);
916   if (err != CHDERR_NONE)
917      goto done;
918
919done:
920   astring_free(fname);
921   if ((err != CHDERR_NONE) && (*diff_file != NULL))
922   {
923      mame_fclose(*diff_file);
924      *diff_file = NULL;
925   }
926   return err;
927}
928
929
930/*-------------------------------------------------
839931    process_disk_entries - process all disk entries
840932    for a region
841933-------------------------------------------------*/
r936r937
848940      /* handle files */
849941      if (ROMENTRY_ISFILE(romp))
850942      {
851         chd_file *source, *diff = NULL;
943         char acthash[HASH_BUF_SIZE];
944         open_chd chd = { 0 };
852945         chd_header header;
853         char filename[1024];
854         char acthash[HASH_BUF_SIZE];
946         astring *filename;
855947         chd_error err;
856948
857949         /* make the filename of the source */
858         sprintf(filename, "%s.chd", ROM_GETNAME(romp));
950         filename = astring_assemble_2(astring_alloc(), ROM_GETNAME(romp), ".chd");
859951
860952         /* first open the source drive */
861         debugload("Opening disk image: %s\n", filename);
862         err = open_disk_image(Machine->gamedrv, romp, &source);
953         debugload("Opening disk image: %s\n", astring_c(filename));
954         err = open_disk_image(Machine->gamedrv, romp, &chd.origfile, &chd.origchd);
863955         if (err != CHDERR_NONE)
864956         {
865957            if (err == CHDERR_UNSUPPORTED_VERSION)
866               sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename);
958               sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", astring_c(filename));
867959            else
868               sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND\n", filename);
960               sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND\n", astring_c(filename));
869961
870962            /* if this is NO_DUMP, keep going, though the system may not be able to handle it */
871963            if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_NO_DUMP))
872964               romdata->warnings++;
873965            else
874966               romdata->errors++;
875            romp++;
876            continue;
967            goto next;
877968         }
878969
879970         /* get the header and extract the MD5/SHA1 */
880         header = *chd_get_header(source);
971         header = *chd_get_header(chd.origchd);
881972         hash_data_clear(acthash);
882973         hash_data_insert_binary_checksum(acthash, HASH_MD5, header.md5);
883974         hash_data_insert_binary_checksum(acthash, HASH_SHA1, header.sha1);
r936r937
885976         /* verify the MD5 */
886977         if (!hash_data_is_equal(ROM_GETHASHDATA(romp), acthash, 0))
887978         {
888            sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG CHECKSUMS:\n", filename);
979            sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG CHECKSUMS:\n", astring_c(filename));
889980            dump_wrong_and_correct_checksums(romdata, ROM_GETHASHDATA(romp), acthash);
890981            romdata->warnings++;
891982         }
892983         else if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_BAD_DUMP))
893984         {
894            sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s CHD NEEDS REDUMP\n", filename);
985            sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s CHD NEEDS REDUMP\n", astring_c(filename));
895986            romdata->warnings++;
896987         }
897988
898989         /* if not read-only, make the diff file */
899990         if (!DISK_ISREADONLY(romp))
900991         {
901            /* make the filename of the diff */
902            sprintf(filename, "%s.dif", ROM_GETNAME(romp));
903
904            /* try to open the diff */
905            debugload("Opening differencing image: %s\n", filename);
906            err = chd_open(filename, CHD_OPEN_READWRITE, source, &diff);
992            /* try to open or create the diff */
993            err = open_disk_diff(Machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd);
907994            if (err != CHDERR_NONE)
908995            {
909               /* didn't work; try creating it instead */
910               debugload("Creating differencing image: %s\n", filename);
911               err = chd_create(filename, 0, 0, CHDCOMPRESSION_NONE, source);
912               if (err != CHDERR_NONE)
913               {
914                  if (err == CHDERR_UNSUPPORTED_VERSION)
915                     sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename);
916                  else
917                     sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: CAN'T CREATE DIFF FILE\n", filename);
918                  romdata->errors++;
919                  romp++;
920                  continue;
921               }
922
923               /* open the newly-created diff file */
924               debugload("Opening differencing image: %s\n", filename);
925               err = chd_open(filename, CHD_OPEN_READWRITE, source, &diff);
926               if (err != CHDERR_NONE)
927               {
928                  if (err == CHDERR_UNSUPPORTED_VERSION)
929                     sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename);
930                  else
931                     sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: CAN'T OPEN DIFF FILE\n", filename);
932                  romdata->errors++;
933                  romp++;
934                  continue;
935               }
996               if (err == CHDERR_UNSUPPORTED_VERSION)
997                  sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", astring_c(filename));
998               else
999                  sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: CAN'T OPEN DIFF FILE\n", astring_c(filename));
1000               romdata->errors++;
1001               goto next;
9361002            }
9371003         }
9381004
939         /* we're okay, set the handle */
1005         /* we're okay, add to the list of disks */
9401006         debugload("Assigning to handle %d\n", DISK_GETINDEX(romp));
941         disk_handle[DISK_GETINDEX(romp)] = DISK_ISREADONLY(romp) ? source : diff;
1007         *chd_list_tailptr = auto_malloc(sizeof(**chd_list_tailptr));
1008         **chd_list_tailptr = chd;
1009         chd_list_tailptr = &(*chd_list_tailptr)->next;
1010next:
9421011         romp++;
1012         astring_free(filename);
9431013      }
9441014   }
9451015}
r936r937
9761046   romdata.romstotal = count_roms(romp);
9771047
9781048   /* reset the disk list */
979   memset(disk_handle, 0, sizeof(disk_handle));
1049   chd_list = NULL;
1050   chd_list_tailptr = &chd_list;
9801051
9811052   /* loop until we hit the end */
9821053   for (region = romp, regnum = 0; region; region = rom_next_region(region), regnum++)
r936r937
10411112
10421113void rom_exit(running_machine *machine)
10431114{
1115   open_chd *curchd;
10441116   int i;
10451117
10461118   /* free the memory allocated for various regions */
r936r937
10481120      free_memory_region(machine, i);
10491121
10501122   /* close all hard drives */
1051   chd_close_all();
1123   for (curchd = chd_list; curchd != NULL; curchd = curchd->next)
1124   {
1125      if (curchd->diffchd != NULL)
1126         chd_close(curchd->diffchd);
1127      if (curchd->difffile != NULL)
1128         mame_fclose(curchd->difffile);
1129      if (curchd->origchd != NULL)
1130         chd_close(curchd->origchd);
1131      if (curchd->origfile != NULL)
1132         mame_fclose(curchd->origfile);
1133   }
10521134}
10531135
10541136
src/lib/expat/xmlparse.c
r936r937
37513751#endif /* XML_DTD */
37523752      dtd->hasParamEntityRefs = XML_TRUE;
37533753      if (startDoctypeDeclHandler) {
3754         XML_Char *tem;
37543755        if (!XmlIsPublicId(enc, s, next, eventPP))
37553756          return XML_ERROR_PUBLICID;
3756        doctypePubid = poolStoreString(&tempPool, enc,
3757        tem = poolStoreString(&tempPool, enc,
37573758                                       s + enc->minBytesPerChar,
37583759                                       next - enc->minBytesPerChar);
3759        if (!doctypePubid)
3760        if (!tem)
37603761          return XML_ERROR_NO_MEMORY;
3761        normalizePublicId((XML_Char *)doctypePubid);
3762        normalizePublicId(tem);
3763        doctypePubid = tem;
37623764        poolFinish(&tempPool);
37633765        handleDefault = XML_FALSE;
37643766        goto alreadyChecked;
src/lib/lib.mak
r936r937
3838   $(LIBOBJ)/util/jedparse.o \
3939   $(LIBOBJ)/util/md5.o \
4040   $(LIBOBJ)/util/options.o \
41   $(LIBOBJ)/util/palette.o \
4142   $(LIBOBJ)/util/png.o \
4243   $(LIBOBJ)/util/pool.o \
4344   $(LIBOBJ)/util/sha1.o \
src/lib/util/palette.c
r0r937
1/******************************************************************************
2
3    palette.c
4
5    Palette handling functions.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10******************************************************************************/
11
12#include "palette.h"
13
14
15
16/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
19
20/* object to track dirty states */
21typedef struct _dirty_state dirty_state;
22struct _dirty_state
23{
24   UINT32 *      dirty;                  /* bitmap of dirty entries */
25   UINT32         mindirty;               /* minimum dirty entry */
26   UINT32         maxdirty;               /* minimum dirty entry */
27};
28
29
30/* a single palette client */
31struct _palette_client
32{
33   palette_client *next;                  /* pointer to next client */
34   palette_t *      palette;               /* reference to the palette */
35   dirty_state      live;                  /* live dirty state */
36   dirty_state      previous;               /* previous dirty state */
37};
38
39
40/* a palette object */
41struct _palette_t
42{
43   UINT32         refcount;               /* reference count on the palette */
44   UINT32         numcolors;               /* number of colors in the palette */
45   UINT32         numgroups;               /* number of groups in the palette */
46
47   rgb_t *         entry_color;            /* array of raw colors */
48   float *         entry_contrast;            /* contrast value for each entry */
49   rgb_t *         adjusted_color;            /* array of adjusted colors */
50   rgb_t *         adjusted_rgb15;            /* array of adjusted colors as RGB15 */
51
52   float *         group_bright;            /* brightness value for each group */
53   float *         group_contrast;            /* contrast value for each group */
54
55   palette_client *client_list;            /* list of clients for this palette */
56};
57
58
59
60/***************************************************************************
61    FUNCTION PROTOTYPES
62***************************************************************************/
63
64static void internal_palette_free(palette_t *palette);
65static void update_adjusted_color(palette_t *palette, UINT32 group, UINT32 index);
66
67
68
69/***************************************************************************
70    INLINE FUNCTIONS
71***************************************************************************/
72
73/*-------------------------------------------------
74    adjust_palette_entry - adjust a palette
75    entry for brightness
76-------------------------------------------------*/
77
78INLINE rgb_t adjust_palette_entry(rgb_t entry, float brightness, float contrast)
79{
80   int r = rgb_clamp((float)RGB_RED(entry) * contrast + brightness);
81   int g = rgb_clamp((float)RGB_GREEN(entry) * contrast + brightness);
82   int b = rgb_clamp((float)RGB_BLUE(entry) * contrast + brightness);
83   return MAKE_RGB(r,g,b);
84}
85
86
87
88/***************************************************************************
89    PALETTE ALLOCATION
90***************************************************************************/
91
92/*-------------------------------------------------
93    palette_alloc - allocate a new palette object
94    and take a single reference on it
95-------------------------------------------------*/
96
97palette_t *palette_alloc(UINT32 numcolors, UINT32 numgroups)
98{
99   palette_t *palette;
100   UINT32 index;
101
102   /* allocate memory */
103   palette = malloc(sizeof(*palette));
104   if (palette == NULL)
105      goto error;
106   memset(palette, 0, sizeof(*palette));
107
108   /* allocate an array of palette entries and individual contrasts for each */
109   palette->entry_color = malloc(sizeof(*palette->entry_color) * numcolors);
110   palette->entry_contrast = malloc(sizeof(*palette->entry_contrast) * numcolors);
111   if (palette->entry_color == NULL || palette->entry_contrast == NULL)
112      goto error;
113
114   /* initialize the entries */
115   for (index = 0; index < numcolors; index++)
116   {
117      palette->entry_color[index] = RGB_BLACK;
118      palette->entry_contrast[index] = 1.0f;
119   }
120
121   /* allocate an array of brightness and contrast for each group */
122   palette->group_bright = malloc(sizeof(*palette->group_bright) * numgroups);
123   palette->group_contrast = malloc(sizeof(*palette->group_contrast) * numgroups);
124   if (palette->group_bright == NULL || palette->group_contrast == NULL)
125      goto error;
126
127   /* initialize the entries */
128   for (index = 0; index < numgroups; index++)
129   {
130      palette->group_bright[index] = 0.0f;
131      palette->group_contrast[index] = 1.0f;
132   }
133
134   /* allocate arrays for the adjusted colors */
135   palette->adjusted_color = malloc(sizeof(*palette->adjusted_color) * (numcolors * numgroups + 2));
136   palette->adjusted_rgb15 = malloc(sizeof(*palette->adjusted_rgb15) * (numcolors * numgroups + 2));
137   if (palette->adjusted_color == NULL || palette->adjusted_rgb15 == NULL)
138      goto error;
139
140   /* initialize the arrays */
141   for (index = 0; index < numcolors * numgroups; index++)
142   {
143      palette->adjusted_color[index] = RGB_BLACK;
144      palette->adjusted_rgb15[index] = rgb_to_rgb15(RGB_BLACK);
145   }
146
147   /* add black and white as the last two colors */
148   palette->adjusted_color[index] = RGB_BLACK;
149   palette->adjusted_rgb15[index++] = rgb_to_rgb15(RGB_BLACK);
150   palette->adjusted_color[index] = RGB_WHITE;
151   palette->adjusted_rgb15[index++] = rgb_to_rgb15(RGB_WHITE);
152
153   /* initialize the remainder of the structure */
154   palette->refcount = 1;
155   palette->numcolors = numcolors;
156   palette->numgroups = numgroups;
157   return palette;
158
159error:
160   if (palette != NULL)
161      internal_palette_free(palette);
162
163   return NULL;
164}
165
166
167/*-------------------------------------------------
168    palette_ref - reference a palette object,
169    incrementing its reference count
170-------------------------------------------------*/
171
172void palette_ref(palette_t *palette)
173{
174   palette->refcount++;
175}
176
177
178/*-------------------------------------------------
179    palette_deref - dereference a palette object;
180    if the reference count goes to 0, it is freed
181-------------------------------------------------*/
182
183void palette_deref(palette_t *palette)
184{
185   /* if the reference count goes to 0, free */
186   if (--palette->refcount == 0)
187      internal_palette_free(palette);
188}
189
190
191
192/***************************************************************************
193    PALETTE INFORMATION
194***************************************************************************/
195
196/*-------------------------------------------------
197    palette_get_num_colors - return the number of
198    colors allocated in the palette
199-------------------------------------------------*/
200
201int palette_get_num_colors(palette_t *palette)
202{
203   return palette->numcolors;
204}
205
206
207/*-------------------------------------------------
208    palette_get_num_groups - return the number of
209    groups managed by the palette
210-------------------------------------------------*/
211
212int palette_get_num_groups(palette_t *palette)
213{
214   return palette->numgroups;
215}
216
217
218/*-------------------------------------------------
219    palette_get_black_entry - return the index of
220    the black entry
221-------------------------------------------------*/
222
223UINT32 palette_get_black_entry(palette_t *palette)
224{
225   return palette->numcolors * palette->numgroups + 0;
226}
227
228
229/*-------------------------------------------------
230    palette_get_white_entry - return the index of
231    the white entry
232-------------------------------------------------*/
233
234UINT32 palette_get_white_entry(palette_t *palette)
235{
236   return palette->numcolors * palette->numgroups + 1;
237}
238
239
240
241/***************************************************************************
242    PALETTE CLIENTS
243***************************************************************************/
244
245/*-------------------------------------------------
246    palette_client_alloc - add a new client to a
247    palette
248-------------------------------------------------*/
249
250palette_client *palette_client_alloc(palette_t *palette)
251{
252   UINT32 total_colors = palette->numcolors * palette->numgroups;
253   UINT32 dirty_dwords = (total_colors + 31) / 32;
254   palette_client *client;
255
256   /* allocate memory for the client */
257   client = malloc(sizeof(*client));
258   if (client == NULL)
259      goto error;
260   memset(client, 0, sizeof(*client));
261
262   /* allocate dirty lists */
263   client->live.dirty = malloc(dirty_dwords * sizeof(UINT32));
264   client->previous.dirty = malloc(dirty_dwords * sizeof(UINT32));
265   if (client->live.dirty == NULL || client->previous.dirty == NULL)
266      goto error;
267
268   /* mark everything dirty to start with */
269   memset(client->live.dirty, 0xff, dirty_dwords * sizeof(UINT32));
270   memset(client->previous.dirty, 0xff, dirty_dwords * sizeof(UINT32));
271   client->live.dirty[dirty_dwords - 1] &= (1 << (total_colors % 32)) - 1;
272   client->previous.dirty[dirty_dwords - 1] &= (1 << (total_colors % 32)) - 1;
273
274   /* initialize the rest of the structure and add a reference to a palette */
275   client->palette = palette;
276   palette_ref(palette);
277   client->live.mindirty = 0;
278   client->live.maxdirty = total_colors - 1;
279
280   /* now add us to the list of clients */
281   client->next = palette->client_list;
282   palette->client_list = client;
283   return client;
284
285error:
286   if (client != NULL)
287   {
288      if (client->live.dirty != NULL)
289         free(client->live.dirty);
290      if (client->previous.dirty != NULL)
291         free(client->previous.dirty);
292      free(client);
293   }
294   return NULL;
295}
296
297
298/*-------------------------------------------------
299    palette_client_free - remove a client from a
300    palette
301-------------------------------------------------*/
302
303void palette_client_free(palette_client *client)
304{
305   palette_client **curptr;
306
307   /* first locate and remove ourself from the palette's list */
308   for (curptr = &client->palette->client_list; *curptr != NULL; curptr = &(*curptr)->next)
309      if (*curptr == client)
310      {
311         *curptr = client->next;
312         break;
313      }
314
315   /* now deref the palette */
316   palette_deref(client->palette);
317
318   /* free our data */
319   if (client->live.dirty != NULL)
320      free(client->live.dirty);
321   if (client->previous.dirty != NULL)
322      free(client->previous.dirty);
323   free(client);
324}
325
326
327/*-------------------------------------------------
328    palette_client_get_palette - return a pointer
329    to the palette for this client
330-------------------------------------------------*/
331
332palette_t *palette_client_get_palette(palette_client *client)
333{
334   return client->palette;
335}
336
337
338/*-------------------------------------------------
339    palette_client_get_dirty_list - atomically get
340    the current dirty list for a client
341-------------------------------------------------*/
342
343const UINT32 *palette_client_get_dirty_list(palette_client *client, UINT32 *mindirty, UINT32 *maxdirty)
344{
345   dirty_state temp;
346
347   /* fill in the mindirty/maxdirty */
348   if (mindirty != NULL)
349      *mindirty = client->live.mindirty;
350   if (maxdirty != NULL)
351      *maxdirty = client->live.maxdirty;
352
353   /* if nothing to report, report nothing and don't swap */
354   if (client->live.mindirty > client->live.maxdirty)
355      return NULL;
356
357   /* swap the live and previous lists */
358   temp = client->live;
359   client->live = client->previous;
360   client->previous = temp;
361
362   /* erase relevant entries in the new live one */
363   if (client->live.mindirty <= client->live.maxdirty)
364      memset(client->live.dirty, client->live.mindirty / 8, (client->live.maxdirty / 8) + 1 - (client->live.mindirty / 8));
365   client->live.mindirty = client->palette->numcolors * client->palette->numgroups;
366   client->live.maxdirty = 0;
367
368   /* return a pointer to the previous table */
369   return client->previous.dirty;
370}
371
372
373
374/***************************************************************************
375    PALETTE COLOR MANAGEMENT
376***************************************************************************/
377
378/*-------------------------------------------------
379    palette_entry_set_color - set the raw RGB
380    color for a given palette index
381-------------------------------------------------*/
382
383void palette_entry_set_color(palette_t *palette, UINT32 index, rgb_t rgb)
384{
385   int groupnum;
386
387   /* if out of range, or unchanged, ignore */
388   if (index >= palette->numcolors || palette->entry_color[index] == rgb)
389      return;
390
391   /* set the color */
392   palette->entry_color[index] = rgb;
393
394   /* update across all groups */
395   for (groupnum = 0; groupnum < palette->numgroups; groupnum++)
396      update_adjusted_color(palette, groupnum, index);
397}
398
399
400/*-------------------------------------------------
401    palette_entry_get_color - return the raw RGB
402    color for a given palette index
403-------------------------------------------------*/
404
405rgb_t palette_entry_get_color(palette_t *palette, UINT32 index)
406{
407   return (index < palette->numcolors) ? palette->entry_color[index] : RGB_BLACK;
408}
409
410
411/*-------------------------------------------------
412    palette_entry_get_adjusted_color - return the
413    adjusted RGB color (after all adjustments) for
414    a given palette index
415-------------------------------------------------*/
416
417rgb_t palette_entry_get_adjusted_color(palette_t *palette, UINT32 index)
418{
419   return (index < palette->numcolors * palette->numgroups) ? palette->adjusted_color[index] : RGB_BLACK;
420}
421
422
423/*-------------------------------------------------
424    palette_entry_list_raw - return the entire
425    palette as an array of raw RGB values
426-------------------------------------------------*/
427
428const rgb_t *palette_entry_list_raw(palette_t *palette)
429{
430   return palette->entry_color;
431}
432
433
434/*-------------------------------------------------
435    palette_entry_list_adjusted - return the
436    entire palette as an array of adjusted RGB
437    values
438-------------------------------------------------*/
439
440const rgb_t *palette_entry_list_adjusted(palette_t *palette)
441{
442   return palette->adjusted_color;
443}
444
445
446/*-------------------------------------------------
447    palette_entry_list_adjusted_rgb15 - return the
448    entire palette as an array of adjusted RGB-15
449    values
450-------------------------------------------------*/
451
452const rgb_t *palette_entry_list_adjusted_rgb15(palette_t *palette)
453{
454   return palette->adjusted_rgb15;
455}
456
457
458
459/***************************************************************************
460    PALETTE ADJUSTMENTS
461***************************************************************************/
462
463/*-------------------------------------------------
464    palette_entry_set_contrast - set the contrast
465    adjustment for a single palette index
466-------------------------------------------------*/
467
468void palette_entry_set_contrast(palette_t *palette, UINT32 index, float contrast)
469{
470   int groupnum;
471
472   /* if out of range, or unchanged, ignore */
473   if (index >= palette->numcolors || palette->entry_contrast[index] == contrast)
474      return;
475
476   /* set the contrast */
477   palette->entry_contrast[index] = contrast;
478
479   /* update across all groups */
480   for (groupnum = 0; groupnum < palette->numgroups; groupnum++)
481      update_adjusted_color(palette, groupnum, index);
482}
483
484
485/*-------------------------------------------------
486    palette_entry_get_contrast - return the
487    contrast adjustment for a single palette index
488-------------------------------------------------*/
489
490float palette_entry_get_contrast(palette_t *palette, UINT32 index)
491{
492   return (index < palette->numcolors) ? palette->entry_contrast[index] : 1.0f;
493}
494
495
496/*-------------------------------------------------
497    palette_group_set_brightness - configure
498    overall brightness for a palette group
499-------------------------------------------------*/
500
501void palette_group_set_brightness(palette_t *palette, UINT32 group, float brightness)
502{
503   int index;
504
505   /* if out of range, or unchanged, ignore */
506   if (group >= palette->numgroups || palette->group_bright[group] == brightness)
507      return;
508
509   /* set the contrast */
510   palette->group_bright[group] = brightness;
511
512   /* update across all colors */
513   for (index = 0; index < palette->numcolors; index++)
514      update_adjusted_color(palette, group, index);
515}
516
517
518/*-------------------------------------------------
519    palette_group_set_contrast - configure
520    overall contrast for a palette group
521-------------------------------------------------*/
522
523void palette_group_set_contrast(palette_t *palette, UINT32 group, float contrast)
524{
525   int index;
526
527   /* if out of range, or unchanged, ignore */
528   if (group >= palette->numgroups || palette->group_contrast[group] == contrast)
529      return;
530
531   /* set the contrast */
532   palette->group_contrast[group] = contrast;
533
534   /* update across all colors */
535   for (index = 0; index < palette->numcolors; index++)
536      update_adjusted_color(palette, group, index);
537}
538
539
540
541/***************************************************************************
542    PALETTE UTILITIES
543***************************************************************************/
544
545/*-------------------------------------------------
546    palette_normalize_range - normalize a range
547    of palette entries
548-------------------------------------------------*/
549
550void palette_normalize_range(palette_t *palette, UINT32 start, UINT32 end, int lum_min, int lum_max)
551{
552   UINT32 ymin = 1000 * 255, ymax = 0;
553   UINT32 tmin, tmax;
554   UINT32 index;
555
556   /* clamp within range */
557   start = MAX(start, 0);
558   end = MIN(end, palette->numcolors - 1);
559
560   /* find the minimum and maximum brightness of all the colors in the range */
561   for (index = start; index <= end; index++)
562   {
563      rgb_t rgb = palette->entry_color[index];
564      UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
565      ymin = MIN(ymin, y);
566      ymax = MAX(ymax, y);
567   }
568
569   /* determine target minimum/maximum */
570   tmin = (lum_min < 0) ? ((ymin + 500) / 1000) : lum_min;
571   tmax = (lum_max < 0) ? ((ymax + 500) / 1000) : lum_max;
572
573   /* now normalize the palette */
574   for (index = start; index <= end; index++)
575   {
576      rgb_t rgb = palette->entry_color[index];
577      UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
578      UINT32 target = tmin + ((y - ymin) * (tmax - tmin + 1)) / (ymax - ymin);
579      UINT8 r = (y == 0) ? 0 : rgb_clamp(RGB_RED(rgb) * 1000 * target / y);
580      UINT8 g = (y == 0) ? 0 : rgb_clamp(RGB_GREEN(rgb) * 1000 * target / y);
581      UINT8 b = (y == 0) ? 0 : rgb_clamp(RGB_BLUE(rgb) * 1000 * target / y);
582      palette_entry_set_color(palette, index, MAKE_RGB(r, g, b));
583   }
584}
585
586
587
588/***************************************************************************
589    INTERNAL ROUTINES
590***************************************************************************/
591
592/*-------------------------------------------------
593    internal_palette_free - free all allocations
594    from a palette
595-------------------------------------------------*/
596
597static void internal_palette_free(palette_t *palette)
598{
599   /* free per-color data */
600   if (palette->entry_color != NULL)
601      free(palette->entry_color);
602   if (palette->entry_contrast != NULL)
603      free(palette->entry_contrast);
604
605   /* free per-group data */
606   if (palette->group_bright != NULL)
607      free(palette->group_bright);
608   if (palette->group_contrast != NULL)
609      free(palette->group_contrast);
610
611   /* free adjusted data */
612   if (palette->adjusted_color != NULL)
613      free(palette->adjusted_color);
614   if (palette->adjusted_rgb15 != NULL)
615      free(palette->adjusted_rgb15);
616
617   /* and the palette itself */
618   free(palette);
619}
620
621
622/*-------------------------------------------------
623    update_adjusted_color - update a color index
624    by group and index pair
625-------------------------------------------------*/
626
627static void update_adjusted_color(palette_t *palette, UINT32 group, UINT32 index)
628{
629   UINT32 finalindex = group * palette->numcolors + index;
630   palette_client *client;
631   rgb_t adjusted;
632
633   /* compute the adjusted value */
634   adjusted = adjust_palette_entry(palette->entry_color[index], palette->group_bright[group], palette->group_contrast[group] * palette->entry_contrast[index]);
635
636   /* if not different, ignore */
637   if (palette->adjusted_color[finalindex] == adjusted)
638      return;
639
640   /* otherwise, modify the adjusted color array */
641   palette->adjusted_color[finalindex] = adjusted;
642   palette->adjusted_rgb15[finalindex] = rgb_to_rgb15(adjusted);
643
644   /* mark dirty in all clients */
645   for (client = palette->client_list; client != NULL; client = client->next)
646   {
647      client->live.dirty[finalindex / 32] |= 1 << (finalindex % 32);
648      client->live.mindirty = MIN(client->live.mindirty, finalindex);
649      client->live.maxdirty = MAX(client->live.maxdirty, finalindex);
650   }
651}
src/lib/util/chd.c
r936r937
114114};
115115
116116
117/* multifile object */
118typedef struct _multi_file multi_file;
119struct _multi_file
120{
121   UINT32               numfiles;      /* number of files */
122   chd_interface_file **   files;         /* array of open file handles */
123   UINT64 *            length;         /* array of file lengths */
124};
125
126
127117/* internal representation of an open CHD file */
128118struct _chd_file
129119{
130120   UINT32               cookie;         /* cookie, should equal COOKIE_VALUE */
131   chd_file *            next;         /* pointer to next file in the global list */
132121
133   multi_file *         file;         /* handle to the open multi file */
122   core_file *            file;         /* handle to the open core file */
123   UINT8               owns_file;      /* flag indicating if this file should be closed on chd_close() */
134124   chd_header             header;         /* header, extracted from file */
135125
136126   chd_file *            parent;         /* pointer to parent file, or NULL */
r936r937
194184    GLOBAL VARIABLES
195185***************************************************************************/
196186
197static chd_interface cur_interface;
198static chd_file *first_file;
199
200187static const UINT8 nullmd5[CHD_MD5_BYTES] = { 0 };
201188static const UINT8 nullsha1[CHD_SHA1_BYTES] = { 0 };
202189
r936r937
212199
213200/* internal header operations */
214201static chd_error header_validate(const chd_header *header);
215static chd_error header_read(multi_file *file, chd_header *header);
216static chd_error header_write(multi_file *file, const chd_header *header);
202static chd_error header_read(core_file *file, chd_header *header);
203static chd_error header_write(core_file *file, const chd_header *header);
217204
218205/* internal hunk read/write */
219206static chd_error hunk_read_into_cache(chd_file *chd, UINT32 hunknum);
r936r937
221208static chd_error hunk_write_from_memory(chd_file *chd, UINT32 hunknum, const UINT8 *src);
222209
223210/* internal map access */
224static chd_error map_write_initial(multi_file *file, chd_file *parent, const chd_header *header);
211static chd_error map_write_initial(core_file *file, chd_file *parent, const chd_header *header);
225212static chd_error map_read(chd_file *chd);
226213
227214/* internal CRC map access */
r936r937
250237static chd_error av_codec_config(chd_file *chd, int param, void *config);
251238static chd_error av_codec_postinit(chd_file *chd);
252239
253/* multifile routines */
254static multi_file *multi_open(const char *filename, const char *mode);
255static void multi_close(multi_file *file);
256static UINT32 multi_read(multi_file *file, UINT64 offset, UINT32 count, void *buffer);
257static UINT32 multi_write(multi_file *file, UINT64 offset, UINT32 count, const void *buffer);
258static UINT64 multi_length(multi_file *file);
259240
260241
261
262242/***************************************************************************
263243    CODEC INTERFACES
264244***************************************************************************/
r936r937
494474
495475
496476/***************************************************************************
497    EXTERNAL INTERFACING
498***************************************************************************/
499
500/*-------------------------------------------------
501    chd_set_interface - set the interface for
502    CHD accesses
503-------------------------------------------------*/
504
505void chd_set_interface(chd_interface *new_interface)
506{
507   if (new_interface != NULL)
508      cur_interface = *new_interface;
509   else
510      memset(&cur_interface, 0, sizeof(cur_interface));
511}
512
513
514
515/***************************************************************************
516477    CHD FILE MANAGEMENT
517478***************************************************************************/
518479
519480/*-------------------------------------------------
520    chd_create - create a new CHD file
481    chd_create_file - create a new CHD file
521482-------------------------------------------------*/
522483
523chd_error chd_create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent)
484chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent)
524485{
525   multi_file *file = NULL;
526486   chd_file *newchd = NULL;
527487   chd_header header;
528488   chd_error err;
529489   int intfnum;
530490
531   /* punt if no interface */
532   if (cur_interface.open == NULL)
533      EARLY_EXIT(err = CHDERR_NO_INTERFACE);
534
535491   /* verify parameters */
536   if (filename == NULL)
537      EARLY_EXIT(err = CHDERR_FILE_NOT_FOUND);
492   if (file == NULL)
493      EARLY_EXIT(err = CHDERR_INVALID_PARAMETER);
538494   if (parent == NULL && (logicalbytes == 0 || hunkbytes == 0))
539495      EARLY_EXIT(err = CHDERR_INVALID_PARAMETER);
540496
r936r937
579535   if (err != CHDERR_NONE)
580536      EARLY_EXIT(err);
581537
582   /* attempt to create the file */
583   file = multi_open(filename, "wb");
584   if (file == NULL)
585      EARLY_EXIT(err = CHDERR_CANT_CREATE_FILE);
586
587538   /* write the resulting header */
588539   err = header_write(file, &header);
589540   if (err != CHDERR_NONE)
r936r937
594545   if (err != CHDERR_NONE)
595546      EARLY_EXIT(err);
596547
597   /* all done */
598   multi_close(file);
599   file = NULL;
600
601548   /* if we have a parent, clone the metadata */
602549   if (parent != NULL)
603550   {
604551      /* open the new CHD via the standard mechanism */
605      err = chd_open(filename, CHD_OPEN_READWRITE, parent, &newchd);
552      err = chd_open_file(file, CHD_OPEN_READWRITE, parent, &newchd);
606553      if (err != CHDERR_NONE)
607554         EARLY_EXIT(err);
608555
r936r937
618565   return CHDERR_NONE;
619566
620567cleanup:
621   if (file != NULL)
622      multi_close(file);
623568   if (newchd != NULL)
624569      chd_close(newchd);
625570   return err;
r936r937
627572
628573
629574/*-------------------------------------------------
630    chd_open - open a CHD file for access
575    chd_open_file - open a CHD file for access
631576-------------------------------------------------*/
632577
633chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd)
578chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd)
634579{
635580   chd_file *newchd = NULL;
636   chd_file **currptr;
637581   chd_error err;
638582   int intfnum;
639583
640   /* punt if no interface */
641   if (cur_interface.open == NULL)
642      EARLY_EXIT(err = CHDERR_NO_INTERFACE);
643
644584   /* verify parameters */
645   if (filename == NULL)
646      EARLY_EXIT(err = CHDERR_FILE_NOT_FOUND);
585   if (file == NULL)
586      EARLY_EXIT(err = CHDERR_INVALID_PARAMETER);
647587
648588   /* punt if invalid parent */
649589   if (parent != NULL && parent->cookie != COOKIE_VALUE)
r936r937
656596   memset(newchd, 0, sizeof(*newchd));
657597   newchd->cookie = COOKIE_VALUE;
658598   newchd->parent = parent;
599   newchd->file = file;
659600
660   /* first attempt to open the file */
661   newchd->file = multi_open(filename, (mode == CHD_OPEN_READWRITE) ? "rb+" : "rb");
662   if (newchd->file == NULL)
663      EARLY_EXIT(err = CHDERR_FILE_NOT_FOUND);
664
665601   /* now attempt to read the header */
666602   err = header_read(newchd->file, &newchd->header);
667603   if (err != CHDERR_NONE)
r936r937
734670   if (err != CHDERR_NONE)
735671      EARLY_EXIT(err);
736672
737   /* hook us to the end of the global list */
738   for (currptr = &first_file; *currptr != NULL; currptr = &(*currptr)->next) ;
739   *chd = *currptr = newchd;
740
741673   /* all done */
674   *chd = newchd;
742675   return CHDERR_NONE;
743676
744677cleanup:
r936r937
749682
750683
751684/*-------------------------------------------------
685    chd_create - create a CHD file by
686    filename
687-------------------------------------------------*/
688
689chd_error chd_create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent)
690{
691   core_file *file = NULL;
692   file_error filerr;
693   chd_error chderr;
694
695   filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
696   if (filerr != FILERR_NONE)
697   {
698      chderr = CHDERR_FILE_NOT_FOUND;
699      goto cleanup;
700   }
701
702   chderr = chd_create_file(file, logicalbytes, hunkbytes, compression, parent);
703   if (chderr != CHDERR_NONE)
704      goto cleanup;
705
706cleanup:
707   if (file != NULL)
708      core_fclose(file);
709   return chderr;
710}
711
712
713/*-------------------------------------------------
714    chd_open - open a CHD file by
715    filename
716-------------------------------------------------*/
717
718chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd)
719{
720   chd_error err;
721   file_error filerr;
722   core_file *file = NULL;
723   UINT32 openflags;
724
725   /* choose the proper mode */
726   switch(mode)
727   {
728      case CHD_OPEN_READ:
729         openflags = OPEN_FLAG_READ;
730         break;
731
732      case CHD_OPEN_READWRITE:
733         openflags = OPEN_FLAG_READ | OPEN_FLAG_WRITE;
734         break;
735
736      default:
737         err = CHDERR_INVALID_PARAMETER;
738         goto cleanup;
739   }
740
741   /* open the file */
742   filerr = core_fopen(filename, openflags, &file);
743   if (filerr != FILERR_NONE)
744   {
745      err = CHDERR_FILE_NOT_FOUND;
746      goto cleanup;
747   }
748
749   /* now open the CHD */
750   err = chd_open_file(file, mode, parent, chd);
751   if (err != CHDERR_NONE)
752      goto cleanup;
753
754   /* we now own this file */
755   (*chd)->owns_file = TRUE;
756
757cleanup:
758   if ((err != CHDERR_NONE) && (file != NULL))
759      core_fclose(file);
760   return err;
761}
762
763
764/*-------------------------------------------------
752765    chd_close - close a CHD file for access
753766-------------------------------------------------*/
754767
755768void chd_close(chd_file *chd)
756769{
757   chd_file **currptr;
758
759770   /* punt if NULL or invalid */
760771   if (chd == NULL || chd->cookie != COOKIE_VALUE)
761772      return;
r936r937
796807      free(chd->crcmap);
797808
798809   /* close the file */
799   if (chd->file != NULL)
800      multi_close(chd->file);
810   if (chd->owns_file && chd->file != NULL)
811      core_fclose(chd->file);
801812
802   /* unlink ourselves */
803   for (currptr = &first_file; *currptr != NULL; currptr = &(*currptr)->next)
804      if (*currptr == chd)
805      {
806         *currptr = (*currptr)->next;
807         break;
808      }
809
810813#if PRINTF_MAX_HUNK
811814   printf("Max hunk = %d/%d\n", chd->maxhunk, chd->header.totalhunks);
812815#endif
r936r937
817820
818821
819822/*-------------------------------------------------
820    chd_close_all - close all open CHD files
823    chd_core_file - return the associated
824    core_file
821825-------------------------------------------------*/
822826
823void chd_close_all(void)
827core_file *chd_core_file(chd_file *chd)
824828{
825   while (first_file != NULL)
826      chd_close(first_file);
829   return chd->file;
827830}
828831
829832
r936r937
876879
877880
878881/*-------------------------------------------------
879    chd_set_header - write the current header to
882    chd_set_header_file - write the current header to
880883    the file
881884-------------------------------------------------*/
882885
883chd_error chd_set_header(const char *filename, const chd_header *header)
886chd_error chd_set_header_file(core_file *file, const chd_header *header)
884887{
885   multi_file *file = NULL;
886888   chd_header oldheader;
887889   chd_error err;
888890
889   /* punt if no interface */
890   if (cur_interface.open == NULL)
891      EARLY_EXIT(err = CHDERR_NO_INTERFACE);
892
893   /* punt if NULL or invalid */
894   if (filename == NULL || header == NULL)
895      EARLY_EXIT(err = CHDERR_INVALID_PARAMETER);
896
897891   /* validate the header */
898892   err = header_validate(header);
899893   if (err != CHDERR_NONE)
900894      EARLY_EXIT(err);
901895
902   /* attempt to open the file */
903   file = multi_open(filename, "rb+");
904   if (file == NULL)
905      EARLY_EXIT(err = CHDERR_FILE_NOT_FOUND);
906
907896   /* read the old header */
908897   err = header_read(file, &oldheader);
909898   if (err != CHDERR_NONE)
r936r937
930919   if (err != CHDERR_NONE)
931920      EARLY_EXIT(err);
932921
933   /* close the file and return */
934   multi_close(file);
935922   return CHDERR_NONE;
936923
937924cleanup:
938   if (file)
939      multi_close(file);
940925   return err;
941926}
942927
943928
929/*-------------------------------------------------
930    chd_set_header - write the current
931    header to the file
932-------------------------------------------------*/
944933
934chd_error chd_set_header(const char *filename, const chd_header *header)
935{
936   core_file *file = NULL;
937   file_error filerr;
938   chd_error err;
939
940   filerr = core_fopen(filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE, &file);
941   if (filerr != FILERR_NONE)
942   {
943      err = CHDERR_FILE_NOT_FOUND;
944      goto cleanup;
945   }
946
947   err = chd_set_header_file(file, header);
948   if (err != CHDERR_NONE)
949      goto cleanup;
950
951cleanup:
952   if (file != NULL)
953      core_fclose(file);
954   return err;
955}
956
957
958
945959/***************************************************************************
946960    CORE DATA READ/WRITE
947961***************************************************************************/
r936r937
11281142
11291143   /* read the metadata */
11301144   outputlen = MIN(outputlen, metaentry.length);
1131   count = multi_read(chd->file, metaentry.offset + METADATA_HEADER_SIZE, outputlen, output);
1145   core_fseek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET);
1146   count = core_fread(chd->file, output, outputlen);
11321147   if (count != outputlen)
11331148      return CHDERR_READ_ERROR;
11341149
r936r937
11761191   if (err == CHDERR_NONE && inputlen <= metaentry.length)
11771192   {
11781193      /* overwrite the original data with our new input data */
1179      count = multi_write(chd->file, metaentry.offset + METADATA_HEADER_SIZE, inputlen, inputbuf);
1194      core_fseek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET);
1195      count = core_fwrite(chd->file, inputbuf, inputlen);
11801196      if (count != inputlen)
11811197         return CHDERR_WRITE_ERROR;
11821198
r936r937
12041220   put_bigendian_uint64(&raw_meta_header[8], (err == CHDERR_NONE) ? metaentry.next : 0);
12051221
12061222   /* write out the new header */
1207   offset = multi_length(chd->file);
1208   count = multi_write(chd->file, offset, sizeof(raw_meta_header), raw_meta_header);
1223   offset = core_fsize(chd->file);
1224   core_fseek(chd->file, offset, SEEK_SET);
1225   count = core_fwrite(chd->file, raw_meta_header, sizeof(raw_meta_header));
12091226   if (count != sizeof(raw_meta_header))
12101227      return CHDERR_WRITE_ERROR;
12111228
12121229   /* follow that with the data */
1213   count = multi_write(chd->file, offset + METADATA_HEADER_SIZE, inputlen, inputbuf);
1230   core_fseek(chd->file, offset + METADATA_HEADER_SIZE, SEEK_SET);
1231   count = core_fwrite(chd->file, inputbuf, inputlen);
12141232   if (count != inputlen)
12151233      return CHDERR_WRITE_ERROR;
12161234
r936r937
12981316{
12991317   chd_error err;
13001318
1301   /* punt if no interface */
1302   if (cur_interface.open == NULL)
1303      return CHDERR_NO_INTERFACE;
1304
13051319   /* verify parameters */
13061320   if (chd == NULL)
13071321      return CHDERR_INVALID_PARAMETER;
r936r937
13791393   /* update the ratio */
13801394   if (curratio != NULL)
13811395   {
1382      UINT64 curlength = multi_length(chd->file);
1396      UINT64 curlength = core_fsize(chd->file);
13831397      *curratio = 1.0 - (double)curlength / (double)((UINT64)chd->comphunk * (UINT64)chd->header.hunkbytes);
13841398   }
13851399
r936r937
14221436
14231437chd_error chd_verify_begin(chd_file *chd)
14241438{
1425   /* punt if no interface */
1426   if (cur_interface.open == NULL)
1427      return CHDERR_NO_INTERFACE;
1428
14291439   /* verify parameters */
14301440   if (chd == NULL)
14311441      return CHDERR_INVALID_PARAMETER;
r936r937
16661676    internal data structure
16671677-------------------------------------------------*/
16681678
1669static chd_error header_read(multi_file *file, chd_header *header)
1679static chd_error header_read(core_file *file, chd_header *header)
16701680{
16711681   UINT8 rawheader[CHD_MAX_HEADER_SIZE];
16721682   UINT32 count;
r936r937
16791689   if (!file)
16801690      return CHDERR_INVALID_FILE;
16811691
1682   /* punt if no interface */
1683   if (!cur_interface.read)
1684      return CHDERR_NO_INTERFACE;
1685
16861692   /* seek and read */
1687   count = multi_read(file, 0, sizeof(rawheader), rawheader);
1693   core_fseek(file, 0, SEEK_SET);
1694   count = core_fread(file, rawheader, sizeof(rawheader));
16881695   if (count != sizeof(rawheader))
16891696      return CHDERR_READ_ERROR;
16901697
r936r937
17481755    internal data structure
17491756-------------------------------------------------*/
17501757
1751static chd_error header_write(multi_file *file, const chd_header *header)
1758static chd_error header_write(core_file *file, const chd_header *header)
17521759{
17531760   UINT8 rawheader[CHD_MAX_HEADER_SIZE];
17541761   UINT32 count;
r936r937
17611768   if (!file)
17621769      return CHDERR_INVALID_FILE;
17631770
1764   /* punt if no interface */
1765   if (!cur_interface.write)
1766      return CHDERR_NO_INTERFACE;
1767
17681771   /* only support writing modern headers */
17691772   if (header->version != 3)
17701773      return CHDERR_INVALID_PARAMETER;
r936r937
17871790   memcpy(&rawheader[100], header->parentsha1, CHD_SHA1_BYTES);
17881791
17891792   /* seek and write */
1790   count = multi_write(file, 0, CHD_V3_HEADER_SIZE, rawheader);
1793   core_fseek(file, 0, SEEK_SET);
1794   count = core_fwrite(file, rawheader, CHD_V3_HEADER_SIZE);
17911795   if (count != CHD_V3_HEADER_SIZE)
17921796      return CHDERR_WRITE_ERROR;
17931797
r936r937
18511855      case MAP_ENTRY_TYPE_COMPRESSED:
18521856
18531857         /* read it into the decompression buffer */
1854         bytes = multi_read(chd->file, entry->offset, entry->length, chd->compressed);
1858         core_fseek(chd->file, entry->offset, SEEK_SET);
1859         bytes = core_fread(chd->file, chd->compressed, entry->length);
18551860         if (bytes != entry->length)
18561861            return CHDERR_READ_ERROR;
18571862
r936r937
18651870
18661871      /* uncompressed data */
18671872      case MAP_ENTRY_TYPE_UNCOMPRESSED:
1868         bytes = multi_read(chd->file, entry->offset, chd->header.hunkbytes, dest);
1873         core_fseek(chd->file, entry->offset, SEEK_SET);
1874         bytes = core_fread(chd->file, dest, chd->header.hunkbytes);
18691875         if (bytes != chd->header.hunkbytes)
18701876            return CHDERR_READ_ERROR;
18711877         break;
r936r937
19911997   /* if the data doesn't fit into the previous entry, make a new one at the eof */
19921998   newentry.offset = entry->offset;
19931999   if (newentry.offset == 0 || newentry.length > entry->length)
1994      newentry.offset = multi_length(chd->file);
2000      newentry.offset = core_fsize(chd->file);
19952001
19962002   /* write the data */
1997   bytes = multi_write(chd->file, newentry.offset, newentry.length, data);
2003   core_fseek(chd->file, newentry.offset, SEEK_SET);
2004   bytes = core_fwrite(chd->file, data, newentry.length);
19982005   if (bytes != newentry.length)
19992006      return CHDERR_WRITE_ERROR;
20002007
r936r937
20042011
20052012   /* update the map on file */
20062013   map_assemble(&fileentry[0], &chd->map[hunknum]);
2007   bytes = multi_write(chd->file, chd->header.length + hunknum * sizeof(fileentry), sizeof(fileentry), &fileentry[0]);
2014   core_fseek(chd->file, chd->header.length + hunknum * sizeof(fileentry), SEEK_SET);
2015   bytes = core_fwrite(chd->file, &fileentry[0], sizeof(fileentry));
20082016   if (bytes != sizeof(fileentry))
20092017      return CHDERR_WRITE_ERROR;
20102018
r936r937
20222030    a new CHD file
20232031-------------------------------------------------*/
20242032
2025static chd_error map_write_initial(multi_file *file, chd_file *parent, const chd_header *header)
2033static chd_error map_write_initial(core_file *file, chd_file *parent, const chd_header *header)
20262034{
20272035   UINT8 blank_map_entries[MAP_STACK_ENTRIES * MAP_ENTRY_SIZE];
20282036   int fullchunks, remainder, count, i, j;
r936r937
20562064         }
20572065
20582066      /* write the chunks */
2059      count = multi_write(file, fileoffset, sizeof(blank_map_entries), blank_map_entries);
2067      core_fseek(file, fileoffset, SEEK_SET);
2068      count = core_fwrite(file, blank_map_entries, sizeof(blank_map_entries));
20602069      if (count != sizeof(blank_map_entries))
20612070         return CHDERR_WRITE_ERROR;
20622071      fileoffset += sizeof(blank_map_entries);
r936r937
20762085         }
20772086
20782087      /* write the chunks */
2079      count = multi_write(file, fileoffset, remainder * MAP_ENTRY_SIZE, blank_map_entries);
2088      core_fseek(file, fileoffset, SEEK_SET);
2089      count = core_fwrite(file, blank_map_entries, remainder * MAP_ENTRY_SIZE);
20802090      if (count != remainder * MAP_ENTRY_SIZE)
20812091         return CHDERR_WRITE_ERROR;
20822092      fileoffset += remainder * MAP_ENTRY_SIZE;
r936r937
20842094
20852095   /* then write a special end-of-list cookie */
20862096   memcpy(&blank_map_entries[0], END_OF_LIST_COOKIE, MAP_ENTRY_SIZE);
2087   count = multi_write(file, fileoffset, MAP_ENTRY_SIZE, blank_map_entries);
2097   core_fseek(file, fileoffset, SEEK_SET);
2098   count = core_fwrite(file, blank_map_entries, MAP_ENTRY_SIZE);
20882099   if (count != MAP_ENTRY_SIZE)
20892100      return CHDERR_WRITE_ERROR;
20902101
r936r937
21202131         entries = MAP_STACK_ENTRIES;
21212132
21222133      /* read that many */
2123      count = multi_read(chd->file, fileoffset, entries * entrysize, raw_map_entries);
2134      core_fseek(chd->file, fileoffset, SEEK_SET);
2135      count = core_fread(chd->file, raw_map_entries, entries * entrysize);
21242136      if (count != entries * entrysize)
21252137      {
21262138         err = CHDERR_READ_ERROR;
r936r937
21482160   }
21492161
21502162   /* verify the cookie */
2151   count = multi_read(chd->file, fileoffset, entrysize, &cookie);
2163   core_fseek(chd->file, fileoffset, SEEK_SET);
2164   count = core_fread(chd->file, &cookie, entrysize);
21522165   if (count != entrysize || memcmp(&cookie, END_OF_LIST_COOKIE, entrysize))
21532166   {
21542167      err = CHDERR_INVALID_FILE;
r936r937
21562169   }
21572170
21582171   /* verify the length */
2159   if (maxoffset > multi_length(chd->file))
2172   if (maxoffset > core_fsize(chd->file))
21602173   {
21612174      err = CHDERR_INVALID_FILE;
21622175      goto cleanup;
r936r937
23232336      UINT32   count;
23242337
23252338      /* read the raw header */
2326      count = multi_read(chd->file, metaentry->offset, sizeof(raw_meta_header), raw_meta_header);
2339      core_fseek(chd->file, metaentry->offset, SEEK_SET);
2340      count = core_fread(chd->file, raw_meta_header, sizeof(raw_meta_header));
23272341      if (count != sizeof(raw_meta_header))
23282342         break;
23292343
r936r937
23712385   else
23722386   {
23732387      /* read the previous raw header */
2374      count = multi_read(chd->file, prevoffset, sizeof(raw_meta_header), raw_meta_header);
2388      core_fseek(chd->file, prevoffset, SEEK_SET);
2389      count = core_fread(chd->file, raw_meta_header, sizeof(raw_meta_header));
23752390      if (count != sizeof(raw_meta_header))
23762391         return CHDERR_READ_ERROR;
23772392
r936r937
23792394      put_bigendian_uint64(&raw_meta_header[8], nextoffset);
23802395
23812396      /* write the previous raw header */
2382      count = multi_write(chd->file, prevoffset, sizeof(raw_meta_header), raw_meta_header);
2397      core_fseek(chd->file, prevoffset, SEEK_SET);
2398      count = core_fwrite(chd->file, raw_meta_header, sizeof(raw_meta_header));
23832399      if (count != sizeof(raw_meta_header))
23842400         return CHDERR_WRITE_ERROR;
23852401   }
r936r937
23992415   UINT32 count;
24002416
24012417   /* read the raw header */
2402   count = multi_read(chd->file, offset, sizeof(raw_meta_header), raw_meta_header);
2418   core_fseek(chd->file, offset, SEEK_SET);
2419   count = core_fread(chd->file, raw_meta_header, sizeof(raw_meta_header));
24032420   if (count != sizeof(raw_meta_header))
24042421      return CHDERR_READ_ERROR;
24052422
r936r937
24072424   put_bigendian_uint32(&raw_meta_header[4], length);
24082425
24092426   /* write the raw header */
2410   count = multi_write(chd->file, offset, sizeof(raw_meta_header), raw_meta_header);
2427   core_fseek(chd->file, offset, SEEK_SET);
2428   count = core_fwrite(chd->file, raw_meta_header, sizeof(raw_meta_header));
24112429   if (count != sizeof(raw_meta_header))
24122430      return CHDERR_WRITE_ERROR;
24132431
r936r937
28402858   avcomp_decompress_config(data->compstate, data->decompconfig.decode_mask, data->decompconfig.video_buffer, data->decompconfig.video_stride, data->decompconfig.video_xor, data->decompconfig.audio_xor);
28412859   return CHDERR_NONE;
28422860}
2843
2844
2845
2846/***************************************************************************
2847    MULTIFILE ROUTINES
2848***************************************************************************/
2849
2850/*-------------------------------------------------
2851    multi_open - open one or more files that
2852    make up a CHD
2853-------------------------------------------------*/
2854
2855static multi_file *multi_open(const char *filename, const char *mode)
2856{
2857   chd_interface_file *chdfile = NULL;
2858   multi_file *file = NULL;
2859   char *curname = NULL;
2860   int numfiles = 1;
2861   int i;
2862
2863   /* open the first file */
2864   chdfile = (*cur_interface.open)(filename, mode);
2865   if (chdfile == NULL)
2866      return NULL;
2867
2868   /* allocate a new multi_file object */
2869   file = malloc(sizeof(*file));
2870   if (file == NULL)
2871      goto error;
2872   memset(file, 0, sizeof(*file));
2873
2874   /* if we're not writing, look for additional files */
2875   if (strchr(mode, 'w') == NULL && strchr(mode, '+') == NULL)
2876   {
2877      /* allocate a copy of the filename */
2878      curname = malloc(strlen(filename) + 1 + 4);
2879      if (curname == NULL)
2880         goto error;
2881
2882      /* count how many files are available */
2883      for ( ; numfiles <= 1000; numfiles++)
2884      {
2885         chd_interface_file *tempfile;
2886
2887         chd_multi_filename(filename, curname, numfiles - 1);
2888         tempfile = (*cur_interface.open)(curname, mode);
2889         if (tempfile == NULL)
2890            break;
2891         (*cur_interface.close)(tempfile);
2892      }
2893   }
2894
2895   /* allocate memory for the file and length arrays */
2896   file->files = malloc(numfiles * sizeof(file->files[0]));
2897   file->length = malloc(numfiles * sizeof(file->length[0]));
2898   if (file->files == NULL || file->length == NULL)
2899      goto error;
2900
2901   /* fill in the first entry */
2902   file->files[0] = chdfile;
2903   file->length[0] = (*cur_interface.length)(chdfile);
2904   file->numfiles = numfiles;
2905
2906   /* now open the remaining files for real */
2907   for (i = 1; i < file->numfiles; i++)
2908   {
2909      chd_multi_filename(filename, curname, i - 1);
2910      file->files[i] = (*cur_interface.open)(curname, mode);
2911      if (file->files[i] == NULL)
2912         goto error;
2913      file->length[i] = (*cur_interface.length)(file->files[i]);
2914   }
2915
2916   /* free memory */
2917   if (curname != NULL)
2918      free(curname);
2919
2920   return file;
2921
2922error:
2923   if (file != NULL)
2924   {
2925      if (file->files != NULL)
2926         free(file->files);
2927      if (file->length != NULL)
2928         free(file->length);
2929      free(file);
2930   }
2931   if (curname != NULL)
2932      free(curname);
2933   if (chdfile != NULL)
2934      (*cur_interface.close)(chdfile);
2935   return NULL;
2936}
2937
2938
2939/*-------------------------------------------------
2940    multi_close - close all open files associated
2941    with a CHD
2942-------------------------------------------------*/
2943
2944static void multi_close(multi_file *file)
2945{
2946   int i;
2947
2948   /* close all files */
2949   for (i = 0; i < file->numfiles; i++)
2950      (*cur_interface.close)(file->files[i]);
2951
2952   /* free memory */
2953   free(file->files);
2954   free(file->length);
2955   free(file);
2956}
2957
2958
2959/*-------------------------------------------------
2960    multi_read - read from potentially multiple
2961    files that make up a CHD
2962-------------------------------------------------*/
2963
2964static UINT32 multi_read(multi_file *file, UINT64 offset, UINT32 count, void *buffer)
2965{
2966   UINT64 baseoffset = 0;
2967   UINT32 firstcount;
2968   int i;
2969
2970   /* find the file where the starting offset lives */
2971   for (i = 0; i < file->numfiles; i++)
2972   {
2973      if (offset >= baseoffset && offset < baseoffset + file->length[i])
2974         break;
2975      baseoffset += file->length[i];
2976   }
2977
2978   /* if past the total end, return nothing */
2979   if (i == file->numfiles)
2980      return 0;
2981
2982   /* if we don't cross the end of the file, just do the read */
2983   if (offset + count <= baseoffset + file->length[i])
2984      return (*cur_interface.read)(file->files[i], offset - baseoffset, count, buffer);
2985
2986   /* otherwise, break it into two reads */
2987   firstcount = baseoffset + file->length[i] - offset;
2988   return multi_read(file, offset, firstcount, buffer) +
2989         multi_read(file, offset + firstcount, count - firstcount, (UINT8 *)buffer + firstcount);
2990}
2991
2992
2993/*-------------------------------------------------
2994    multi_write - write to a CHD file; writes
2995    past the end always go to the last file, no
2996    matter how large it grows
2997-------------------------------------------------*/
2998
2999static UINT32 multi_write(multi_file *file, UINT64 offset, UINT32 count, const void *buffer)
3000{
3001   UINT64 baseoffset = 0;
3002   UINT32 firstcount;
3003   int i;
3004
3005   /* find the file where the starting offset lives */
3006   for (i = 0; i < file->numfiles; i++)
3007   {
3008      if (offset >= baseoffset && offset < baseoffset + file->length[i])
3009         break;
3010      baseoffset += file->length[i];
3011   }
3012
3013   /* if past the total end, append to the last file */
3014   if (i == file->numfiles)
3015   {
3016      baseoffset -= file->length[--i];
3017      file->length[i] = (offset + count) - baseoffset;
3018   }
3019
3020   /* if we don't cross the end of the file, just do the write */
3021   if (offset + count <= baseoffset + file->length[i])
3022      return (*cur_interface.write)(file->files[i], offset - baseoffset, count, buffer);
3023
3024   /* otherwise, break it into two writes */
3025   firstcount = baseoffset + file->length[i] - offset;
3026   return multi_write(file, offset, firstcount, buffer) +
3027         multi_write(file, offset + firstcount, count - firstcount, (UINT8 *)buffer + firstcount);
3028}
3029
3030
3031/*-------------------------------------------------
3032    multi_length - return the total length of a
3033    CHD file
3034-------------------------------------------------*/
3035
3036static UINT64 multi_length(multi_file *file)
3037{
3038   UINT64 totalsize = 0;
3039   int i;
3040
3041   /* sum the sizes of all the files */
3042   for (i = 0; i < file->numfiles; i++)
3043      totalsize += file->length[i];
3044   return totalsize;
3045}
src/lib/util/palette.h
r0r937
1/******************************************************************************
2
3    palette.c
4
5    Core palette routines.
6
7    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#pragma once
13
14#ifndef __PALETTE_H__
15#define __PALETTE_H__
16
17#include "osdcore.h"
18
19
20/***************************************************************************
21    TYPE DEFINITIONS
22***************************************************************************/
23
24/* an rgb_t is a single combined R,G,B (and optionally alpha) value */
25typedef UINT32 rgb_t;
26
27/* an rgb15_t is a single combined 15-bit R,G,B value */
28typedef UINT16 rgb15_t;
29
30/* a palette is an opaque, reference counted object */
31typedef struct _palette_t palette_t;
32
33/* a palette client is someone who is tracking the dirty state of a palette */
34typedef struct _palette_client palette_client;
35
36
37
38/***************************************************************************
39    MACROS
40***************************************************************************/
41
42/* macros to assemble rgb_t values */
43#define MAKE_RGB(r,g,b)    ((((rgb_t)(r) & 0xff) << 16) | (((rgb_t)(g) & 0xff) << 8) | ((rgb_t)(b) & 0xff))
44#define MAKE_ARGB(a,r,g,b)   (MAKE_RGB(r,g,b) | (((rgb_t)(a) & 0xff) << 24))
45
46/* macros to extract components from rgb_t values */
47#define RGB_ALPHA(rgb)      (((rgb) >> 24) & 0xff)
48#define RGB_RED(rgb)      (((rgb) >> 16) & 0xff)
49#define RGB_GREEN(rgb)      (((rgb) >> 8) & 0xff)
50#define RGB_BLUE(rgb)      ((rgb) & 0xff)
51
52/* common colors */
53#define RGB_BLACK         (MAKE_RGB(0,0,0))
54#define RGB_WHITE         (MAKE_RGB(255,255,255))
55
56
57
58/***************************************************************************
59    FUNCTION PROTOTYPES
60***************************************************************************/
61
62
63/* ----- palette allocation ----- */
64
65/* allocate a new palette object and take a single reference on it */
66palette_t *palette_alloc(UINT32 numcolors, UINT32 numgroups);
67
68/* reference a palette object, incrementing its reference count */
69void palette_ref(palette_t *palette);
70
71/* dereference a palette object; if the reference count goes to 0, it is freed */
72void palette_deref(palette_t *palette);
73
74
75
76/* ----- palette information ----- */
77
78/* return the number of colors managed by the palette */
79int palette_get_num_colors(palette_t *palette);
80
81/* return the number of groups managed by the palette */
82int palette_get_num_groups(palette_t *palette);
83
84/* return the index of the black entry */
85UINT32 palette_get_black_entry(palette_t *palette);
86
87/* return the index of the white entry */
88UINT32 palette_get_white_entry(palette_t *palette);
89
90
91
92/* ----- palette clients ----- */
93
94/* add a new client to a palette */
95palette_client *palette_client_alloc(palette_t *palette);
96
97/* remove a client from a palette */
98void palette_client_free(palette_client *client);
99
100/* return a pointer to the palette for this client */
101palette_t *palette_client_get_palette(palette_client *client);
102
103/* atomically get the current dirty list for a client */
104const UINT32 *palette_client_get_dirty_list(palette_client *client, UINT32 *mindirty, UINT32 *maxdirty);
105
106
107
108/* ----- color management ----- */
109
110/* set the raw RGB color for a given palette index */
111void palette_entry_set_color(palette_t *palette, UINT32 index, rgb_t rgb);
112
113/* return the raw RGB color for a given palette index */
114rgb_t palette_entry_get_color(palette_t *palette, UINT32 index);
115
116/* return the adjusted RGB color (after all adjustments) for a given palette index */
117rgb_t palette_entry_get_adjusted_color(palette_t *palette, UINT32 index);
118
119/* return the entire palette as an array of raw RGB values */
120const rgb_t *palette_entry_list_raw(palette_t *palette);
121
122/* return the entire palette as an array of adjusted RGB values */
123const rgb_t *palette_entry_list_adjusted(palette_t *palette);
124
125/* return the entire palette as an array of adjusted RGB-15 values */
126const rgb_t *palette_entry_list_adjusted_rgb15(palette_t *palette);
127
128
129
130/* ----- palette adjustments ----- */
131
132/* set the contrast adjustment for a single palette index */
133void palette_entry_set_contrast(palette_t *palette, UINT32 index, float contrast);
134
135/* return the contrast adjustment for a single palette index */
136float palette_entry_get_contrast(palette_t *palette, UINT32 index);
137
138/* configure overall brightness for a palette group */
139void palette_group_set_brightness(palette_t *palette, UINT32 group, float brightness);
140
141/* configure overall contrast for a palette group */
142void palette_group_set_contrast(palette_t *palette, UINT32 group, float contrast);
143
144
145
146/* ----- palette utilities ----- */
147
148/* normalize a range of palette entries, mapping minimum brightness to lum_min and maximum
149   brightness to lum_max; if either value is < 0, that boundary value is not modified */
150void palette_normalize_range(palette_t *palette, UINT32 start, UINT32 end, int lum_min, int lum_max);
151
152
153
154/***************************************************************************
155    INLINE FUNCTIONS
156***************************************************************************/
157
158/*-------------------------------------------------
159    rgb_to_rgb15 - convert an RGB triplet to
160    a 15-bit OSD-specified RGB value
161-------------------------------------------------*/
162
163INLINE rgb15_t rgb_to_rgb15(rgb_t rgb)
164{
165   return ((RGB_RED(rgb) >> 3) << 10) | ((RGB_GREEN(rgb) >> 3) << 5) | ((RGB_BLUE(rgb) >> 3) << 0);
166}
167
168
169/*-------------------------------------------------
170    rgb_clamp - clamp an RGB component to 0-255
171-------------------------------------------------*/
172
173INLINE UINT8 rgb_clamp(INT32 value)
174{
175   if (value < 0)
176      return 0;
177   if (value > 255)
178      return 255;
179   return value;
180}
181
182
183/*-------------------------------------------------
184    pal1bit - convert a 1-bit value to 8 bits
185-------------------------------------------------*/
186
187INLINE UINT8 pal1bit(UINT8 bits)
188{
189   return (bits & 1) ? 0xff : 0x00;
190}
191
192
193/*-------------------------------------------------
194    pal2bit - convert a 2-bit value to 8 bits
195-------------------------------------------------*/
196
197INLINE UINT8 pal2bit(UINT8 bits)
198{
199   bits &= 3;
200   return (bits << 6) | (bits << 4) | (bits << 2) | bits;
201}
202
203
204/*-------------------------------------------------
205    pal3bit - convert a 3-bit value to 8 bits
206-------------------------------------------------*/
207
208INLINE UINT8 pal3bit(UINT8 bits)
209{
210   bits &= 7;
211   return (bits << 5) | (bits << 2) | (bits >> 1);
212}
213
214
215/*-------------------------------------------------
216    pal4bit - convert a 4-bit value to 8 bits
217-------------------------------------------------*/
218
219INLINE UINT8 pal4bit(UINT8 bits)
220{
221   bits &= 0xf;
222   return (bits << 4) | bits;
223}
224
225
226/*-------------------------------------------------
227    pal5bit - convert a 5-bit value to 8 bits
228-------------------------------------------------*/
229
230INLINE UINT8 pal5bit(UINT8 bits)
231{
232   bits &= 0x1f;
233   return (bits << 3) | (bits >> 2);
234}
235
236
237/*-------------------------------------------------
238    pal6bit - convert a 6-bit value to 8 bits
239-------------------------------------------------*/
240
241INLINE UINT8 pal6bit(UINT8 bits)
242{
243   bits &= 0x3f;
244   return (bits << 2) | (bits >> 4);
245}
246
247
248/*-------------------------------------------------
249    pal7bit - convert a 7-bit value to 8 bits
250-------------------------------------------------*/
251
252INLINE UINT8 pal7bit(UINT8 bits)
253{
254   bits &= 0x7f;
255   return (bits << 1) | (bits >> 6);
256}
257
258
259#endif   /* __PALETTE_H__ */
src/lib/util/chd.h
r936r937
1313#define __CHD_H__
1414
1515#include "osdcore.h"
16#include "corefile.h"
1617
1718
1819/***************************************************************************
r936r937
171172
172173/* opaque types */
173174typedef struct _chd_file chd_file;
174typedef struct _chd_interface_file chd_interface_file;
175175
176176
177177/* progress callback function */
r936r937
202202};
203203
204204
205/* file I/O interface */
206typedef struct _chd_interface chd_interface;
207struct _chd_interface
208{
209   chd_interface_file *(*open)(const char *filename, const char *mode);
210   void (*close)(chd_interface_file *file);
211   UINT32 (*read)(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
212   UINT32 (*write)(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
213   UINT64 (*length)(chd_interface_file *file);
214};
215
216
217205/* A/V codec decompression configuration */
218206typedef struct _av_codec_decompress_config av_codec_decompress_config;
219207struct _av_codec_decompress_config
r936r937
232220***************************************************************************/
233221
234222
235/* ----- external interfacing ----- */
236
237/* set the interface callbacks used for file I/O */
238void chd_set_interface(chd_interface *new_interface);
239
240
241
242223/* ----- CHD file management ----- */
243224
244225/* create a new CHD file fitting the given description */
245226chd_error chd_create(const char *filename, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent);
246227
228/* same as chd_create(), but accepts an already-opened core_file object */
229chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent);
230
247231/* open an existing CHD file */
248232chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd);
249233
234/* same as chd_open(), but accepts an already-opened core_file object */
235chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd);
236
250237/* close a CHD file */
251238void chd_close(chd_file *chd);
252239
253/* close all open CHD files */
254void chd_close_all(void);
240/* return the associated core_file */
241core_file *chd_core_file(chd_file *chd);
255242
256/* compute the indexed filename for multi-CHD use */
257void chd_multi_filename(const char *origname, char *finalname, int index);
258243
259244
260
261245/* ----- CHD header management ----- */
262246
263247/* return a pointer to the extracted CHD header data */
r936r937
266250/* set a modified header */
267251chd_error chd_set_header(const char *filename, const chd_header *header);
268252
253/* same as chd_set_header(), but accepts an already-opened core_file object */
254chd_error chd_set_header_file(core_file *file, const chd_header *header);
269255
270256
257
271258/* ----- core data read/write ----- */
272259
273260/* read one hunk from the CHD file */
src/lib/util/png.c
r936r937
3939};
4040
4141
42/* temporary */
43typedef UINT32 rgb_t;
4442
45#define RGB_ALPHA(x)   (((x) >> 24) & 0xff)
46#define RGB_RED(x)      (((x) >> 16) & 0xff)
47#define RGB_GREEN(x)   (((x) >> 8) & 0xff)
48#define RGB_BLUE(x)      (((x) >> 0) & 0xff)
49
50INLINE UINT8 pal5bit(UINT8 bits)
51{
52   bits &= 0x1f;
53   return (bits << 3) | (bits >> 2);
54}
55
56
5743/***************************************************************************
5844    GLOBAL VARIABLES
5945***************************************************************************/
src/lib/util/bitmap.c
r936r937
1414
1515
1616/***************************************************************************
17    CONSTANTS
17    BITMAP ALLOCATION/CONFIGURATION
1818***************************************************************************/
1919
20/* VERY IMPORTANT: bitmap_alloc must allocate also a "safety area" 16 pixels wide all
21   around the bitmap. This is required because, for performance reasons, some graphic
22   routines don't clip at boundaries of the bitmap. */
23#define BITMAP_SAFETY            16
24
25
26
27/***************************************************************************
28    BITMAP ALLOCATION
29***************************************************************************/
30
3120/*-------------------------------------------------
3221    bitmap_alloc -- allocate memory for a new
3322    bitmap of the given format
r936r937
3524
3625bitmap_t *bitmap_alloc(int width, int height, bitmap_format format)
3726{
27   return bitmap_alloc_slop(width, height, 0, 0, format);
28}
29
30
31/*-------------------------------------------------
32    bitmap_alloc_slop -- allocate a new bitmap with
33    additional slop on the borders
34-------------------------------------------------*/
35
36bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format)
37{
3838   int bpp = bitmap_format_to_bpp(format);
3939   size_t allocbytes;
4040   bitmap_t *bitmap;
r936r937
4545      return NULL;
4646
4747   /* round the width to a multiple of 8 and add some padding */
48   rowpixels = (width + 2 * BITMAP_SAFETY + 7) & ~7;
48   rowpixels = (width + 2 * xslop + 7) & ~7;
4949
5050   /* allocate memory */
51   allocbytes = sizeof(*bitmap) + rowpixels * (height + 2 * BITMAP_SAFETY) * bpp / 8;
51   allocbytes = sizeof(*bitmap) + rowpixels * (height + 2 * yslop) * bpp / 8;
5252   bitmap = malloc(allocbytes);
5353   if (bitmap == NULL)
5454      return NULL;
r936r937
6262   bitmap->height = height;
6363   bitmap->bpp = bpp;
6464   bitmap->rowpixels = rowpixels;
65   bitmap->base = (UINT8 *)bitmap + sizeof(*bitmap) + rowpixels * BITMAP_SAFETY + (bpp / 8) * BITMAP_SAFETY;
65   bitmap->base = (UINT8 *)bitmap + sizeof(*bitmap) + rowpixels * yslop + (bpp / 8) * xslop;
6666
6767   return bitmap;
6868}
r936r937
100100
101101
102102/*-------------------------------------------------
103    bitmap_set_palette -- associate a palette with
104    a bitmap
105-------------------------------------------------*/
106
107void bitmap_set_palette(bitmap_t *bitmap, palette_t *palette)
108{
109   /* first dereference any existing palette */
110   if (bitmap->palette != NULL)
111   {
112      palette_deref(bitmap->palette);
113      bitmap->palette = NULL;
114   }
115
116   /* then reference any new palette */
117   if (palette != NULL)
118   {
119      palette_ref(palette);
120      bitmap->palette = palette;
121   }
122}
123
124
125/*-------------------------------------------------
103126    bitmap_free -- release memory allocated for
104127    a bitmap
105128-------------------------------------------------*/
106129
107130void bitmap_free(bitmap_t *bitmap)
108131{
132   /* dereference the palette */
133   if (bitmap->palette != NULL)
134      palette_deref(bitmap->palette);
135
136   /* free the bitmap */
109137   free(bitmap);
110138}
111139
src/lib/util/bitmap.h
r936r937
1515#define __BITMAP_H__
1616
1717#include "osdcore.h"
18#include "palette.h"
1819
1920
2021/***************************************************************************
r936r937
5859   int            height;         /* height of the bitmap */
5960   bitmap_format   format;         /* format of the bitmap */
6061   int            bpp;         /* bits per pixel */
62   palette_t *      palette;      /* optional palette */
6163};
6264
6365
r936r937
8082    FUNCTION PROTOTYPES
8183***************************************************************************/
8284
85
8386/* ----- bitmap allocation ----- */
8487
88/* allocate a new bitmap of the given dimensions and format */
8589bitmap_t *bitmap_alloc(int width, int height, bitmap_format format);
90
91/* allocate a new bitmap with additional slop on the borders */
92bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format);
93
94/* wrap a bitmap object around an existing array of data */
8695bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_format format);
96
97/* associate a palette with a bitmap */
98void bitmap_set_palette(bitmap_t *bitmap, palette_t *palette);
99
100/* free allocated data for a bitmap */
87101void bitmap_free(bitmap_t *bitmap);
88102
89103
104
90105/* ----- bitmap drawing ----- */
91106
92void bitmap_fill(bitmap_t *dest, const rectangle *clip, UINT32 color);
107/* fill a bitmap with a single color, clipping to the given rectangle */
108void bitmap_fill(bitmap_t *dest, const rectangle *clip, rgb_t color);
93109
94110
111
95112/* ----- bitmap utilities ----- */
96113
114/* return the number of bits per pixel for a given bitmap format */
97115int bitmap_format_to_bpp(bitmap_format format);
98116
99117
100118
119
101120/***************************************************************************
102121    INLINE FUNCTIONS
103122***************************************************************************/
104123
105/* compute the intersection of two rectangles */
124/*-------------------------------------------------
125    sect_rect - compute the intersection of two
126    rectangles
127-------------------------------------------------*/
128
106129INLINE void sect_rect(rectangle *dst, const rectangle *src)
107130{
108131   if (src->min_x > dst->min_x) dst->min_x = src->min_x;
r936r937
112135}
113136
114137
115/* compute the union of two rectangles */
138/*-------------------------------------------------
139    union_rect - compute the union of two
140    rectangles
141-------------------------------------------------*/
142
116143INLINE void union_rect(rectangle *dst, const rectangle *src)
117144{
118145   if (src->min_x < dst->min_x) dst->min_x = src->min_x;
r936r937
122149}
123150
124151
125/* draw a filled rectangle into a bitmap of arbitrary depth */
152/*-------------------------------------------------
153    plot_box - draw a filled rectangle into a
154    bitmap of arbitrary depth
155-------------------------------------------------*/
156
126157INLINE void plot_box(bitmap_t *bitmap, int x, int y, int width, int height, UINT32 color)
127158{
128159   rectangle clip;
src/mess/devices/harddriv.c
r936r937
8585
8686/*************************************
8787 *
88 *  chd_create_ref()/chd_open_ref()
89 *
90 *  These are a set of wrappers that wrap the chd_open()
91 *  and chd_create() functions to provide a way to open
92 *  the images with a filename.  This is just a stopgap
93 *  measure until I get the core CHD code changed.  For
94 *  now, this is an ugly hack but it works very well
95 *
96 *  When these functions get moved into the core, it will
97 *  remove the need to specify an 'open' function in the
98 *  CHD interface
99 *
100 *************************************/
101
102#define ENCODED_IMAGE_REF_PREFIX   "/:/M/E/S/S//i/m/a/g/e//#"
103#define ENCODED_IMAGE_REF_FORMAT   (ENCODED_IMAGE_REF_PREFIX "%p.chd")
104#define ENCODED_IMAGE_REF_LEN      (sizeof(ENCODED_IMAGE_REF_PREFIX)+20)
105
106
107static void encode_ptr(void *ptr, char filename[ENCODED_IMAGE_REF_LEN])
108{
109   snprintf(filename, ENCODED_IMAGE_REF_LEN, ENCODED_IMAGE_REF_FORMAT, ptr);
110}
111
112
113
114int chd_create_ref(void *ref, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent)
115{
116   char filename[ENCODED_IMAGE_REF_LEN];
117   encode_ptr(ref, filename);
118   return chd_create(filename, logicalbytes, hunkbytes, compression, parent);
119}
120
121
122
123chd_error chd_open_ref(void *ref, int mode, chd_file *parent, chd_file **chd)
124{
125   char filename[ENCODED_IMAGE_REF_LEN];
126   encode_ptr(ref, filename);
127   return chd_open(filename, mode, parent, chd);
128}
129
130
131
132/*************************************
133 *
134 *   decode_image_ref()
135 *
136 *   This function will decode an image pointer,
137 *   provided one has been encoded in the ASCII
138 *   string.
139 *
140 *************************************/
141
142static mess_image *decode_image_ref(const char encoded_image_ref[ENCODED_IMAGE_REF_LEN])
143{
144   void *ptr;
145   char c[5] = { 0, };
146
147   /* scan the reference */
148   if (sscanf(encoded_image_ref, ENCODED_IMAGE_REF_PREFIX "%p%c%c%c%c", &ptr, &c[0], &c[1], &c[2], &c[3]) != 5)
149      return NULL;
150
151   /* check for the correct file extension */
152   if (strcmp(c, ".chd"))
153      return NULL;
154
155   /* success */
156   return (mess_image *) ptr;
157}
158
159
160
161/*************************************
162 *
163 *   Interface between MAME's CHD system and MESS's image system
164 *
165 *************************************/
166
167static chd_interface_file *mess_chd_open(const char *filename, const char *mode);
168static void mess_chd_close(chd_interface_file *file);
169static UINT32 mess_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
170static UINT32 mess_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
171static UINT64 mess_chd_length(chd_interface_file *file);
172
173static chd_interface mess_hard_disk_interface =
174{
175   mess_chd_open,
176   mess_chd_close,
177   mess_chd_read,
178   mess_chd_write,
179   mess_chd_length
180};
181
182
183static chd_interface_file *mess_chd_open(const char *filename, const char *mode)
184{
185   file_error filerr;
186   mess_image *image = decode_image_ref(filename);
187
188   /* used when experimenting with CHDs */
189   if (USE_CHD_OPEN && !image)
190   {
191      mame_file *file;
192      filerr = mame_fopen(SEARCHPATH_IMAGE, filename, OPEN_FLAG_READ, &file);
193      return (chd_interface_file *) file;
194   }
195
196   /* invalid "file name"? */
197   if (!image)
198      return NULL;
199
200   /* read-only fp? */
201   if (!image_is_writable(image) && !(mode[0] == 'r' && !strchr(mode, '+')))
202      return NULL;
203
204   /* otherwise return file pointer */
205   return (chd_interface_file *) image;
206}
207
208
209
210static void mess_chd_close(chd_interface_file *file)
211{
212}
213
214
215
216static UINT32 mess_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
217{
218   image_fseek((mess_image *)file, offset, SEEK_SET);
219   return image_fread((mess_image *)file, buffer, count);
220}
221
222
223
224static UINT32 mess_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
225{
226   image_fseek((mess_image *)file, offset, SEEK_SET);
227   return image_fwrite((mess_image *)file, buffer, count);
228}
229
230
231
232static UINT64 mess_chd_length(chd_interface_file *file)
233{
234   return image_length((mess_image *)file);
235}
236
237
238
239
240/*************************************
241 *
24288 *   device_init_mess_hd()
24389 *
24490 *   Device init
r936r937
255101
256102   hd->hard_disk_handle = NULL;
257103
258   chd_set_interface(&mess_hard_disk_interface);
259
260104   return INIT_PASS;
261105}
262106
r936r937
286130   {
287131      is_writeable = image_is_writable(image);
288132      chd = NULL;
289      err = chd_open_ref(image, is_writeable ? CHD_OPEN_READWRITE : CHD_OPEN_READ, NULL, &chd);
133      err = chd_open_file(image_core_file(image), is_writeable ? CHD_OPEN_READWRITE : CHD_OPEN_READ, NULL, &chd);
290134
291135      /* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the
292136       * image read only and repeat */
r936r937
348192   totalsectors = cylinders * heads * sectors;
349193
350194   /* create the CHD file */
351   err = chd_create_ref(image, (UINT64)totalsectors * (UINT64)sectorsize, hunksize, CHDCOMPRESSION_NONE, NULL);
195   err = chd_create_file(image_core_file(image), (UINT64)totalsectors * (UINT64)sectorsize, hunksize, CHDCOMPRESSION_NONE, NULL);
352196   if (err != CHDERR_NONE)
353197      goto error;
354198
src/mess/devices/chd_cd.c
r936r937
8585 *
8686 *************************************/
8787
88#define ENCODED_IMAGE_REF_PREFIX   "/:/M/E/S/S//i/m/a/g/e//#"
89#ifdef PTR64
90#define ENCODED_IMAGE_REF_FORMAT   (ENCODED_IMAGE_REF_PREFIX "%016llx")
91#else
92#define ENCODED_IMAGE_REF_FORMAT   (ENCODED_IMAGE_REF_PREFIX "%016x")
93#endif
94#define ENCODED_IMAGE_REF_LEN      (sizeof(ENCODED_IMAGE_REF_PREFIX)+16)
95
96
97static void encode_ptr(void *ptr, char filename[ENCODED_IMAGE_REF_LEN])
98{
99   snprintf(filename, ENCODED_IMAGE_REF_LEN, ENCODED_IMAGE_REF_FORMAT,
100      (FPTR)ptr);
101}
102
103
104
105int chdcd_create_ref(void *ref, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent)
106{
107   char filename[ENCODED_IMAGE_REF_LEN];
108   encode_ptr(ref, filename);
109   return chd_create(filename, logicalbytes, hunkbytes, compression, parent);
110}
111
112
113
114chd_error chdcd_open_ref(void *ref, int mode, chd_file *parent, chd_file **chd)
115{
116   char filename[ENCODED_IMAGE_REF_LEN];
117   encode_ptr(ref, filename);
118   return chd_open(filename, mode, parent, chd);
119}
120
121
122
12388/*************************************
12489 *
125 *   decode_image_ref()
126 *
127 *   This function will decode an image pointer,
128 *   provided one has been encoded in the ASCII
129 *   string.
130 *
131 *************************************/
132
133static mess_image *decode_image_ref(const char encoded_image_ref[ENCODED_IMAGE_REF_LEN])
134{
135   FPTR ptr;
136
137   if (sscanf(encoded_image_ref, ENCODED_IMAGE_REF_FORMAT, &ptr) == 1)
138      return (mess_image *) ptr;
139
140   return NULL;
141}
142
143
144
145/*************************************
146 *
147 *   Interface between MAME's CHD system and MESS's image system
148 *
149 *************************************/
150
151static chd_interface_file *mess_chd_open(const char *filename, const char *mode);
152static void mess_chd_close(chd_interface_file *file);
153static UINT32 mess_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
154static UINT32 mess_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
155static UINT64 mess_chd_length(chd_interface_file *file);
156
157static chd_interface mess_cdrom_interface =
158{
159   mess_chd_open,
160   mess_chd_close,
161   mess_chd_read,
162   mess_chd_write,
163   mess_chd_length
164};
165
166
167static chd_interface_file *mess_chd_open(const char *filename, const char *mode)
168{
169   mess_image *img = decode_image_ref(filename);
170
171   /* invalid "file name"? */
172   assert(img);
173
174   /* cdroms are read-only */
175   if (!(mode[0] == 'r' && !strchr(mode, '+')))
176      return NULL;
177
178   /* otherwise return file pointer */
179   return (chd_interface_file *) img;
180}
181
182
183
184static void mess_chd_close(chd_interface_file *file)
185{
186}
187
188
189
190static UINT32 mess_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
191{
192   image_fseek((mess_image *)file, offset, SEEK_SET);
193   return image_fread((mess_image *)file, buffer, count);
194}
195
196
197
198static UINT32 mess_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
199{
200   image_fseek((mess_image *)file, offset, SEEK_SET);
201   return image_fwrite((mess_image *)file, buffer, count);
202}
203
204
205
206static UINT64 mess_chd_length(chd_interface_file *file)
207{
208   return image_length((mess_image *)file);
209}
210
211
212
213/*************************************
214 *
21590 *   device_init_mess_cd()
21691 *
21792 *   Device init
r936r937
228103
229104        cd->cdrom_handle = NULL;
230105
231   chd_set_interface(&mess_cdrom_interface);
232
233106   return INIT_PASS;
234107}
235108
r936r937
254127   cd = get_drive(image);
255128
256129   /* open the CHD file */
257   err = chdcd_open_ref(image, CHD_OPEN_READ, NULL, &chd);   /* CDs are never writable */
130   err = chd_open_file(image_core_file(image), CHD_OPEN_READ, NULL, &chd);   /* CDs are never writable */
258131   if (err)
259132      goto error;
260133
src/mess/mess.h
r936r937
1616#include "device.h"
1717#include "image.h"
1818#include "artworkx.h"
19#include "memory.h"
1920
2021
2122
src/mess/tools/imgtool/stream.c
r936r937
3232
3333   union
3434   {
35      osd_file *file;
35      core_file *file;
3636      UINT8 *buffer;
3737   } u;
3838};
r936r937
112112      OPEN_FLAG_READ | OPEN_FLAG_WRITE,
113113      OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE
114114   };
115   osd_file *f = NULL;
115   core_file *f = NULL;
116116   char *buf = NULL;
117117   int len, i;
118118   imgtool_stream *s = NULL;
119119   char c;
120   UINT64 filesize;
121120
122121   /* maybe we are just a ZIP? */
123122   ext = strrchr(fname, '.');
124123   if (ext && !mame_stricmp(ext, ".zip"))
125124      return stream_open_zip(fname, NULL, read_or_write);
126125
127   filerr = osd_open(fname, write_modes[read_or_write], &f, &filesize);
126   filerr = core_fopen(fname, write_modes[read_or_write], &f);
128127   if (filerr != FILERR_NONE)
129128   {
130129      if (!read_or_write)
r936r937
166165   memset(imgfile, 0, sizeof(*imgfile));
167166   imgfile->imgtype = IMG_FILE;
168167   imgfile->position = 0;
169   imgfile->filesize = filesize;
168   imgfile->filesize = core_fsize(f);
170169   imgfile->write_protect = read_or_write ? 0 : 1;
171170   imgfile->u.file = f;
172171   imgfile->name = fname;
173172   return imgfile;
174173
175174error:
176   if (imgfile)
175   if (imgfile != NULL)
177176      free((void *) imgfile);
178   if (f)
179      osd_close(f);
177   if (f != NULL)
178      core_fclose(f);
180179   if (buf)
181180      free(buf);
182181   return (imgtool_stream *) NULL;
r936r937
236235   switch(s->imgtype)
237236   {
238237      case IMG_FILE:
239         osd_close(s->u.file);
238         core_fclose(s->u.file);
240239         break;
241240
242241      case IMG_MEM:
r936r937
252251
253252
254253
254core_file *stream_core_file(imgtool_stream *stream)
255{
256   return (stream->imgtype == IMG_FILE) ? stream->u.file : NULL;
257}
258
259
260
255261UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
256262{
257   file_error filerr;
258263   UINT32 result = 0;
259264
260265   switch(stream->imgtype)
261266   {
262267      case IMG_FILE:
263268         assert(sz == (UINT32) sz);
264         filerr = osd_read(stream->u.file, buf, stream->position, (UINT32) sz, &result);
269         core_fseek(stream->u.file, stream->position, SEEK_SET);
270         result = core_fread(stream->u.file, buf, (UINT32) sz);
265271         break;
266272
267273      case IMG_MEM:
r936r937
285291
286292UINT32 stream_write(imgtool_stream *s, const void *buf, UINT32 sz)
287293{
288   file_error filerr;
289294   void *new_buffer;
290295   UINT32 result = 0;
291296
r936r937
316321         break;
317322
318323      case IMG_FILE:
319         filerr = osd_write(s->u.file, buf, s->position, sz, &result);
324         core_fseek(s->u.file, s->position, SEEK_SET);
325         result = core_fwrite(s->u.file, buf, sz);
320326         break;
321327
322328      default:
src/mess/tools/imgtool/stream.h
r936r937
1010#define STREAM_H
1111
1212#include "imgterrs.h"
13#include "corefile.h"
1314#include "mamecore.h"
1415
1516typedef struct _imgtool_stream imgtool_stream;
r936r937
1819imgtool_stream *stream_open_write_stream(int filesize);
1920imgtool_stream *stream_open_mem(void *buf, size_t sz);
2021void stream_close(imgtool_stream *stream);
22core_file *stream_core_file(imgtool_stream *stream);
2123UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz);
2224UINT32 stream_write(imgtool_stream *stream, const void *buf, UINT32 sz);
2325UINT64 stream_size(imgtool_stream *stream);
src/mess/tools/imgtool/imghd.c
r936r937
1414#include "imghd.h"
1515
1616
17/* Encoded mess_image: in order to have hard_disk_open handle mess_image
18pointers, we encode the reference as an ASCII string and pass it as a file
19name.  mess_hard_disk_open then decodes the file name to get the original
20mess_image pointer. */
21#define encoded_image_ref_prefix "/:/i/m/g/t/o/o/l//S/T/R/E/A/M//#"
22#define encoded_image_ref_len_format "%03d"
23#define encoded_image_ref_format encoded_image_ref_prefix encoded_image_ref_len_format "@%p"
24enum
25{
26   ptr_max_len = 100,
27   encoded_image_ref_len_offset = sizeof(encoded_image_ref_prefix)-1,
28   encoded_image_ref_len_len = 3,
29   encoded_image_ref_max_len = sizeof(encoded_image_ref_prefix)-1+encoded_image_ref_len_len+1+ptr_max_len+1
30};
31
32
33
34/* this should not be necessary, but I'd rather introduce a spectacular rather
35 * than a subtle crash */
36static void chd_save_interface(chd_interface *intf)
37{
38   memset(intf, 0, sizeof(*intf));
39}
40
41
42
4317static imgtoolerr_t map_chd_error(chd_error chderr)
4418{
4519   imgtoolerr_t err;
r936r937
6842
6943
7044/*
71   encode_image_ref()
72
73   Encode an image pointer into an ASCII string that can be passed to
74   hard_disk_open as a file name.
75*/
76static void encode_image_ref(const imgtool_stream *stream, char encoded_image_ref[encoded_image_ref_max_len])
77{
78   int actual_len;
79   char buf[encoded_image_ref_len_len+1];
80
81   /* print, leaving len as 0 */
82   actual_len = snprintf(encoded_image_ref, encoded_image_ref_max_len,
83      encoded_image_ref_format, 0, (void *) stream);
84
85   /* debug check: has the buffer been filled */
86   assert(actual_len < (encoded_image_ref_max_len-1));
87
88   /* print actual lenght */
89   sprintf(buf, encoded_image_ref_len_format, actual_len);
90   memcpy(encoded_image_ref+encoded_image_ref_len_offset, buf, encoded_image_ref_len_len);
91}
92
93/*
94   decode_image_ref()
95
96   This function will decode an image pointer, provided one has been encoded
97   in the ASCII string.
98*/
99static imgtool_stream *decode_image_ref(const char *encoded_image_ref)
100{
101   int expected_len;
102   void *ptr;
103
104   /* read original lenght and ptr */
105   if (sscanf(encoded_image_ref, encoded_image_ref_format, &expected_len, &ptr) == 2)
106   {
107      /* only return ptr if lenght match */
108      if (expected_len == strlen(encoded_image_ref))
109         return (imgtool_stream *) ptr;
110   }
111
112   return NULL;
113}
114
115
116static chd_interface_file *imgtool_chd_open(const char *filename, const char *mode);
117static void imgtool_chd_close(chd_interface_file *file);
118static UINT32 imgtool_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer);
119static UINT32 imgtool_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer);
120static UINT64 imgtool_chd_length(chd_interface_file *file);
121
122static chd_interface imgtool_chd_interface =
123{
124   imgtool_chd_open,
125   imgtool_chd_close,
126   imgtool_chd_read,
127   imgtool_chd_write,
128   imgtool_chd_length
129};
130
131/*
132   MAME hard disk core interface
133*/
134
135/*
136   imgtool_chd_open - interface for opening a hard disk image
137*/
138static chd_interface_file *imgtool_chd_open(const char *filename, const char *mode)
139{
140   imgtool_stream *img = decode_image_ref(filename);
141
142   /* invalid "file name"? */
143   if (img == NULL)
144      return NULL;
145
146   /* read-only fp? */
147   if ((stream_isreadonly(img)) && ! (mode[0] == 'r' && !strchr(mode, '+')))
148      return NULL;
149
150   /* otherwise return file pointer */
151   return (chd_interface_file *) img;
152}
153
154/*
155   imgtool_chd_close - interface for closing a hard disk image
156*/
157static void imgtool_chd_close(chd_interface_file *file)
158{
159}
160
161/*
162   imgtool_chd_read - interface for reading from a hard disk image
163*/
164static UINT32 imgtool_chd_read(chd_interface_file *file, UINT64 offset, UINT32 count, void *buffer)
165{
166   stream_seek((imgtool_stream *)file, offset, SEEK_SET);
167   return stream_read((imgtool_stream *)file, buffer, count);
168}
169
170/*
171   imgtool_chd_write - interface for writing to a hard disk image
172*/
173static UINT32 imgtool_chd_write(chd_interface_file *file, UINT64 offset, UINT32 count, const void *buffer)
174{
175   stream_seek((imgtool_stream *)file, offset, SEEK_SET);
176   return stream_write((imgtool_stream *)file, buffer, count);
177}
178
179/*
180   imgtool_chd_write - interface for determining the length of a hard disk image
181*/
182static UINT64 imgtool_chd_length(chd_interface_file *file)
183{
184   return stream_size((imgtool_stream *)file);
185}
186
187
188/*
18945   imghd_create()
19046
19147   Create a MAME HD image
r936r937
19349imgtoolerr_t imghd_create(imgtool_stream *stream, UINT32 hunksize, UINT32 cylinders, UINT32 heads, UINT32 sectors, UINT32 seclen)
19450{
19551   imgtoolerr_t err = IMGTOOLERR_SUCCESS;
196   char encoded_image_ref[encoded_image_ref_max_len];
197   chd_interface interface_save;
19852   UINT8 *cache = NULL;
19953   chd_file *chd = NULL;
20054   int rc;
r936r937
20256   int hunknum, totalhunks;
20357   char metadata[256];
20458
205   /* jump through the hoops as required by the CHD system */
206   encode_image_ref(stream, encoded_image_ref);
207   chd_save_interface(&interface_save);
208   chd_set_interface(&imgtool_chd_interface);
209
21059   /* sanity check args */
21160   if (hunksize >= 2048)
21261   {
r936r937
22776   logicalbytes = (UINT64)cylinders * heads * sectors * seclen;
22877
22978   /* create the new hard drive */
230   rc = chd_create(encoded_image_ref, logicalbytes, hunksize, CHDCOMPRESSION_NONE, NULL);
79   rc = chd_create_file(stream_core_file(stream), logicalbytes, hunksize, CHDCOMPRESSION_NONE, NULL);
23180   if (rc != CHDERR_NONE)
23281   {
23382      err = map_chd_error(rc);
r936r937
23584   }
23685
23786   /* open the new hard drive */
238   rc = chd_open(encoded_image_ref, CHD_OPEN_READWRITE, NULL, &chd);
87   rc = chd_open_file(stream_core_file(stream), CHD_OPEN_READWRITE, NULL, &chd);
23988   if (rc != CHDERR_NONE)
24089   {
24190      err = map_chd_error(rc);
r936r937
278127      free(cache);
279128   if (chd)
280129      chd_close(chd);
281   chd_set_interface(&interface_save);
282130   return err;
283131}
284132
r936r937
293141{
294142   chd_error chderr;
295143   imgtoolerr_t err = IMGTOOLERR_SUCCESS;
296   char encoded_image_ref[encoded_image_ref_max_len];
297   chd_interface interface_save;
298144
299145   hard_disk->hard_disk = NULL;
300146   hard_disk->chd = NULL;
301   encode_image_ref(stream, encoded_image_ref);
302147
303   /* use our CHD interface */
304   chd_save_interface(&interface_save);
305   chd_set_interface(&imgtool_chd_interface);
306
307   chderr = chd_open(encoded_image_ref, stream_isreadonly(stream) ? CHD_OPEN_READ : CHD_OPEN_READWRITE, NULL, &hard_disk->chd);
148   chderr = chd_open_file(stream_core_file(stream), stream_isreadonly(stream) ? CHD_OPEN_READ : CHD_OPEN_READWRITE, NULL, &hard_disk->chd);
308149   if (chderr)
309150   {
310151      err = map_chd_error(chderr);
r936r937
322163done:
323164   if (err)
324165      imghd_close(hard_disk);
325   chd_set_interface(&interface_save);
326166   return err;
327167}
328168
r936r937
335175*/
336176void imghd_close(struct mess_hard_disk_file *disk)
337177{
338   chd_interface interface_save;
339
340   chd_save_interface(&interface_save);
341   chd_set_interface(&imgtool_chd_interface);
342
343178   if (disk->hard_disk)
344179   {
345180      hard_disk_close(disk->hard_disk);
r936r937
352187   }
353188   if (disk->stream)
354189      stream_close(disk->stream);
355
356   chd_set_interface(&interface_save);
357190}
358191
359192
r936r937
365198*/
366199imgtoolerr_t imghd_read(struct mess_hard_disk_file *disk, UINT32 lbasector, void *buffer)
367200{
368   chd_interface interface_save;
369201   UINT32 reply;
370
371   chd_save_interface(&interface_save);
372   chd_set_interface(&imgtool_chd_interface);
373202   reply = hard_disk_read(disk->hard_disk, lbasector, buffer);
374   chd_set_interface(&interface_save);
375
376203   return reply ? IMGTOOLERR_SUCCESS : map_chd_error(reply);
377204}
378205
r936r937
385212*/
386213imgtoolerr_t imghd_write(struct mess_hard_disk_file *disk, UINT32 lbasector, const void *buffer)
387214{
388   chd_interface interface_save;
389215   UINT32 reply;
390
391   chd_save_interface(&interface_save);
392   chd_set_interface(&imgtool_chd_interface);
393216   reply = hard_disk_write(disk->hard_disk, lbasector, buffer);
394   chd_set_interface(&interface_save);
395
396217   return reply ? IMGTOOLERR_SUCCESS : map_chd_error(reply);
397218}
398219
r936r937
405226*/
406227const hard_disk_info *imghd_get_header(struct mess_hard_disk_file *disk)
407228{
408   chd_interface interface_save;
409229   const hard_disk_info *reply;
410
411   chd_save_interface(&interface_save);
412   chd_set_interface(&imgtool_chd_interface);
413230   reply = hard_disk_get_info(disk->hard_disk);
414   chd_set_interface(&interface_save);
415
416231   return reply;
417232}
418233
src/mess/image.c
r936r937
4040   char *err_message;
4141
4242   /* variables that are only non-zero when an image is mounted */
43   osd_file *file;
43   core_file *file;
4444   char *name;
4545   char *dir;
4646   char *hash;
47   UINT64 length;
48   UINT64 pos;
4947   char *basename_noext;
5048   
5149   /* flags */
r936r937
401399         {
402400            /* success! */
403401            err = IMAGE_ERROR_SUCCESS;
404            image->ptr = ptr;
405            image->length = header->uncompressed_length;
402            core_fopen_ram(ptr, header->uncompressed_length, OPEN_FLAG_READ, &image->file);
406403         }
407404      }
408405   }
r936r937
441438   file_extension = strrchr(path, '.');
442439   if (!file_extension || mame_stricmp(file_extension, ".zip"))
443440   {
444      filerr = osd_open(path, open_flags, &image->file, &image->length);
441      filerr = core_fopen(path, open_flags, &image->file);
445442
446443      /* did the open succeed? */
447444      switch(filerr)
r936r937
614611      }
615612
616613      /* verify the file */
617      err = image->dev->imgverify(buffer, (size_t) image->length);
614      err = image->dev->imgverify(buffer, core_fsize(image->file));
618615      if (err)
619616      {
620617         image->err = IMAGE_ERROR_INVALIDIMAGE;
r936r937
689686{
690687   if (image->file)
691688   {
692      osd_close(image->file);
689      core_fclose(image->file);
693690      image->file = NULL;
694691   }
695692
r936r937
699696   image->name = NULL;
700697   image->dir = NULL;
701698   image->hash = NULL;
702   image->length = 0;
703   image->pos = 0;
704699   image->longname = NULL;
705700   image->manufacturer = NULL;
706701   image->year = NULL;
r936r937
10891084
10901085
10911086/*-------------------------------------------------
1087    image_core_file
1088-------------------------------------------------*/
1089
1090core_file *image_core_file(mess_image *image)
1091{
1092   return image->file;
1093}
1094
1095
1096
1097/*-------------------------------------------------
10921098    image_typename_id
10931099-------------------------------------------------*/
10941100
r936r937
11091115    image_length
11101116-------------------------------------------------*/
11111117
1112UINT64 image_length(mess_image *img)
1118UINT64 image_length(mess_image *image)
11131119{
1114   return img->length;
1120   return core_fsize(image->file);
11151121}
11161122
11171123
r936r937
11851191
11861192UINT32 image_fread(mess_image *image, void *buffer, UINT32 length)
11871193{
1188   length = MIN(length, image->length - image->pos);
1189
1190   if (image->file)
1191      osd_read(image->file, buffer, image->pos, length, &length);
1192   else if (image->ptr)
1193      memcpy(buffer, ((UINT8 *) image->ptr) + image->pos, length);
1194   else
1195      length = 0;
1196
1197   image->pos += length;
1198   return length;
1194   return core_fread(image->file, buffer, length);
11991195}
12001196
12011197
r936r937
12061202
12071203UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length)
12081204{
1209   /* if we are not associated with a file, clip the length */
1210   if (!image->file)
1211      length = MIN(length, image->length - image->pos);
1212
1213   if (image->file)
1214   {
1215      osd_write(image->file, buffer, image->pos, length, &length);
1216
1217      /* since we've written to the file, we may need to invalidate the pointer */
1218      if (image->ptr)
1219      {
1220         image_freeptr(image, image->ptr);
1221         image->ptr = NULL;
1222      }
1223   }
1224   else if (image->ptr)
1225   {
1226      memcpy(((UINT8 *) image->ptr) + image->pos, buffer, length);
1227   }
1228   else
1229      length = 0;
1230
1231   image->pos += length;
1232
1233   /* did we grow the file? */
1234   if (image->length < image->pos)
1235      image->length = image->pos;
1236
1237   /* return */
1238   return length;
1205   return core_fwrite(image->file, buffer, length);
12391206}
12401207
12411208
r936r937
12461213
12471214int image_fseek(mess_image *image, INT64 offset, int whence)
12481215{
1249   switch(whence)
1250   {
1251      case SEEK_SET:
1252         image->pos = offset;
1253         break;
1254      case SEEK_CUR:
1255         image->pos += offset;
1256         break;
1257      case SEEK_END:
1258         image->pos = image->length + offset;
1259         break;
1260   }
1261   if (image->pos > image->length)
1262      image->pos = image->length;
1263   return 0;
1216   return core_fseek(image->file, offset, whence);
12641217}
12651218
12661219
r936r937
12711224
12721225UINT64 image_ftell(mess_image *image)
12731226{
1274   return image->pos;
1227   return core_ftell(image->file);
12751228}
12761229
12771230
r936r937
12961249
12971250int image_feof(mess_image *image)
12981251{
1299   return image->pos >= image->length;
1252   return core_feof(image->file);
13001253}
13011254
13021255
r936r937
13071260
13081261void *image_ptr(mess_image *image)
13091262{
1310   UINT64 size;
1311   UINT64 pos;
1312   void *ptr;
1313
1314   if (!image->ptr)
1315   {
1316      /* get the image size; bomb out if too big */
1317      size = image_length(image);
1318      if (size != (UINT32) size)
1319         return NULL;
1320
1321      /* allocate the memory */
1322      ptr = image_malloc(image, (UINT32) size);
1323
1324      /* save current position */
1325      pos = image_ftell(image);
1326
1327      /* read all data */
1328      image_fseek(image, 0, SEEK_SET);
1329      if (image_fread(image, ptr, (UINT32) size) != size)
1330         return NULL;
1331
1332      /* reset position */
1333      image_fseek(image, pos, SEEK_SET);
1334
1335      /* success */
1336      image->ptr = ptr;
1337   }
1338   return image->ptr;
1263   return (void *) core_fbuffer(image->file);
13391264}
13401265
13411266
src/mess/video/vic6560.c
r936r937
165165   white = Machine->pens[1];
166166   pointerelement = allocgfx(&pointerlayout);
167167   decodegfx(pointerelement, pointermask, 0, 1);
168   pointerelement->colortable = pointercolortable;
168   /* 7-Sep-2007 - After 0.118u5, you cannot revector the color table */
169   /* pointerelement->colortable = pointercolortable; */
169170   pointercolortable[1] = Machine->pens[1];
170171   pointercolortable[2] = Machine->pens[0];
171172   pointerelement->total_colors = 3;
src/mess/video/gb.c
r936r937
12901290}
12911291
12921292WRITE8_HANDLER ( gbc_video_w ) {
1293   static const UINT16 gbc_to_gb_pal[4] = {32767, 21140, 10570, 0};
1293   /* static const UINT16 gbc_to_gb_pal[4] = {32767, 21140, 10570, 0}; */
12941294   static UINT16 BP = 0, OP = 0;
12951295
12961296   switch( offset ) {
r936r937
13191319      /* Some GBC games are lazy and still call this */
13201320      if( gbc_mode == GBC_MODE_MONO ) {
13211321         update_scanline();
1322         Machine->remapped_colortable[0] = gbc_to_gb_pal[(data & 0x03)];
1323         Machine->remapped_colortable[1] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1324         Machine->remapped_colortable[2] = gbc_to_gb_pal[(data & 0x30) >> 4];
1325         Machine->remapped_colortable[3] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1322         /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1323         /*
1324            Machine->remapped_colortable[0] = gbc_to_gb_pal[(data & 0x03)];
1325            Machine->remapped_colortable[1] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1326            Machine->remapped_colortable[2] = gbc_to_gb_pal[(data & 0x30) >> 4];
1327            Machine->remapped_colortable[3] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1328         */
13261329      }
13271330      break;
13281331   case 0x08:      /* OBP0 - GB Object 0 palette */
13291332      if( gbc_mode == GBC_MODE_MONO ) /* Some GBC games are lazy and still call this */
13301333      {
1331         Machine->remapped_colortable[4] = gbc_to_gb_pal[(data & 0x03)];
1332         Machine->remapped_colortable[5] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1333         Machine->remapped_colortable[6] = gbc_to_gb_pal[(data & 0x30) >> 4];
1334         Machine->remapped_colortable[7] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1334         /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1335         /*
1336            Machine->remapped_colortable[4] = gbc_to_gb_pal[(data & 0x03)];
1337            Machine->remapped_colortable[5] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1338            Machine->remapped_colortable[6] = gbc_to_gb_pal[(data & 0x30) >> 4];
1339            Machine->remapped_colortable[7] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1340         */
13351341      }
13361342      break;
13371343   case 0x09:      /* OBP1 - GB Object 1 palette */
13381344      if( gbc_mode == GBC_MODE_MONO ) /* Some GBC games are lazy and still call this */
13391345      {
1340         Machine->remapped_colortable[8] = gbc_to_gb_pal[(data & 0x03)];
1341         Machine->remapped_colortable[9] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1342         Machine->remapped_colortable[10] = gbc_to_gb_pal[(data & 0x30) >> 4];
1343         Machine->remapped_colortable[11] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1346         /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1347         /*
1348            Machine->remapped_colortable[8] = gbc_to_gb_pal[(data & 0x03)];
1349            Machine->remapped_colortable[9] = gbc_to_gb_pal[(data & 0x0C) >> 2];
1350            Machine->remapped_colortable[10] = gbc_to_gb_pal[(data & 0x30) >> 4];
1351            Machine->remapped_colortable[11] = gbc_to_gb_pal[(data & 0xC0) >> 6];
1352         */
13441353      }
13451354      break;
13461355   case 0x11:      /* HDMA1 - HBL General DMA - Source High */
r936r937
13811390      break;
13821391   case 0x29:      /* BCPD - background palette data */
13831392      if( GBCBCPS & 0x1 )
1384         Machine->remapped_colortable[(GBCBCPS & 0x3e) >> 1] = ((UINT16)(data & 0x7f) << 8) | BP;
1393      {
1394         /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1395         /* Machine->remapped_colortable[(GBCBCPS & 0x3e) >> 1] = ((UINT16)(data & 0x7f) << 8) | BP; */
1396      }
13851397      else
13861398         BP = data;
13871399      if( GBCBCPS & 0x80 )
r936r937
13941406      break;
13951407   case 0x2B:      /* OCPD - Object palette data */
13961408      if( GBCOCPS & 0x1 )
1397         Machine->remapped_colortable[GBC_PAL_OBJ_OFFSET + ((GBCOCPS & 0x3e) >> 1)] = ((UINT16)(data & 0x7f) << 8) | OP;
1409      {
1410         /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1411         /* Machine->remapped_colortable[GBC_PAL_OBJ_OFFSET + ((GBCOCPS & 0x3e) >> 1)] = ((UINT16)(data & 0x7f) << 8) | OP; */
1412      }
13981413      else
13991414         OP = data;
14001415      if( GBCOCPS & 0x80 )
src/mess/video/arcadia.c
r936r937
634634INLINE void arcadia_draw_char(mame_bitmap *bitmap, UINT8 *ch, int color,
635635               int y, int x)
636636{
637   /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
638    * the color table, a vile gross hack.  Doesn't look like this is going
639    * to survive the 0.118u5 transition */
637640    int k,b;
638641    if (arcadia_video.multicolor) {
639642   int c;
640643   if (color&0x40) c=arcadia_video.reg.d.pal[1];
641644   else c=arcadia_video.reg.d.pal[0];
642   Machine->gfx[0]->colortable[1]=Machine->pens[(c>>3)&7];
645   /*Machine->gfx[0]->colortable[1]=Machine->pens[(c>>3)&7];*/
643646
644647   if (color&0x80) c=arcadia_video.reg.d.pal[1];
645648   else c=arcadia_video.reg.d.pal[0];
646   Machine->gfx[0]->colortable[0]=Machine->pens[c&7];
649   /*Machine->gfx[0]->colortable[0]=Machine->pens[c&7];*/
647650
648651    } else {
649   Machine->gfx[0]->colortable[1]=
650       Machine->pens[((arcadia_video.reg.d.pal[1]>>3)&1)|((color>>5)&6)];
652   /*Machine->gfx[0]->colortable[1]=
653       Machine->pens[((arcadia_video.reg.d.pal[1]>>3)&1)|((color>>5)&6)];*/
651654    }
652655
653656    if (arcadia_video.doublescan) {
r936r937
688691    h=arcadia_video.doublescan?16:8;
689692
690693    if (bitmap->height-arcadia_video.line<h) h=bitmap->height-arcadia_video.line;
691    plot_box(bitmap, 0, y, bitmap->width, h, Machine->gfx[0]->colortable[0]);
694    plot_box(bitmap, 0, y, bitmap->width, h, Machine->remapped_colortable[Machine->gfx[0]->color_base + 0]);
692695    memset(arcadia_video.bg[y], 0, sizeof(arcadia_video.bg[0])*h);
693696    for (x=XPOS+arcadia_video.shift, j=0; j<16;j++,x+=8) {
694697   ch=chars1[j];
r936r937
742745   if (arcadia_video.pos[i].x<=-XPOS) continue;
743746   if (arcadia_video.pos[i].x>=128+XPOS-8) continue;
744747
748   /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
749    * the color table, a vile gross hack.  Doesn't look like this is going
750    * to survive the 0.118u5 transition */
745751   switch (i) {
746752   case 0:
747       Machine->gfx[0]->colortable[1]=Machine->pens[(arcadia_video.reg.d.pal[3]>>3)&7];
753       /*Machine->gfx[0]->colortable[1]=Machine->pens[(arcadia_video.reg.d.pal[3]>>3)&7];*/
748754       doublescan=arcadia_video.reg.d.pal[3]&0x80?FALSE:TRUE;
749755       break;
750756   case 1:
751       Machine->gfx[0]->colortable[1]=Machine->pens[arcadia_video.reg.d.pal[3]&7];
757       /*Machine->gfx[0]->colortable[1]=Machine->pens[arcadia_video.reg.d.pal[3]&7];*/
752758       doublescan=arcadia_video.reg.d.pal[3]&0x40?FALSE:TRUE;
753759       break;
754760   case 2:
755       Machine->gfx[0]->colortable[1]=Machine->pens[(arcadia_video.reg.d.pal[2]>>3)&7];
761       /*Machine->gfx[0]->colortable[1]=Machine->pens[(arcadia_video.reg.d.pal[2]>>3)&7];*/
756762       doublescan=arcadia_video.reg.d.pal[2]&0x80?FALSE:TRUE;
757763       break;
758764   case 3:
759       Machine->gfx[0]->colortable[1]=Machine->pens[arcadia_video.reg.d.pal[2]&7];
765       /*Machine->gfx[0]->colortable[1]=Machine->pens[arcadia_video.reg.d.pal[2]&7];*/
760766       doublescan=arcadia_video.reg.d.pal[2]&0x40?FALSE:TRUE;
761767       break;
762768   }
r936r937
803809   // unbelievable, reflects only charline, but alien invaders uses it for
804810   // alien scrolling
805811
806   Machine->gfx[0]->colortable[0]=Machine->pens[arcadia_video.reg.d.pal[1]&7];
812   /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
813    * the color table, a vile gross hack.  Doesn't look like this is going
814    * to survive the 0.118u5 transition */
815   /*Machine->gfx[0]->colortable[0]=Machine->pens[arcadia_video.reg.d.pal[1]&7];*/
807816
808817   if (arcadia_video.line<arcadia_video.ypos)
809818   {
810      plot_box(arcadia_video.bitmap, 0, arcadia_video.line, Machine->screen[0].width, 1, Machine->gfx[0]->colortable[0]);
819      plot_box(arcadia_video.bitmap, 0, arcadia_video.line, Machine->screen[0].width, 1, Machine->remapped_colortable[Machine->gfx[0]->color_base + 0]);
811820      memset(arcadia_video.bg[arcadia_video.line], 0, sizeof(arcadia_video.bg[0]));
812821   }
813822   else
r936r937
835844      else
836845      {
837846         arcadia_video.charline=0xd;
838         plot_box(arcadia_video.bitmap, 0, arcadia_video.line, Machine->screen[0].width, 1, Machine->gfx[0]->colortable[0]);
847         plot_box(arcadia_video.bitmap, 0, arcadia_video.line, Machine->screen[0].width, 1, Machine->remapped_colortable[Machine->gfx[0]->color_base + 0]);
839848         memset(arcadia_video.bg[arcadia_video.line], 0, sizeof(arcadia_video.bg[0]));
840849      }
841850   }
src/mess/video/x68k.c
r936r937
862862   /* create the char set (gfx will then be updated dynamically from RAM) */
863863   Machine->gfx[gfx_index] = allocgfx(&x68k_pcg_8);
864864   decodegfx(Machine->gfx[gfx_index] , memory_region(REGION_USER1), 0, 256);
865   Machine->gfx[gfx_index]->colortable = (Machine->remapped_colortable+0x100);
865   /* 7-Sep-2007 - After 0.118u5, you cannot change the colortable */
866   /* Machine->gfx[gfx_index]->colortable = (Machine->remapped_colortable+0x100); */
866867   Machine->gfx[gfx_index]->total_colors = 16;
867868
868869   gfx_index++;
869870
870871   Machine->gfx[gfx_index] = allocgfx(&x68k_pcg_16);
871872   decodegfx(Machine->gfx[gfx_index] , memory_region(REGION_USER1), 0, 256);
872   Machine->gfx[gfx_index]->colortable = (Machine->remapped_colortable+0x100);
873   /* 7-Sep-2007 - After 0.118u5, you cannot change the colortable */
874   /* Machine->gfx[gfx_index]->colortable = (Machine->remapped_colortable+0x100); */
873875   Machine->gfx[gfx_index]->total_colors = 16;
874876
875877   /* Tilemaps */
src/mess/video/pc_t1t.c
r936r937
510510
511511   if (height > 8)
512512   {
513      bgcolor = gfx->colortable[gfx->color_granularity * (attr % gfx->total_colors)];
513      bgcolor = Machine->remapped_colortable[gfx->color_base + gfx->color_granularity * (attr % gfx->total_colors)];
514514      plot_box(bitmap, r->min_x, r->min_y + 8, width, height - 8, bgcolor);
515515   }
516516}
src/mess/video/avigo.c
r936r937
131131    avigo_video_memory = auto_malloc(((AVIGO_SCREEN_WIDTH>>3)*AVIGO_SCREEN_HEIGHT));
132132   Machine->gfx[0] = stylus_pointer = allocgfx(&pointerlayout);
133133   decodegfx(stylus_pointer, pointermask, 0, 1);
134   stylus_pointer->colortable = stylus_color_table;
134   /* 7-Sep-2007 - After 0.118u5, you cannot revector the color table */
135   /*stylus_pointer->colortable = stylus_color_table;*/
135136   stylus_pointer->total_colors = 3;
136137   stylus_color_table[1] = Machine->pens[0];
137138   stylus_color_table[2] = Machine->pens[1];
src/mess/video/odyssey2.c
r936r937
423423    int offset = ptr | ((color & 1) << 8);
424424
425425    offset=(offset + (y >> 1)) & 0x1ff;
426    Machine->gfx[0]->colortable[1]=Machine->pens[16 + ((color & 0xe) >> 1)];
426   /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
427    * the color table, a vile gross hack.  Doesn't look like this is going
428    * to survive the 0.118u5 transition */
429   /* Machine->gfx[0]->colortable[1]=Machine->pens[16 + ((color & 0xe) >> 1)]; */
427430
428431    // don't ask me about the technical background, but also this height thingy is needed
429432    // invaders aliens (!) and shoot (-)
r936r937
485488
486489      for (i=0; i<ARRAY_LENGTH(o2_vdc.s.sprites); i++)
487490      {
488         Machine->gfx[0]->colortable[1]=Machine->pens[16+((o2_vdc.s.sprites[i].color>>3)&7)];
491         /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
492          * the color table, a vile gross hack.  Doesn't look like this is going
493          * to survive the 0.118u5 transition */
494         /* Machine->gfx[0]->colortable[1]=Machine->pens[16+((o2_vdc.s.sprites[i].color>>3)&7)]; */
489495
490496         y=o2_vdc.s.sprites[i].y;
491497         x=o2_vdc.s.sprites[i].x;
src/mess/video/ted7360.c
r936r937
950950{
951951   cursorelement = allocgfx(&cursorlayout);
952952   decodegfx(cursorelement, cursormask, 0, 1);
953   cursorelement->colortable = cursorcolortable;
953   /* 7-Sep-2007 - After 0.118u5, you cannot revector the color table */
954   /* cursorelement->colortable = cursorcolortable; */
954955   cursorcolortable[1] = Machine->pens[1];
955956   cursorelement->total_colors = 2;
956957   ted7360_bitmap = auto_bitmap_alloc(Machine->screen[0].width, Machine->screen[0].height, BITMAP_FORMAT_INDEXED16);
src/mess/video/vc4000.c
r936r937
433433   {
434434      vc4000_draw_grid(collision);
435435
436      Machine->gfx[0]->colortable[1]=Machine->pens[8|((vc4000_video.reg.d.sprite_colors[0]>>3)&7)];
436      /* 7-Sep-2007 - whomever wrote this crap code was dynamically remapping
437       * the color table, a vile gross hack.  Doesn't look like this is going
438       * to survive the 0.118u5 transition */
439      /* Machine->gfx[0]->colortable[1]=Machine->pens[8|((vc4000_video.reg.d.sprite_colors[0]>>3)&7)]; */
437440      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[0]);
438      Machine->gfx[0]->colortable[1]=Machine->pens[8|(vc4000_video.reg.d.sprite_colors[0]&7)];
441      /* Machine->gfx[0]->colortable[1]=Machine->pens[8|(vc4000_video.reg.d.sprite_colors[0]&7)]; */
439442      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[1]);
440      Machine->gfx[0]->colortable[1]=Machine->pens[8|((vc4000_video.reg.d.sprite_colors[1]>>3)&7)];
443      /* Machine->gfx[0]->colortable[1]=Machine->pens[8|((vc4000_video.reg.d.sprite_colors[1]>>3)&7)]; */
441444      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[2]);
442      Machine->gfx[0]->colortable[1]=Machine->pens[8|(vc4000_video.reg.d.sprite_colors[1]&7)];
445      /* Machine->gfx[0]->colortable[1]=Machine->pens[8|(vc4000_video.reg.d.sprite_colors[1]&7)]; */
443446      vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[3]);
444447
445448      for (i=0; i<256; i++)
src/mess/image.h
r936r937
105105int image_exists(mess_image *image);
106106int image_slotexists(mess_image *image);
107107
108core_file *image_core_file(mess_image *image);
108109const char *image_typename_id(mess_image *image);
109110const char *image_filename(mess_image *image);
110111const char *image_basename(mess_image *image);
src/mess/machine/gb.c
r936r937
796796               }
797797               if (sgb_bytecount == (sgb_packets << 4) )
798798               {
799                  /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
799800                  switch( sgb_data[0] >> 3 )
800801                  {
801802                     case 0x00:   /* PAL01 */
803                        /*
802804                        Machine->remapped_colortable[0*4 + 0] = sgb_data[1] | (sgb_data[2] << 8);
803805                        Machine->remapped_colortable[0*4 + 1] = sgb_data[3] | (sgb_data[4] << 8);
804806                        Machine->remapped_colortable[0*4 + 2] = sgb_data[5] | (sgb_data[6] << 8);
r936r937
807809                        Machine->remapped_colortable[1*4 + 1] = sgb_data[9] | (sgb_data[10] << 8);
808810                        Machine->remapped_colortable[1*4 + 2] = sgb_data[11] | (sgb_data[12] << 8);
809811                        Machine->remapped_colortable[1*4 + 3] = sgb_data[13] | (sgb_data[14] << 8);
812                        */
810813                        break;
811814                     case 0x01:   /* PAL23 */
815                        /*
812816                        Machine->remapped_colortable[2*4 + 0] = sgb_data[1] | (sgb_data[2] << 8);
813817                        Machine->remapped_colortable[2*4 + 1] = sgb_data[3] | (sgb_data[4] << 8);
814818                        Machine->remapped_colortable[2*4 + 2] = sgb_data[5] | (sgb_data[6] << 8);
r936r937
817821                        Machine->remapped_colortable[3*4 + 1] = sgb_data[9] | (sgb_data[10] << 8);
818822                        Machine->remapped_colortable[3*4 + 2] = sgb_data[11] | (sgb_data[12] << 8);
819823                        Machine->remapped_colortable[3*4 + 3] = sgb_data[13] | (sgb_data[14] << 8);
824                        */
820825                        break;
821826                     case 0x02:   /* PAL03 */
827                        /*
822828                        Machine->remapped_colortable[0*4 + 0] = sgb_data[1] | (sgb_data[2] << 8);
823829                        Machine->remapped_colortable[0*4 + 1] = sgb_data[3] | (sgb_data[4] << 8);
824830                        Machine->remapped_colortable[0*4 + 2] = sgb_data[5] | (sgb_data[6] << 8);
r936r937
827833                        Machine->remapped_colortable[3*4 + 1] = sgb_data[9] | (sgb_data[10] << 8);
828834                        Machine->remapped_colortable[3*4 + 2] = sgb_data[11] | (sgb_data[12] << 8);
829835                        Machine->remapped_colortable[3*4 + 3] = sgb_data[13] | (sgb_data[14] << 8);
836                        */
830837                        break;
831838                     case 0x03:   /* PAL12 */
839                        /*
832840                        Machine->remapped_colortable[1*4 + 0] = sgb_data[1] | (sgb_data[2] << 8);
833841                        Machine->remapped_colortable[1*4 + 1] = sgb_data[3] | (sgb_data[4] << 8);
834842                        Machine->remapped_colortable[1*4 + 2] = sgb_data[5] | (sgb_data[6] << 8);
r936r937
837845                        Machine->remapped_colortable[2*4 + 1] = sgb_data[9] | (sgb_data[10] << 8);
838846                        Machine->remapped_colortable[2*4 + 2] = sgb_data[11] | (sgb_data[12] << 8);
839847                        Machine->remapped_colortable[2*4 + 3] = sgb_data[13] | (sgb_data[14] << 8);
848                        */
840849                        break;
841850                     case 0x04:   /* ATTR_BLK */
842851                        {
r936r937
10351044                     case 0x0A:   /* PAL_SET */
10361045                        {
10371046                           UINT16 index_, J, I;
1047                           /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
10381048
10391049                           /* Palette 0 */
10401050                           index_ = (UINT16)(sgb_data[1] | (sgb_data[2] << 8)) * 4;
1041                           Machine->remapped_colortable[0] = sgb_pal_data[index_];
1042                           Machine->remapped_colortable[1] = sgb_pal_data[index_ + 1];
1043                           Machine->remapped_colortable[2] = sgb_pal_data[index_ + 2];
1044                           Machine->remapped_colortable[3] = sgb_pal_data[index_ + 3];
1051                           /*
1052                              Machine->remapped_colortable[0] = sgb_pal_data[index_];
1053                              Machine->remapped_colortable[1] = sgb_pal_data[index_ + 1];
1054                              Machine->remapped_colortable[2] = sgb_pal_data[index_ + 2];
1055                              Machine->remapped_colortable[3] = sgb_pal_data[index_ + 3];
1056                           */
10451057                           /* Palette 1 */
10461058                           index_ = (UINT16)(sgb_data[3] | (sgb_data[4] << 8)) * 4;
1047                           Machine->remapped_colortable[4] = sgb_pal_data[index_];
1048                           Machine->remapped_colortable[5] = sgb_pal_data[index_ + 1];
1049                           Machine->remapped_colortable[6] = sgb_pal_data[index_ + 2];
1050                           Machine->remapped_colortable[7] = sgb_pal_data[index_ + 3];
1059                           /*
1060                              Machine->remapped_colortable[4] = sgb_pal_data[index_];
1061                              Machine->remapped_colortable[5] = sgb_pal_data[index_ + 1];
1062                              Machine->remapped_colortable[6] = sgb_pal_data[index_ + 2];
1063                              Machine->remapped_colortable[7] = sgb_pal_data[index_ + 3];
1064                           */
10511065                           /* Palette 2 */
10521066                           index_ = (UINT16)(sgb_data[5] | (sgb_data[6] << 8)) * 4;
1053                           Machine->remapped_colortable[8] = sgb_pal_data[index_];
1054                           Machine->remapped_colortable[9] = sgb_pal_data[index_ + 1];
1055                           Machine->remapped_colortable[10] = sgb_pal_data[index_ + 2];
1056                           Machine->remapped_colortable[11] = sgb_pal_data[index_ + 3];
1067                           /*
1068                              Machine->remapped_colortable[8] = sgb_pal_data[index_];
1069                              Machine->remapped_colortable[9] = sgb_pal_data[index_ + 1];
1070                              Machine->remapped_colortable[10] = sgb_pal_data[index_ + 2];
1071                              Machine->remapped_colortable[11] = sgb_pal_data[index_ + 3];
1072                           */
10571073                           /* Palette 3 */
10581074                           index_ = (UINT16)(sgb_data[7] | (sgb_data[8] << 8)) * 4;
1059                           Machine->remapped_colortable[12] = sgb_pal_data[index_];
1060                           Machine->remapped_colortable[13] = sgb_pal_data[index_ + 1];
1061                           Machine->remapped_colortable[14] = sgb_pal_data[index_ + 2];
1062                           Machine->remapped_colortable[15] = sgb_pal_data[index_ + 3];
1075                           /*
1076                              Machine->remapped_colortable[12] = sgb_pal_data[index_];
1077                              Machine->remapped_colortable[13] = sgb_pal_data[index_ + 1];
1078                              Machine->remapped_colortable[14] = sgb_pal_data[index_ + 2];
1079                              Machine->remapped_colortable[15] = sgb_pal_data[index_ + 3];
1080                           */
10631081                           /* Attribute File */
10641082                           if( sgb_data[9] & 0x40 )
10651083                              sgb_window_mask = 0;
r936r937
11321150                              {
11331151                                 col = program_read_byte_8 (0x8800 + (I*2));
11341152                                 col |= (UINT16)(program_read_byte_8 (0x8800 + (I*2) + 1)) << 8;
1135                                 Machine->remapped_colortable[SGB_BORDER_PAL_OFFSET + I] = col;
1153                                 /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1154                                 /* Machine->remapped_colortable[SGB_BORDER_PAL_OFFSET + I] = col; */
11361155                              }
11371156                           }
11381157                           else /* Do things normally */
r936r937
11421161                              {
11431162                                 col = program_read_byte_8 (0x9000 + (I*2));
11441163                                 col |= (UINT16)(program_read_byte_8 (0x9000 + (I*2) + 1)) << 8;
1145                                 Machine->remapped_colortable[SGB_BORDER_PAL_OFFSET + I] = col;
1164                                 /* 7-Sep-2007 - After 0.118u5, you cannot change remapped_colortable */
1165                                 /* Machine->remapped_colortable[SGB_BORDER_PAL_OFFSET + I] = col; */
11461166                              }
11471167                           }
11481168                        }
src/mess/mess.mak
r936r937
177177#CPUS += M37702
178178#CPUS += M37710
179179#CPUS += PPC403
180#CPUS += PPC601
180181#CPUS += PPC602
181182CPUS += PPC603
182183#CPUS += MPC8240
docs/messnew.txt
r936r937
6060
6161Source Changes:
6262----------------
63- The core is based on MAME 0.118u4.  This incorporates all features of the
63- The core is based on MAME 0.118u5.  This incorporates all features of the
6464  update to this core.  [MAME team]
6565
6666

Previous 15994 Revisions Next


© 1998-2018 The MESS Team