Previous 15994 Revisions Next

r1216 Friday 2nd November, 2007 at 11:20:02 UTC by Nathan Woods
Updated to MAME 0.120u2 core
[docs]messnew.txt
[src/emu]eigccppc.h* eigccx86.h* eminline.h* emu.mak mame.c mamecore.h profiler.c rendersw.c tilemap.c validity.c
[src/emu/cpu/m6800]m6800.c
[src/emu/cpu/tms32031]32031ops.c tms32031.c
[src/emu/machine]53c810.c 53c810.h 6850acia.c am53cf96.c am53cf96.h cr589.c* cr589.h* i2cmem.c* i2cmem.h* scsi.c* scsi.h* scsicd.c scsicd.h* scsidev.c* scsidev.h scsihd.c scsihd.h* wd33c93.c wd33c93.h
[src/emu/video]polynew.c rgbgen.h* rgbsse.h* rgbutil.h* vector.c vooddefs.h voodoo.c
[src/mame]mame.mak mamedriv.c tiny.mak
[src/mame/audio]cclimber.c galaxian.c
[src/mame/drivers]bfcobra.c bnstars.c cclimber.c cps2.c dambustr.c firebeat.c galaga.c galaxian.c hornet.c ksys573.c madalien.c meadows.c midzeus.c mpu4.c nwk-tr.c polyplay.c senjyo.c skykid.c srmp6.c suna8.c superqix.c wilytowr.c yamato.c zr107.c
[src/mame/includes]cclimber.h galaxian.h midzeus.h*
[src/mame/machine]cps2crpt.c cubocd32.c model1.c
[src/mame/video]gaelco3d.c midzeus.c* namcos22.c skykid.c stvvdp2.c
[src/mess/machine]ncr5380.c
[src/osd]osdcore.h
[src/osd/windows]osd_cpu.h osinline.h windows.mak

src/mame/audio/galaxian.c
r1215r1216
525525}
526526
527527
528struct Samplesinterface galaxian_custom_interface =
528struct Samplesinterface galaxian_samples_interface =
529529{
530530   5,
531531   NULL,
src/mame/audio/cclimber.c
r1215r1216
8383   0
8484};
8585
86struct Samplesinterface cclimber_custom_interface =
86struct Samplesinterface cclimber_samples_interface =
8787{
8888   1,
8989   NULL,
src/mame/machine/cubocd32.c
r1215r1216
33#include "cdrom.h"
44#include "coreutil.h"
55#include "sound/cdda.h"
6#include "machine/i2cmem.h"
67
78
89/*********************************************************************************
r1215r1216
1920*********************************************************************************/
2021
2122#define LOG_AKIKO      0
22#define LOG_AKIKO_I2C   0
2323#define LOG_AKIKO_CD   0
2424
2525#define CD_SECTOR_TIME      (1000/((150*1024)/2048))   /* 1X CDROM sector time in msec (300KBps) */
2626
2727
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
4128#define   NVRAM_SIZE 1024
4229#define   NVRAM_PAGE_SIZE   16   /* max size of one write request */
4330
r1215r1216
5037   UINT32   c2p_output_index;
5138
5239   /* i2c bus */
53   int      i2c_state;
54   int      i2c_bitcounter;
55   int      i2c_direction;
56   int      i2c_sda_dir_nvram;
5740   int      i2c_scl_out;
58   int      i2c_scl_in;
5941   int      i2c_scl_dir;
60   int      i2c_oscl;
6142   int      i2c_sda_out;
62   int      i2c_sda_in;
6343   int      i2c_sda_dir;
64   int      i2c_osda;
6544
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
7445   /* cdrom */
7546   UINT32   cdrom_status[2];
7647   UINT32   cdrom_address[2];
r1215r1216
9768
9869void amiga_akiko_init(void)
9970{
71   i2cmem_init( 0, I2CMEM_SLAVE_ADDRESS, NVRAM_PAGE_SIZE, NVRAM_SIZE, NULL );
72
10073   akiko.c2p_input_index = 0;
10174   akiko.c2p_output_index = 0;
10275
103   akiko.i2c_state = I2C_WAIT;
104   akiko.i2c_bitcounter = -1;
105   akiko.i2c_direction = -1;
106   akiko.i2c_sda_dir_nvram = 0;
10776   akiko.i2c_scl_out = 0;
108   akiko.i2c_scl_in = 0;
10977   akiko.i2c_scl_dir = 0;
110   akiko.i2c_oscl = 0;
11178   akiko.i2c_sda_out = 0;
112   akiko.i2c_sda_in = 0;
11379   akiko.i2c_sda_dir = 0;
114   akiko.i2c_osda = 0;
11580
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
12281   akiko.cdrom_status[0] = akiko.cdrom_status[1] = 0;
12382   akiko.cdrom_address[0] = akiko.cdrom_address[1] = 0;
12483   akiko.cdrom_track_index = 0;
r1215r1216
188147   }
189148}
190149
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
350150static void akiko_nvram_write(UINT32 data)
351151{
352   int      sda;
353
354   akiko.i2c_oscl = akiko.i2c_scl_out;
355152   akiko.i2c_scl_out = BIT(data,31);
356   akiko.i2c_osda = akiko.i2c_sda_out;
357153   akiko.i2c_sda_out = BIT(data,30);
358154   akiko.i2c_scl_dir = BIT(data,15);
359155   akiko.i2c_sda_dir = BIT(data,14);
360156
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    }
157   i2cmem_write( 0, I2CMEM_SCL, akiko.i2c_scl_out );
158   i2cmem_write( 0, I2CMEM_SDA, akiko.i2c_sda_out );
368159}
369160
370161static UINT32 akiko_nvram_read(void)
371162{
372163   UINT32   v = 0;
373164
374   if ( !akiko.i2c_scl_dir )
375       v |= akiko.i2c_scl_in ? (1<<31) : 0x00;
165   if ( akiko.i2c_scl_dir )
166   {
167      v |= akiko.i2c_scl_out << 31;
168   }
376169   else
377       v |= akiko.i2c_scl_out ? (1<<31) : 0x00;
170   {
171      v |= 0 << 31;
172   }
378173
379   if ( !akiko.i2c_sda_dir )
380       v |= akiko.i2c_sda_in ? (1<<30) : 0x00;
174   if ( akiko.i2c_sda_dir )
175   {
176      v |= akiko.i2c_sda_out << 30;
177   }
381178   else
382       v |= akiko.i2c_sda_out ? (1<<30) : 0x00;
179   {
180      v |= i2cmem_read( 0, I2CMEM_SDA ) << 30;
181   }
383182
384   v |= akiko.i2c_scl_dir ? (1<<15) : 0x00;
385   v |= akiko.i2c_sda_dir ? (1<<14) : 0x00;
183   v |= akiko.i2c_scl_dir << 15;
184   v |= akiko.i2c_sda_dir << 14;
386185
387    return v;
186   return v;
388187}
389188
390189NVRAM_HANDLER( cd32 )
391190{
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   }
191   nvram_handler_i2cmem_0( machine, file, read_or_write );
403192}
404193
405194/*************************************
src/mame/machine/cps2crpt.c
r1215r1216
769769   { "ddtodh",   { 0x19691019,0xe825dde0 }, 0x180000 },   // 0C78 1019 4000  cmpi.w  #$1019,$4000
770770   { "ecofghtr", { 0x931031dc,0xba987654 }, 0x200000 },   // 0838 0003 7345  btst    #3,$7345
771771   { "ecofghtu", { 0x931031ed,0xcba98765 }, 0x200000 },   // 0838 0003 7345  btst    #3,$7345
772   { "ecofgtu1", { 0x931031ed,0xcba98765 }, 0x200000 },   // 0838 0003 7345  btst    #3,$7345
772773   { "uecology", { 0x931031fe,0xdcba9876 }, 0x200000 },   // 0838 0003 7345  btst    #3,$7345
773774   { "ecofghta", { 0x931031ba,0x98765432 }, 0x200000 },   // 0838 0003 7345  btst    #3,$7345
774775   { "ssf2t",    { 0x944e8302,0x56d3143c }, 0x400000 },   // 0838 0007 2000  btst    #7,$2000
r1215r1216
834835   { "sfzh",     { 0x876b0e39,0x5ca24fd1 }, 0x080000 },   // 0C80 0564 2194  cmpi.l  #$05642194,D0
835836   { "sfzb",     { 0xef415bd3,0x7a92c680 }, 0x080000 },   // 0C80 0564 2194  cmpi.l  #$05642194,D0
836837   { "sfzbr1",   { 0xef415bd3,0x7a92c680 }, 0x080000 },   // 0C80 0564 2194  cmpi.l  #$05642194,D0
837   { "mmancp2u", { 0x054893fa,0x94642525 }, 0x100000 },    // 0C80 0564 2194  cmpi.l  #$05642194,D0
838   { "mmancp2u", { 0x054893fa,0x94642525 }, 0x100000 },   // 0C80 0564 2194  cmpi.l  #$05642194,D0
838839   { "rmancp2j", { 0x07215501,0x37fa32d0 }, 0x100000 },   // 0C80 0564 2194  cmpi.l  #$05642194,D0
839840   { "19xx",     { 0x0e07181f,0x5fd0f080 }, 0x200000 },   // 0C81 0095 1101  cmpi.l  #$00951101,D1
840841   { "19xxa",    { 0xcce74cf5,0xb7da3711 }, 0x200000 },   // 0C81 0095 1101  cmpi.l  #$00951101,D1
src/mame/machine/model1.c
r1215r1216
16151615}
16161616
16171617struct function {
1618   int nb;
16191618   void (*cb)(void);
16201619   int count;
16211620};
16221621
1623static struct function ftab_vf[] = {
1624   {   0, fadd,            2 },
1625   {   1, fsub,            2 },
1626   {   2, fmul,            2 },
1627   {   3, fdiv,            2 },
1628   {   5, matrix_push,     0 },
1629   {   6, matrix_pop,      0 },
1630   {   7, matrix_write,   12 },
1631   {   8, clear_stack,     0 },
1632   {  10, anglev,          2 },
1633   {  13, track_select,    1 },
1634   {  14, f14,   4 },
1635   {  15, anglep,          4 },
1636   {  16, matrix_ident,    0 },
1637   {  17, matrix_read,     0 },
1638   {  18, matrix_trans,    3 },
1639   {  19, matrix_scale,    3 },
1640   {  20, matrix_rotx,     1 },
1641   {  21, matrix_roty,     1 },
1642   {  22, matrix_rotz,     1 },
1643   {  24, track_read_quad, 1 },
1644   {  26, transform_point, 3 },
1645   {  27, fsin_m1,         1 },
1646   {  28, fcos_m1,         1 },
1647   {  29, fsinm_m1,        2 },
1648   {  30, fcosm_m1,        2 },
1649   {  31, distance3,       6 },
1650   {  36, acc_set,         1 },
1651   {  37, acc_get,         0 },
1652   {  38, acc_add,         1 },
1653   {  39, acc_sub,         1 },
1654   {  40, acc_mul,         1 },
1655   {  41, acc_div,         1 }, // not used ?
1656   {  42, f42,   3 },
1657   {  43, f43,   6 },
1658   {  44, f44,   1 },
1659   {  45, f45,   1 },
1660   {  46, vlength,         3 },
1661   {  48, track_read_info, 1 },
1662   {  49, colbox_set,     12 },
1663   {  50, colbox_test,     3 },
1664   {  54, track_lookup,    4 },
1665   {  64, col_setcirc,     3 },
1666   {  65, col_testpt,      2 },
1667   {  67, distance,        4 },
1668   {  71, car_move,        4 },
1669   {  72, cpa,            12 },
1670   {  74, vmat_store,      1 },
1671   {  75, vmat_restore,    1 },
1672   {  77, vmat_mul,        2 },
1673   {  78, vmat_read,       1 },
1674   {  79, matrix_unrot,    0 },
1675   {  80, f80,   0 },
1676   {  82, matrix_rtrans,   0 },
1677   {  84, vmat_save,       1 },
1678   {  85, vmat_load,       1 },
1679   {  86, ram_setadr,      1 },
1680   {  87, groundbox_test,  3 },
1681   {  89, f89,   4 },
1682   {  92, f92,   4 },
1683   {  93, f93,   1 },
1684   {  94, f94,   1 },
1685   {  95, vmat_flatten,    0 },
1686   {  96, vmat_load1,      1 },
1687   {  97, ram_trans,       0 },
1688   {  98, f98,   1 },
1689   {  99, f99,   0 },
1690   { 100, f100,  0 },
1691   { 101, groundbox_set,   7 },
1692   { 102, f102,  8 },
1693   { 103, f103,  1 },
1694   { 0, 0, 0 }
1622static const struct function ftab_vf[] = {
1623   { fadd,            2 }, /* 0x00 */
1624   { fsub,            2 },
1625   { fmul,            2 },
1626   { fdiv,            2 },
1627   { NULL,            0 },
1628   { matrix_push,     0 },
1629   { matrix_pop,      0 },
1630   { matrix_write,   12 },
1631   { clear_stack,     0 },
1632   { NULL,            0 },
1633   { anglev,          2 },
1634   { NULL,            0 },
1635   { NULL,            0 },
1636   { track_select,    1 },
1637   { f14,             4 },
1638   { anglep,          4 },
1639
1640   { matrix_ident,    0 },  /* 0x10 */
1641   { matrix_read,     0 },
1642   { matrix_trans,    3 },
1643   { matrix_scale,    3 },
1644   { matrix_rotx,     1 },
1645   { matrix_roty,     1 },
1646   { matrix_rotz,     1 },
1647   { NULL,            0 },
1648   { track_read_quad, 1 },
1649   { NULL,            0 },
1650   { transform_point, 3 },
1651   { fsin_m1,         1 },
1652   { fcos_m1,         1 },
1653   { fsinm_m1,        2 },
1654   { fcosm_m1,        2 },
1655   { distance3,       6 },
1656
1657   { NULL,            0 },  /* 0x20 */
1658   { NULL,            0 },
1659   { NULL,            0 },
1660   { NULL,            0 },
1661   { acc_set,         1 },
1662   { acc_get,         0 },
1663   { acc_add,         1 },
1664   { acc_sub,         1 },
1665   { acc_mul,         1 },
1666   { acc_div,         1 }, // not used ?
1667   { f42,             3 },
1668   { f43,             6 },
1669   { f44,             1 },
1670   { f45,             1 },
1671   { vlength,         3 },
1672   { NULL, 0 },
1673
1674   { track_read_info, 1 },  /* 0x30 */
1675   { colbox_set,     12 },
1676   { colbox_test,     3 },
1677   { NULL,            0 },
1678   { NULL,            0 },
1679   { NULL,            0 },
1680   { track_lookup,    4 },
1681   { NULL,            0 },
1682   { NULL,            0 },
1683   { NULL,            0 },
1684   { NULL,            0 },
1685   { NULL,            0 },
1686   { NULL,            0 },
1687   { NULL,            0 },
1688   { NULL,            0 },
1689   { NULL,            0 },
1690
1691   { col_setcirc,     3 },  /* 0x40 */
1692   { col_testpt,      2 },
1693   { NULL,            0 },
1694   { distance,        4 },
1695   { NULL,            0 },
1696   { NULL,            0 },
1697   { NULL,            0 },
1698   { car_move,        4 },
1699   { cpa,            12 },
1700   { NULL,            0 },
1701   { vmat_store,      1 },
1702   { vmat_restore,    1 },
1703   { NULL,            0 },
1704   { vmat_mul,        2 },
1705   { vmat_read,       1 },
1706   { matrix_unrot,    0 },
1707
1708   { f80,             0 },  /* 0x50 */
1709   { NULL,            0 },
1710   { matrix_rtrans,   0 },
1711   { NULL,            0 },
1712   { vmat_save,       1 },
1713   { vmat_load,       1 },
1714   { ram_setadr,      1 },
1715   { groundbox_test,  3 },
1716   { NULL,            0 },
1717   { f89,             4 },
1718   { NULL,            0 },
1719   { NULL,            0 },
1720   { f92,             4 },
1721   { f93,             1 },
1722   { f94,             1 },
1723   { vmat_flatten,    0 },
1724
1725   { vmat_load1,      1 },  /* 0x60 */
1726   { ram_trans,       0 },
1727   { f98,             1 },
1728   { f99,             0 },
1729   { f100,            0 },
1730   { groundbox_set,   7 },
1731   { f102,            8 },
1732   { f103,            1 }
16951733};
1734
16961735// Used in swa scene 1 and unemulated:
16971736//   f14
16981737//   f49_swa
16991738//   f15_swa
17001739
1701static struct function ftab_swa[] = {
1702   {   0, fadd,            2 },
1703   {   1, fsub,            2 },
1704   {   2, fmul,            2 },
1705   {   3, fdiv,            2 },
1706   {   5, matrix_push,     0 },
1707   {   6, matrix_pop,      0 },
1708   {   7, matrix_write,   12 },
1709   {   8, clear_stack,     0 },
1710   {   9, matrix_mul,     12 },
1711   {  10, anglev,          2 },
1712   {  11, f11,             9 },
1713   {  12, normalize,       3 },
1714   {  13, acc_seti,        1 },
1715   {  14, f14,   4 },
1716   {  15, f15_swa, 0 },
1717   {  16, matrix_ident,    0 },
1718   {  17, matrix_read,     0 },
1719   {  18, matrix_trans,    3 },
1720   {  19, matrix_scale,    3 },
1721   {  20, matrix_rotx,     1 },
1722   {  21, matrix_roty,     1 },
1723   {  22, matrix_rotz,     1 },
1724   {  24, f24_swa,   7 },
1725   {  26, transform_point, 3 },
1726   {  27, fsin_m1,         1 },
1727   {  28, fcos_m1,         1 },
1728   {  29, fsinm_m1,        2 },
1729   {  30, fcosm_m1,        2 },
1730   {  31, distance3,       6 },
1731   {  34, ftoi,            1 },
1732   {  35, itof,            1 },
1733   {  36, acc_set,         1 },
1734   {  37, acc_get,         0 },
1735   {  38, acc_add,         1 },
1736   {  39, acc_sub,         1 },
1737   {  40, acc_mul,         1 },
1738   {  41, acc_div,         1 }, // not used ?
1739   {  42, xyz2rqf,         3 },
1740   {  43, f43_swa, 3 },
1741   {  44, matrix_sdir,     3 },
1742   {  45, f45,   1 },
1743   {  46, vlength,         3 },
1744   {  47, f47,   3 },
1745   {  49, f49_swa, 6 },
1746   {  50, f50_swa, 4 },
1747   {  52, f52,   0 },
1748   {  53, matrix_rdir,     3 },
1749   {  56, f56,   7 },
1750   {  57, f57,   0 },
1751   {  58, matrix_readt,    0 },
1752   {  59, acc_geti,        0 },
1753   {  60, f60,   0 },
1754   {  65, push_and_ident,  0 },
1755   {  67, catmull_rom,     13 },
1756   { 0, 0, 0 }
1740static const struct function ftab_swa[] = {
1741   { fadd,            2 },  /* 0x00 */
1742   { fsub,            2 },
1743   { fmul,            2 },
1744   { fdiv,            2 },
1745   { NULL,            0 },
1746   { matrix_push,     0 },
1747   { matrix_pop,      0 },
1748   { matrix_write,   12 },
1749   { clear_stack,     0 },
1750   { matrix_mul,     12 },
1751   { anglev,          2 },
1752   { f11,             9 },
1753   { normalize,       3 },
1754   { acc_seti,        1 },
1755   { f14,             4 },
1756   { f15_swa,         0 },
1757
1758   { matrix_ident,    0 }, /* 0x10 */
1759   { matrix_read,     0 },
1760   { matrix_trans,    3 },
1761   { matrix_scale,    3 },
1762   { matrix_rotx,     1 },
1763   { matrix_roty,     1 },
1764   { matrix_rotz,     1 },
1765   { NULL,            0 },
1766   { f24_swa,         7 },
1767   { NULL,            0 },
1768   { transform_point, 3 },
1769   { fsin_m1,         1 },
1770   { fcos_m1,         1 },
1771   { fsinm_m1,        2 },
1772   { fcosm_m1,        2 },
1773   { distance3,       6 },
1774
1775   { NULL,            0 }, /* 0x20 */
1776   { NULL,            0 },
1777   { ftoi,            1 },
1778   { itof,            1 },
1779   { acc_set,         1 },
1780   { acc_get,         0 },
1781   { acc_add,         1 },
1782   { acc_sub,         1 },
1783   { acc_mul,         1 },
1784   { acc_div,         1 }, // not used ?
1785   { xyz2rqf,         3 },
1786   { f43_swa,         3 },
1787   { matrix_sdir,     3 },
1788   { f45,             1 },
1789   { vlength,         3 },
1790   { f47,             3 },
1791
1792   { NULL,            0 }, /* 0x30 */
1793   { f49_swa,         6 },
1794   { f50_swa,         4 },
1795   { NULL,            0 },
1796   { f52,             0 },
1797   { matrix_rdir,     3 },
1798   { NULL,            0 },
1799   { NULL,            0 },
1800   { f56,             7 },
1801   { f57,             0 },
1802   { matrix_readt,    0 },
1803   { acc_geti,        0 },
1804   { f60,             0 },
1805   { NULL,            0 },
1806   { NULL,            0 },
1807   { NULL,            0 },
1808   { NULL,            0 },
1809
1810   { push_and_ident,  0 }, /* 0x40 */
1811   { NULL,            0 },
1812   { catmull_rom,    13 }
17571813};
17581814
17591815
r1215r1216
17671823static void function_get_vf(void)
17681824{
17691825   UINT32 f = fifoin_pop() >> 23;
1770   struct function *fct;
17711826
1772   for(fct = ftab_vf; fct->cb && fct->nb != f; fct++);
1773
17741827   if(fifoout_rpos != fifoout_wpos) {
17751828      int count = fifoout_wpos - fifoout_rpos;
17761829      if(count < 0)
17771830         count += FIFO_SIZE;
17781831      logerror("TGP function called with sizeout = %d\n", count);
17791832   }
1780   if(fct->cb) {
1781      fifoin_cbcount = fct->count;
1782      fifoin_cb = fct->cb;
1833   if(ARRAY_LENGTH(ftab_vf) > f && NULL != ftab_vf[f].cb) {
1834      fifoin_cbcount = ftab_vf[f].count;
1835      fifoin_cb = ftab_vf[f].cb;
17831836      //      logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount);
17841837      if(!fifoin_cbcount)
17851838         fifoin_cb();
r1215r1216
17931846static void function_get_swa(void)
17941847{
17951848   UINT32 f = fifoin_pop();
1796   struct function *fct;
17971849
1798   for(fct = ftab_swa; fct->cb && fct->nb != f; fct++);
1799
18001850   if(fifoout_rpos != fifoout_wpos) {
18011851      int count = fifoout_wpos - fifoout_rpos;
18021852      if(count < 0)
18031853         count += FIFO_SIZE;
18041854      logerror("TGP function called with sizeout = %d\n", count);
18051855   }
1806   if(fct->cb) {
1807      fifoin_cbcount = fct->count;
1808      fifoin_cb = fct->cb;
1856   if(ARRAY_LENGTH(ftab_swa) > f && NULL != ftab_swa[f].cb) {
1857      fifoin_cbcount = ftab_swa[f].count;
1858      fifoin_cb = ftab_swa[f].cb;
18091859      //      logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount);
18101860      if(!fifoin_cbcount)
18111861         fifoin_cb();
src/mame/mamedriv.c
r1215r1216
24732473   DRIVER( ssf2tbr1 )   /* 11/09/1993 (c) 1993 (World) */
24742474   DRIVER( ssf2tbj )   /* 11/09/1993 (c) 1993 (Japan) */
24752475   DRIVER( ecofghtr )   /* 03/12/1993 (c) 1993 (World) */
2476   DRIVER( ecofghtu )   /* 03/12/1993 (c) 1993 (US) */
2476   DRIVER( ecofghtu )   /* 15/02/1994 (c) 1993 (US) */
2477   DRIVER( ecofgtu1 )   /* 03/12/1993 (c) 1993 (US) */
24772478   DRIVER( ecofghta )   /* 03/12/1993 (c) 1993 (Asia) */
24782479   DRIVER( uecology )    /* 03/12/1993 (c) 1993 (Japan) */
24792480   DRIVER( ddtod )      /* 12/04/1994 (c) 1993 (Euro) */
r1215r1216
28962897   DRIVER( ddr2mc2 )   /* 1999 - Dance Dance Revolution 2nd Mix with beatmaniaIIDX substream CLUB VERSiON 2 (GE984 VER. JAA) */
28972898   DRIVER( gtrfrk2m )   /* 1999 - Guitar Freaks 2nd Mix Ver 1.01 (GQ883 VER. JAD) */
28982899   DRIVER( dsftkd )   /* 1999 - Dancing Stage featuring TRUE KiSS DESTiNATiON (G*884 VER. JAA) */
2900   DRIVER( cr589fw )   /* 1999 - CR-589 Firmware (700B04) */
2901   DRIVER( cr589fwa )   /* 1999 - CR-589 Firmware (700A04) */
28992902   DRIVER( ddr3mk )   /* 2000 - Dance Dance Revolution 3rd Mix - Ver.Korea2 (GN887 VER. KBA) */
29002903   DRIVER( ddr3mka )   /* 2000 - Dance Dance Revolution 3rd Mix - Ver.Korea (GN887 VER. KAA) */
29012904   DRIVER( ddr3ma )   /* 1999 - Dance Dance Revolution 3rd Mix (GN887 VER. AAA) */
r1215r1216
29272930   DRIVER( ddr5m )      /* 2001 - Dance Dance Revolution 5th Mix (G*A27 VER. JAA) */
29282931   DRIVER( dmx2majp )   /* 2001 - Dance Maniax 2nd Mix Append J-Paradise (G*A38 VER. JAA ) */
29292932   DRIVER( gtrfrk6m )   /* 2001 - Guitar Freaks 6th Mix (G*B06 VER. JAA) */
2933   DRIVER( gtrfrk7m )   /* 2001 - Guitar Freaks 6th Mix (G*B17 VER. JAA) */
29302934   DRIVER( ddrmax )   /* 2001 - DDR Max - Dance Dance Revolution 6th Mix (G*B19 VER. JAA) */
29312935   DRIVER( ddrmax2 )   /* 2002 - DDR Max 2 - Dance Dance Revolution 7th Mix (G*B20 VER. JAA) */
29322936   DRIVER( dsem2 )      /* 2002 - Dancing Stage Euro Mix 2 (G*C23 VER. EAA) */
r1215r1216
47854789   DRIVER( thrilld )   /* GX713 (c)1998 */
47864790   DRIVER( midnrun )   /* GX??? (c)1995 */
47874791   DRIVER( windheat )   /* GX677 (c)1996 */
4792   DRIVER( jetwave )   /* GX??? (c)1996 */
47884793
47894794   /* Konami M2 games */
47904795   DRIVER( polystar )   /* GX623 (c)1997 */
r1215r1216
73697374
73707375   /* MPU4+Video Board Games */
73717376   DRIVER( bctvidbs )
7372   DRIVER( dealem )
7377   DRIVER( dealem )   /* 1987 */
7378   DRIVER( timemchn )   /* 1990 */
73737379   DRIVER( crmaze )   /* 1994 */
73747380   DRIVER( crmazea )   /* 1994 */
73757381   DRIVER( crmazeb )   /* 1994 */
src/mame/includes/galaxian.h
r1215r1216
207207
208208/*----------- defined in audio/galaxian.c -----------*/
209209
210extern struct Samplesinterface galaxian_custom_interface;
210extern struct Samplesinterface galaxian_samples_interface;
211211WRITE8_HANDLER( galaxian_pitch_w );
212212WRITE8_HANDLER( galaxian_vol_w );
213213WRITE8_HANDLER( galaxian_noise_enable_w );
src/mame/includes/midzeus.h
r0r1216
1/*************************************************************************
2
3    Driver for Midway Zeus games
4
5**************************************************************************/
6
7
8/*----------- defined in video/midzeus.c -----------*/
9
10extern UINT32 *zeusbase;
11
12VIDEO_START( midzeus );
13VIDEO_UPDATE( midzeus );
14
15READ32_HANDLER( zeus_r );
16WRITE32_HANDLER( zeus_w );
17
18READ32_HANDLER( zeus2_r );
19WRITE32_HANDLER( zeus2_w );
20
src/mame/includes/cclimber.h
r1215r1216
3939/*----------- defined in audio/cclimber.c -----------*/
4040
4141extern struct AY8910interface cclimber_ay8910_interface;
42extern struct Samplesinterface cclimber_custom_interface;
42extern struct Samplesinterface cclimber_samples_interface;
4343WRITE8_HANDLER( cclimber_sample_trigger_w );
4444WRITE8_HANDLER( cclimber_sample_rate_w );
4545WRITE8_HANDLER( cclimber_sample_volume_w );
src/mame/mame.mak
r1215r1216
929929   $(DRIVERS)/midwunit.o $(MACHINE)/midwunit.o \
930930   $(DRIVERS)/midxunit.o \
931931   $(DRIVERS)/midyunit.o $(MACHINE)/midyunit.o $(VIDEO)/midyunit.o \
932   $(DRIVERS)/midzeus.o \
932   $(DRIVERS)/midzeus.o $(VIDEO)/midzeus.o \
933933   $(DRIVERS)/omegrace.o \
934934   $(DRIVERS)/seattle.o \
935935   $(DRIVERS)/tmaster.o \
src/mame/video/stvvdp2.c
r1215r1216
8080*/
8181
8282#include "driver.h"
83#include "eminline.h"
8384#include "profiler.h"
8485
8586UINT32* stv_vdp2_regs;
r1215r1216
21242125
21252126} stv_rbg_cache_data;
21262127
2127#define mul_fixed32( a, b ) fixed_mul_shift( a, b, 16 )
2128#define mul_fixed32( a, b ) mul_32x32_shift( a, b, 16 )
21282129
21292130static void stv_vdp2_fill_rotation_parameter_table( UINT8 rot_parameter )
21302131{
src/mame/video/midzeus.c
r0r1216
1/*************************************************************************
2
3    Driver for Midway Zeus games
4
5**************************************************************************/
6
7#include "driver.h"
8#include "eminline.h"
9#include "includes/midzeus.h"
10#include "video/polynew.h"
11
12
13
14/*************************************
15 *
16 *  Constants
17 *
18 *************************************/
19
20#define WAVERAM_WIDTH   512
21#define WAVERAM_HEIGHT   4096
22
23
24
25/*************************************
26 *
27 *  Type definitions
28 *
29 *************************************/
30
31typedef struct _poly_extra_data poly_extra_data;
32struct _poly_extra_data
33{
34   const UINT32 *   palbase;
35   const UINT32 *   texbase;
36   UINT16         transcolor;
37   UINT16         texwidth;
38   UINT16         color;
39   UINT32         alpha;
40};
41
42
43
44/*************************************
45 *
46 *  Global variables
47 *
48 *************************************/
49
50UINT32 *zeusbase;
51
52static poly_manager *poly;
53
54static UINT32 zeuscmd_buffer[8];
55static UINT8 zeuscmd_buffer_words;
56static UINT8 zeuscmd_buffer_expected_words;
57static INT16 zeus_matrix[3][3];
58static INT32 zeus_point[3];
59static UINT32 *zeus_palbase;
60static int zeus_enable_logging;
61static UINT32 zeus_blend;
62static UINT32 zeus_texdata;
63static UINT32 zeus_objdata;
64
65static UINT32 last_tex[1000][2];
66static int last_tex_index;
67
68static UINT32 *waveram;
69
70
71
72/*************************************
73 *
74 *  Function prototypes
75 *
76 *************************************/
77
78static void exit_handler(running_machine *machine);
79
80
81
82/*************************************
83 *
84 *  Inlines
85 *
86 *************************************/
87
88INLINE UINT32 *waveram_ptr_from_addr(UINT32 addr)
89{
90   return &waveram[((addr & 0x1ff) | ((addr & 0xfff000) >> 3)) * 2];
91}
92
93
94INLINE UINT32 *waveram_pixel_ptr(int bank, int y, int x)
95{
96   return &waveram[bank * (WAVERAM_HEIGHT * WAVERAM_WIDTH) + y * WAVERAM_WIDTH + (x & ~1)];
97}
98
99
100INLINE void waveram_plot(int y, int x, UINT16 color)
101{
102   if (x >= 0 && x < 400 && y >= 0 && y < 256)
103   {
104      UINT32 *ptr = waveram_pixel_ptr(1, y, x);
105      if (x & 1)
106         *ptr = (*ptr & 0x0000ffff) | (color << 16);
107      else
108         *ptr = (*ptr & 0xffff0000) | color;
109   }
110}
111
112
113INLINE void waveram_plot_depth(int y, int x, UINT16 color, UINT16 depth)
114{
115   if (x >= 0 && x < 400 && y >= 0 && y < 256)
116   {
117      UINT32 *ptr = waveram_pixel_ptr(1, y, x);
118      if (x & 1)
119      {
120         ptr[0] = (ptr[0] & 0x0000ffff) | (color << 16);
121         ptr[1] = (ptr[1] & 0x0000ffff) | (depth << 16);
122      }
123      else
124      {
125         ptr[0] = (ptr[0] & 0xffff0000) | color;
126         ptr[1] = (ptr[1] & 0xffff0000) | depth;
127      }
128   }
129}
130
131
132INLINE void waveram_plot_check_depth(int y, int x, UINT16 color, UINT16 depth)
133{
134   if (x >= 0 && x < 400 && y >= 0 && y < 256)
135   {
136      UINT32 *ptr = waveram_pixel_ptr(1, y, x);
137      if (x & 1)
138      {
139         if (depth <= (ptr[1] >> 16))
140         {
141            ptr[0] = (ptr[0] & 0x0000ffff) | (color << 16);
142            ptr[1] = (ptr[1] & 0x0000ffff) | (depth << 16);
143         }
144      }
145      else
146      {
147         if (depth <= (ptr[1] & 0xffff))
148         {
149            ptr[0] = (ptr[0] & 0xffff0000) | color;
150            ptr[1] = (ptr[1] & 0xffff0000) | depth;
151         }
152      }
153   }
154}
155
156
157INLINE UINT32 *zeus_pixaddr(void)
158{
159   int bank = (zeusbase[0xb6] >> 31) & 1;
160   int x = (zeusbase[0xb4] & 0xff) << 1;
161   int y = ((zeusbase[0xb4] >> 15) & 0xffe) | ((zeusbase[0xb4] >> 8) & 0x01);
162   return waveram_pixel_ptr(bank, y, x);
163}
164
165
166INLINE UINT8 get_texel_8bit(const UINT32 *base, int y, int x, int width)
167{
168   if (x >= width)
169      return 0;
170   base += (y / 2) * (width / 2) + (x / 4) * 2 + (y & 1);
171   return *base >> (8 * (x & 3));
172}
173
174
175INLINE UINT8 get_texel_4bit(const UINT32 *base, int y, int x, int width)
176{
177   if (x >= width * 2)
178      return 0;
179   base += (y / 2) * (width / 2) + (x / 8) * 2 + (y & 1);
180   return (*base >> (4 * (x & 7))) & 0x0f;
181}
182
183
184
185/*************************************
186 *
187 *  Video startup
188 *
189 *************************************/
190
191VIDEO_START( midzeus )
192{
193   int i;
194
195   /* allocate memory for "wave" RAM */
196   waveram = auto_malloc(2 * WAVERAM_WIDTH * WAVERAM_HEIGHT * sizeof(*waveram));
197   state_save_register_global_pointer(waveram, 2 * WAVERAM_WIDTH * WAVERAM_HEIGHT);
198
199   /* initialize a 5-5-5 palette */
200   for (i = 0; i < 32768; i++)
201      palette_set_color_rgb(machine, i, pal5bit(i >> 10), pal5bit(i >> 5), pal5bit(i >> 0));
202
203   /* initialize polygon engine */
204   poly = poly_alloc(1000, sizeof(poly_extra_data), 0);
205
206   /* we need to cleanup on exit */
207   add_exit_callback(machine, exit_handler);
208}
209
210
211static void exit_handler(running_machine *machine)
212{
213   FILE *f = fopen("waveram.dmp", "w");
214   int i;
215
216   for (i = 0; i < 2 * WAVERAM_WIDTH * WAVERAM_HEIGHT; i += 2)
217   {
218      if (i % 8 == 0) fprintf(f, "%03X%03X: ", (i / 1024), (i / 2) & 0x1ff);
219      fprintf(f, " %08X %08X ", waveram[i+0], waveram[i+1]);
220      if (i % 8 == 6) fprintf(f, "\n");
221   }
222   fclose(f);
223}
224
225
226
227/*************************************
228 *
229 *  Video update
230 *
231 *************************************/
232
233VIDEO_UPDATE( midzeus )
234{
235   int x, y;
236
237   /* normal update case */
238   if (!input_code_pressed(KEYCODE_W))
239   {
240      for (y = cliprect->min_y; y <= cliprect->max_y; y++)
241      {
242         UINT32 *src = waveram_pixel_ptr(1, y, 0);
243         UINT16 *dest = (UINT16 *)bitmap->base + y * bitmap->rowpixels;
244         for (x = cliprect->min_x; x <= cliprect->max_x; x += 2)
245         {
246            UINT32 pixels = *src;
247            dest[x+0] = pixels & 0x7fff;
248            dest[x+1] = (pixels >> 16) & 0x7fff;
249            src += 2;
250         }
251      }
252   }
253
254   /* waveram drawing case */
255   else
256   {
257      static int yoffs = 0;
258      static int width = 256;
259      UINT32 *base;
260
261      if (input_code_pressed(KEYCODE_DOWN)) yoffs += input_code_pressed(KEYCODE_LSHIFT) ? 0x40 : 1;
262      if (input_code_pressed(KEYCODE_UP)) yoffs -= input_code_pressed(KEYCODE_LSHIFT) ? 0x40 : 1;
263      if (input_code_pressed(KEYCODE_LEFT) && width > 4) { width >>= 1; while (input_code_pressed(KEYCODE_LEFT)) ; }
264      if (input_code_pressed(KEYCODE_RIGHT) && width < 512) { width <<= 1; while (input_code_pressed(KEYCODE_RIGHT)) ; }
265
266      if (yoffs < 0) yoffs = 0;
267      base = waveram_ptr_from_addr(yoffs << 12);
268
269      for (y = cliprect->min_y; y <= cliprect->max_y; y++)
270      {
271         UINT16 *dest = (UINT16 *)bitmap->base + y * bitmap->rowpixels;
272         for (x = cliprect->min_x; x <= cliprect->max_x; x++)
273         {
274            UINT8 tex = get_texel_8bit(base, y, x, width);
275            dest[x] = (tex << 8) | tex;
276         }
277      }
278      popmessage("offs = %06X", yoffs << 12);
279   }
280
281   if (input_code_pressed(KEYCODE_T) && last_tex_index != 0)
282   {
283      int i;
284      printf("----\n");
285      for (i = 0; i < last_tex_index; i++)
286         printf("%06X %03X (w=%d)\n", last_tex[i][0], last_tex[i][1], 512 >> ((last_tex[i][1] >> 6) & 7));
287      last_tex_index = 0;
288   }
289
290   return 0;
291}
292
293
294
295/*
296
297    New analysis:
298
299    Offset
300    ------
301
302    $58  W  Usually written after $5A; after writing, waits for $F6 bit 4 to be cleared
303
304    $5A  W  Usually written first, followed by $58
305
306    $68  W  Written at startup:
307            $00030000 = toggled on then off at startup
308
309    $76  W
310
311    $7C  W
312
313    $80  W  Master control
314
315            $40000000 = set along with $02000000 when enabling FIFO empty interrupt
316            $02000000 = enable internal data FIFO empty interrupt
317            $01000000 = cleared along with $02000000 when disabling FIFO empty interrupt
318            $00020000 = 16-bit (0) or 32-bit (1) mode
319            $00000008 = cleared just before writing to offsets $200-$3FF
320
321    $82  W
322    $84  W
323    $86  W
324    $88  W
325    $8A  W
326    $8C  W
327    $8E  W
328
329    $B0 R/W Data port for direct RAM access
330    $B2 R/W Data port for direct RAM access
331
332    $B4  W  Address for direct RAM access
333
334            $07FF0100 = mask for Y coordinate
335            $000000FF = mask for X coordinate
336
337    $B6  W  Direct RAM access control
338
339            $80000000 = enable writes to wave RAM 0
340            $40000000 = enable writes to wave RAM 1
341            $02000000 = perform access on write to B0(0) or B2(1) ?????
342            $00800000 = enable writes from [$B2] to depth buffer
343            $00400000 = enable writes from [$B0] to depth buffer
344            $00200000 = enable writes from [$B2] to RAM buffer
345            $00100000 = enable writes from [$B0] to RAM buffer
346            $00020000 = auto increment the address
347            $00010000 = perform a read when the address is written
348            $00000001 = enable direct RAM access
349
350            Examples:
351                $80A00000 when writing a single pixel (address written each time)
352                $80A20001 when writing the right pixel of a pair (autoinc assumed)
353                $80F60001 when writing the middle pairs of pixels (autoinc assumed)
354                $80520001 when writing the left pixel of a pair (autoinc assumed)
355                $82F00001 when testing wave RAM page 1 (address written each pair)
356                $42F00001 when testing wave RAM page 0 (address written each pair)
357                $82F60001 when uploading to wave RAM page 1 (autoinc assumed)
358                $42F60001 when uploading to wave RAM page 0 (autoinc assumed)
359
360    $C0  W  Written at startup = $801F2500
361    $C2  W  Written at startup = $0015E591
362    $C4  W  Written at startup = $000C0042 (HSYNC start/HSYNC end?)
363    $C6  W  Written at startup = $0211007F (HTOTAL/HBLANK end?)
364    $C8  W  Written at startup = $010300FF (VSYNC start/VBLANK start?)
365    $CA  W  Written at startup = $01160107 (VTOTAL/VSYNC end?)
366    $CC  W  Written at startup = $00000000
367    $CE  W  Written at startup = $00C87620
368
369    $E0  W  Internal data FIFO
370
371    $F2  R  Looped on until it returns a stable value; must change frequently; PRNG?
372
373    $F4  R  Status register
374
375            $00000800 = VBLANK? code waits for it to clear to 0 and then reset to 1
376            $00000140 = tested together in tight loop until both are 0
377            $00000008 = internal data FIFO full
378            $00000004 = tested in tight loop along with $00000002 until at least one is set
379            $00000002 = tested in tight loop after handling FIFO interrupt until set
380
381    $F6  R  Status register 2
382
383            $00000010 = tested in tight loop after writing 5A/59/58 until set to 0
384
385   $200- W  Unknown, but written in a loop with master control bit $00000008 cleared
386   $3FF     Possible fast buffer clear? One set of writes stores $7F7F to all entries.
387            A second set writes $E00,$25,$E01,$25,...,$E7F,$25. A third set writes
388            $52,$A0000000,...
389
390Notes:
391
392    In 16-bit mode, writes to $E0 are done via $E1 first then $E0
393
394-------------------------------------------------------
395
396Old info:
397
398    offset B7 = control....
399
400        8000 = page 1 enable
401        4000 = page 0 enable
402
403        0080 = 2nd pixel enable (maybe Z buff?)
404        0040 = 1st pixel enable (maybe Z buff?)
405        0020 = 2nd pixel enable
406        0010 = 1st pixel enable
407
408
409    writes 80a2 to write an odd pixel at startup
410    writes 80f6 to write the middle pixels
411    writes 8052 to write an odd pixel at the end
412
413    writes 8050 before writing an odd pixel
414    writes 80a0 before writing an even pixel
415
416    writes 44f1 before reading from page 0 of wave ram
417    writes 84f1 before reading from page 1 of wave ram
418
419    writes 42f0 before writing to page 0 of wave ram
420    writes 82f0 before writing to page 1 of wave ram
421
422*/
423
424/*
425    zeus data notes:
426
427    Data from $1000-1A20
428    Palettes at $2000,$2200,$2400
429    Data from $2600-27C7
430    Palettes at $27C8,$29C8,$2BC8,$2DC8
431    Palettes up through $5A000
432
433    Interesting data at $5A000-5BFFF
434
435    Common sequence:
436        $8000 xxxx $0C01 $3805
437        x = matches address of next data * 8
438*/
439
440
441
442/*
443    Control = $80F6 when doing initial screen clear.
444       Writes 256 consecutive values to $B0, must mean autoincrement
445       Uses latched value in $B2 (maybe also in $B0)
446
447    Control = $82F0 when doing video RAM test write phase.
448       Writes 512 values across, but updates address before each one.
449
450    Control = $84F1 when doing video RAM test read phase.
451       Reads 512 values across, but updates address before each one.
452
453    Control = $80F2 when doing screen clear.
454       Writes 256 consecutive values to $B0, must mean autoincrement.
455       Uses latched value in $B2 (maybe also in $B0)
456
457    Control = $80A0/$8050 when plotting pixels.
458
459    Control = $42F0 when doing wave RAM test write phase.
460       Writes 512 values across, but updates address before each one.
461
462    Control = $44F1 when doing wave RAM test read phase.
463       Reads 512 values across, but updates address before each one.
464*/
465
466
467/*
468
469    Known commands:
470
471        $00rrxxxx = another type of register set?
472         yyyyyyyy
473
474            $0000C040 = set palette to 'yyyyyyyy'
475
476        $17rrxxxx = 16-bit write 'xxxx' to register 'rr'
477
478            $1752xxxx = write 'xxxx' to something that reflects back through $B2
479            $1770xxxx = write 'xxxx' to upper 16 bits of X coordinate
480            $1772xxxx = write 'xxxx' to upper 16 bits of Y coordinate
481            $1774xxxx = write 'xxxx' to upper 16 bits of Z coordinate
482
483        $18rr0000 = 32-bit write 'xxxxxxxx' to register 'rr'
484         xxxxxxxx
485
486        $1A000000 = pipeline synchronize (guess)
487
488        $1C00cccc = load matrix (abc)(def)(ghi) and point (xyz)
489         ffffiiii
490         bbbbaaaa
491         eeeedddd
492         hhhhgggg
493         xxxxxxxx
494         yyyyyyyy
495         zzzzzzzz
496
497        $6700xxxx = render object described at 'bbbbbb' in waveram
498         aabbbbbb
499         ccddcccc
500*/
501
502/*
503Zeus cmd 18 : 18D60000 500A00FF
504Zeus cmd 00 : 0005C0A5 21001125
505Zeus cmd 25 : 25000000 007F0018 01000400 B0F60008
506Zeus cmd 18 : 18D60000 500A00FF
507Zeus cmd 18 : 18CE0000 00FFFFFF
508Zeus cmd 1A : 1A000000
509Zeus cmd 18 : 187E0000 0000FFFF
510Zeus cmd 1A : 1A000000
511Zeus cmd 18 : 18CE0000 00FFFFFF
512Zeus cmd 1A : 1A000000
513Zeus cmd 18 : 187E0000 FF980000
514Zeus cmd 00 : 0080C0A5 3F00102F
515Zeus cmd 17 : 17681370
516Zeus cmd 17 : 176940C4
517Zeus cmd 1C : ( 4000 0000 0000 ) ( 0000 4000 0000 ) ( 0000 0000 4000 )  -152.00   -50.00  1.25000
518Zeus cmd 00 : 0000C040 0318E132 -> palette @ (18E,132)
519Zeus cmd 67 : 67008000 0919F1C4 151 01FA4C -> render @ (19F,1C4)
520Zeus cmd 1C : ( 4000 0000 0000 ) ( 0000 4000 0000 ) ( 0000 0000 4000 )  -135.00   -50.00  1.25000
521Zeus cmd 67 : 67008000 0919F1C4 151 01FA4C
522Zeus cmd 1C : ( 4000 0000 0000 ) ( 0000 4000 0000 ) ( 0000 0000 4000 )  -118.00   -50.00  1.25000
523Zeus cmd 67 : 67008000 0919F1C4 151 01F988
524Zeus cmd 1C : ( 4000 0000 0000 ) ( 0000 4000 0000 ) ( 0000 0000 4000 )  -101.00   -50.00  1.25000
525
52619F1BA:  19DC0000 00000000  19840000 00F01605  25810000 21010000  FFD00000 00000000  FFD00038 000E0000  00080038 0E0E0000  00080000 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
52719F1C4:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD0FFFC 00000000  FFD0003C 00100000  0008003C 0E100000  0008FFFC 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
52819F1CE:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD0FFFC 00000000  FFD00028 000B0000  00080028 0E0B0000  0008FFFC 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
52919F1D8:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD00000 00000000  FFD00034 000D0000  00080034 0E0D0000  00080000 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
53019F1E2:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD00000 00000000  FFD00028 000A0000  000C0028 0F0A0000  000C0000 0F000000  30000000 30000000  30000000 30000000  08000000 00000000
53119F1EC:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD00000 00000000  FFD00014 00050000  00080014 0E050000  00080000 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
53219F1F6:  19DC0000 00000000  19840000 00F01605  25810000 21010000  FFD0FFFC 00000000  FFD00034 000E0000  00080034 0E0E0000  0008FFFC 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
5331A0000:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFCC0000 00000000  FFCC0038 000E0000  000C0038 100E0000  000C0000 10000000  30000000 30000000  30000000 30000000  08000000 00000000
5341A000A:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFCC0000 00000000  FFCC0034 000D0000  000C0034 100D0000  000C0000 10000000  30000000 30000000  30000000 30000000  08000000 00000000
5351A0014:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFCC0000 00000000  FFCC002C 000B0000  0008002C 0F0B0000  00080000 0F000000  30000000 30000000  30000000 30000000  08000000 00000000
5361A001E:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFCC0000 00000000  FFCC002C 000B0000  000C002C 100B0000  000C0000 10000000  30000000 30000000  30000000 30000000  08000000 00000000
5371A0028:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD00000 00000000  FFD0002C 000B0000  000C002C 0F0B0000  000C0000 0F000000  30000000 30000000  30000000 30000000  08000000 00000000
5381A0032:  19DC0000 00000000  19840000 00F01605  25800000 21010000  FFD00000 00000000  FFD00018 00060000  00080018 0E060000  00080000 0E000000  30000000 30000000  30000000 30000000  08000000 00000000
5391A003C:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF9CFF64 00000000  FF9C0084 00480000  005C0084 30480000  005CFF64 30000000  30000000 30000000  30000000 30000000  08000000 00000000
5401A0046:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF80FF48 00000000  FF80009C 00550000  0070009C 3C550000  0070FF48 3C000000  30000000 30000000  30000000 30000000  08000000 00000000
5411A0050:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF68FF30 00000000  FF6800B0 00600000  008800B0 48600000  0088FF30 48000000  30000000 30000000  30000000 30000000  08000000 00000000
5421A005A:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF54FF20 00000000  FF5400C4 00690000  00A000C4 53690000  00A0FF20 53000000  30000000 30000000  30000000 30000000  08000000 00000000
5431A0064:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF44FF10 00000000  FF4400D4 00710000  00B000D4 5B710000  00B0FF10 5B000000  30000000 30000000  30000000 30000000  08000000 00000000
5441A006E:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF3CFF08 00000000  FF3C00E4 00770000  00B400E4 5E770000  00B4FF08 5E000000  30000000 30000000  30000000 30000000  08000000 00000000
5451A0078:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF38FEFC 00000000  FF3800E4 007A0000  00C000E4 627A0000  00C0FEFC 62000000  30000000 30000000  30000000 30000000  08000000 00000000
5461A0082:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF28FEFC 00000000  FF2800EC 007C0000  00C000EC 667C0000  00C0FEFC 66000000  30000000 30000000  30000000 30000000  08000000 00000000
5471A008C:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF60FF28 00000000  FF6000C0 00660000  009C00C0 4F660000  009CFF28 4F000000  30000000 30000000  30000000 30000000  08000000 00000000
5481A0096:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF80FF48 00000000  FF80009C 00550000  0078009C 3E550000  0078FF48 3E000000  30000000 30000000  30000000 30000000  08000000 00000000
5491A00A0:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FF94FF5C 00000000  FF940088 004B0000  00640088 344B0000  0064FF5C 34000000  30000000 30000000  30000000 30000000  08000000 00000000
5501A00AA:  19DC0000 40B68800  19840000 00001604  25810000 21010000  FFA4FF6C 00000000  FFA4007C 00440000  0054007C 2C440000  0054FF6C 2C000000  30000000 30000000  30000000 30000000  08000000 00000000
5511A00B4:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FFACFF78 00000000  FFAC0070 003E0000  00480070 273E0000  0048FF78 27000000  30000000 30000000  30000000 30000000  08000000 00000000
5521A00BE:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FFB4FF7C 00000000  FFB4006C 003C0000  0044006C 243C0000  0044FF7C 24000000  30000000 30000000  30000000 30000000  08000000 00000000
5531A00C8:  19DC0000 00000000  19840000 00001605  25800000 21000000  FF42FF02 00000000  FF4200FE 007F0000  00BE00FE 5F7F0000  00BEFF02 5F000000  30000000 30000000  30000000 30000000  08000000 00000000
5541A00D2:  19DC0000 00000000  19840000 00001605  25800000 21010000  FFB0FF70 00000000  FFB0007C 00430000  0054007C 29430000  0054FF70 29000000  30000000 30000000  30000000 30000000  08000000 00000000
5551A00DC:  19DC0000 40B68800  19840000 00001604  25800000 21010000  FA10F810 00000000  FA1007F0 007F0000  05F007F0 5F7F0000  05F0F810 5F000000  30000000 30000000  30000000 30000000  08000000 00000000
5561A00E6:  0C02C0F0 0F18E1BE
557         19DC0000 4B23CB00  19840000 00001605  252978EF 200C0000  04480000 00000000  043D0000 0000001E  043DFFEB 00000015  043DFFEB 00000015  00040000 0A331400  0743178C 0743178C
5581A00F0:                                        251178D7 200C0000  04480000 00000000  043DFFEB 00000015  043DFFE2 00000000  043DFFE2 00000000  00040000 0743178C  0003175D 0003175D
559                                               25EF78D7 200C0000  04480000 00000000  043DFFE2 00000000  043DFFEB 0000FFEB  043DFFEB 0000FFEB  00040000 0003175D  38C3178C 38C3178C
560                                               25D778EF 200C0000  04480000 00000000  043DFFEB 0000FFEB  043D0000 0000FFE2  043D0000 0000FFE2  00040000 38C3178C  35D31400 35D31400
561                                               25D77811 200C0000  04480000 00000000  043D0000 0000FFE2  043D0015 0000FFEB  043D0015 0000FFEB  00040000 35D31400  38C31474 38C31474
5621A010C:                                        25EF7829 200C0000  04480000 00000000  043D0015 0000FFEB  043D001E 00000000  043D001E 00000000  00040000 38C31474  000314A3 000314A3
563                                               25117829 200C0000  04480000 00000000  043D001E 00000000  043D0015 00000015  043D0015 00000015  00040000 000314A3  07431474 07431474
564                                               25297811 200C0000  04480000 00000000  043D0015 00000015  043D0000 0000001E  043D0000 0000001E  00040000 07431474  0A331400 0A331400
565                                               0C018000 381A0122
566                                               252186F3 200C0000  F64A0000 00000000  F652FFEB 00000015  F6520000 0000001E  F6520000 0000001E  000C0000 06ECD393  09ACD3FF 09ACD3FF
567                                               250D86DF 200C0000  F64A0000 00000000  F652FFE2 00000000  F652FFEB 00000015  F652FFEB 00000015  000C0000 001CD366  06DCD392 06DCD392
5681A0130:                                        25F386DF 200C0000  F64A0000 00000000  F652FFEB 0000FFEB  F652FFE2 00000000  F652FFE2 00000000  000C0000 393CD392  3FFCD366 3FFCD366
569                                               25DF86F3 200C0000  F64A0000 00000000  F6520000 0000FFE2  F652FFEB 0000FFEB  F652FFEB 0000FFEB  000C0000 366CD3FF  392CD393 392CD393
570                                               25DF860D 200C0000  F64A0000 00000000  F6520015 0000FFEB  F6520000 0000FFE2  F6520000 0000FFE2  000C0000 392CD06D  366CD001 366CD001
571                                               25F38621 200C0000  F64A0000 00000000  F652001E 00000000  F6520015 0000FFEB  F6520015 0000FFEB  000C0000 3FFCD09A  393CD06E 393CD06E
5721A014C:                                        250D8621 200C0000  F64A0000 00000000  F6520015 00000015  F652001E 00000000  F652001E 00000000  000C0000 06DCD06E  001CD09A 001CD09A
573                                               2521860D 200C0000  F6520000 0000001E  F6520015 00000015  F64A0000 00000000  F64A0000 00000000  09ACD001 06ECD06D  000C0000 000C0000
574                                               0C018000 381A015B
575                                               25D53969 200C0000  0429001D 0000FFE3  04290029 00000000  043D001E 00000000  043D0015 0000FFEB  356110B3 3FA110F7  3EB2D8B3 3902D88D
576                                               252B3969 200C0000  04290029 00000000  0429001D 0000001D  043D0015 00000015  043D001E 00000000  006110F7 0AA110B3  0702D88D 0152D8B3
577                                               2569392B 200C0000  0429001D 0000001D  04290000 00000029  043D0000 0000001E  043D0015 00000015  0B3110AA 0F711006  0B32D815 08D2D870
5781A0170:                                        256939D5 200C0000  04290000 00000029  0429FFE3 0000001D  043DFFEB 00000015  043D0000 0000001E  0F7113FA 0B311356  08D2DB90 0B32DBEB
579                                               252B3997 200C0000  0429FFE3 0000001D  0429FFD7 00000000  043DFFE2 00000000  043DFFEB 00000015  0AA1134D 00611309  0152DB4D 0702DB73
580                                               25D53997 200C0000  0429FFD7 00000000  0429FFE3 0000FFE3  043DFFEB 0000FFEB  043DFFE2 00000000  3FA11309 3561134D  3902DB73 3EB2DB4D
581                                               259739D5 200C0000  0429FFE3 0000FFE3  04290000 0000FFD7  043D0000 0000FFE2  043DFFEB 0000FFEB  34D11356 309113FA  34D2DBEB 3732DB90
5821A018C:                                        2597392B 200C0000  04290000 0000FFD7  0429001D 0000FFE3  043D0015 0000FFEB  043D0000 0000FFE2  30911006 34D110AA  3732D870 34D2D815
583                                               0C018000 381A0194
5841A0194:                                        252BC769 200C0000  F666001D 0000001D  F6660029 00000000  F652001E 00000000  F6520015 00000015  0AAEF0B3 006EF0F7  018D20B0 06CD208D
585                                               25D5C769 200C0000  F6660029 00000000  F666001D 0000FFE3  F6520015 0000FFEB  F652001E 00000000  3FAEF0F7 356EF0B3  394D208D 3E8D20B0
586                                               2597C72B 200C0000  F666001D 0000FFE3  F6660000 0000FFD7  F6520000 0000FFE2  F6520015 0000FFEB  34DEF0AA 309EF006  350D2018 373D206C
587                                               2597C7D5 200C0000  F6660000 0000FFD7  F666FFE3 0000FFE3  F652FFEB 0000FFEB  F6520000 0000FFE2  309EF3FA 34DEF356  373D2394 350D23E8
5881A01B0:                                        25D5C797 200C0000  F666FFE3 0000FFE3  F666FFD7 00000000  F652FFE2 00000000  F652FFEB 0000FFEB  356EF34D 3FAEF309  3E8D2350 394D2373
589                                               252BC797 200C0000  F666FFD7 00000000  F666FFE3 0000001D  F652FFEB 00000015  F652FFE2 00000000  006EF309 0AAEF34D  06CD2373 018D2350
590                                               2569C7D5 200C0000  F666FFE3 0000001D  F6660000 00000029  F6520000 0000001E  F652FFEB 00000015  0B3EF356 0F7EF3FA  0B0D23E8 08DD2394
591                                               2569C72B 200C0000  F6660000 00000029  F666001D 0000001D  F6520015 00000015  F6520000 0000001E  0F7EF006 0B3EF0AA  08DD206C 0B0D2018
5921A01CC:                                        0C018000 311A01CD
593                                               25300076 200C0000  F6660029 00000000  F666001D 0000001D  0429001D 0000001D  04290029 00000000  00FF24FA 0A6F24BB  0A60DCBB 00F0DCFA
5941A01D4:                                        25760030 200C0000  F666001D 0000001D  F6660000 00000029  04290000 00000029  0429001D 0000001D  0BBF24A6 0FAF240F  0FA0DC0F 0BB0DCA6
595                                               257600D0 200C0000  F6660000 00000029  F666FFE3 0000001D  0429FFE3 0000001D  04290000 00000029  0FAF27F1 0BBF275A  0BB0DF5A 0FA0DFF1
596                                               2530008A 200C0000  F666FFE3 0000001D  F666FFD7 00000000  0429FFD7 00000000  0429FFE3 0000001D  0A6F2745 00FF2706  00F0DF06 0A60DF45
597                                               25D0008A 200C0000  F666FFD7 00000000  F666FFE3 0000FFE3  0429FFE3 0000FFE3  0429FFD7 00000000  3F1F2706 35AF2745  35A0DF45 3F10DF06
5981A01F0:                                        258A00D0 200C0000  F666FFE3 0000FFE3  F6660000 0000FFD7  04290000 0000FFD7  0429FFE3 0000FFE3  345F275A 306F27F1  3060DFF1 3450DF5A
599                                               258A0030 200C0000  F6660000 0000FFD7  F666001D 0000FFE3  0429001D 0000FFE3  04290000 0000FFD7  306F240F 345F24A6  3450DCA6 3060DC0F
600                                               0C018000 071A1000  00000000 00000000
6011A1000:                                        25D00076 200C0000  F666001D 0000FFE3  F6660029 00000000  04290029 00000000  0429001D 0000FFE3  35AF24BB 3F1F24FA  3F10DCFA 35A0DCBB
602                                               08000000 00000000
603*/
604
605
606static void render_poly_4bit(void *dest, INT32 scanline, INT32 startx, INT32 stopx, const poly_params *poly, int threadid)
607{
608   poly_extra_data *extra = poly->extra;
609   float ooz = poly_param_value(startx, scanline, 0, poly);
610   float uoz = poly_param_value(startx, scanline, 1, poly);
611   float voz = poly_param_value(startx, scanline, 2, poly);
612   float doozdx = poly->param[0].dpdx;
613   float duozdx = poly->param[1].dpdx;
614   float dvozdx = poly->param[2].dpdx;
615   const UINT32 *texbase = extra->texbase;
616   const UINT32 *palbase = extra->palbase;
617   UINT16 transcolor = extra->transcolor;
618   int texwidth = extra->texwidth;
619   int x;
620
621   for (x = startx; x < stopx; x++)
622   {
623      float z = recip_approx(ooz);
624      int u = (int)(uoz * z) & ((texwidth * 2) - 1);
625      int v = (int)(voz * z) & 255;
626      UINT8 texel = get_texel_4bit(texbase, v, u, texwidth);
627      if (texel != transcolor)
628      {
629         UINT16 color = palbase[texel >> 1] >> (16 * (texel & 1));
630         INT32 depth = z * 256.0f;
631         if (depth > 0x7fff) depth = 0x7fff;
632         if (depth >= 0)
633            waveram_plot_check_depth(scanline, x, color, depth);
634      }
635
636      ooz += doozdx;
637      uoz += duozdx;
638      voz += dvozdx;
639   }
640}
641
642
643static void render_poly_8bit(void *dest, INT32 scanline, INT32 startx, INT32 stopx, const poly_params *poly, int threadid)
644{
645   poly_extra_data *extra = poly->extra;
646   float ooz = poly_param_value(startx, scanline, 0, poly);
647   float uoz = poly_param_value(startx, scanline, 1, poly);
648   float voz = poly_param_value(startx, scanline, 2, poly);
649   float doozdx = poly->param[0].dpdx;
650   float duozdx = poly->param[1].dpdx;
651   float dvozdx = poly->param[2].dpdx;
652   const UINT32 *texbase = extra->texbase;
653   const UINT32 *palbase = extra->palbase;
654   UINT16 transcolor = extra->transcolor;
655   int texwidth = extra->texwidth;
656   int x;
657
658   for (x = startx; x < stopx; x++)
659   {
660      float z = recip_approx(ooz);
661      int u = (int)(uoz * z) & (texwidth - 1);
662      int v = (int)(voz * z) & 255;
663      UINT8 texel = get_texel_8bit(texbase, v, u, texwidth);
664      if (texel != transcolor)
665      {
666         UINT16 color = palbase[texel >> 1] >> (16 * (texel & 1));
667         INT32 depth = z * 256.0f;
668         if (depth > 0x7fff) depth = 0x7fff;
669         if (depth >= 0)
670            waveram_plot_check_depth(scanline, x, color, depth);
671      }
672
673      ooz += doozdx;
674      uoz += duozdx;
675      voz += dvozdx;
676   }
677}
678
679
680static void zeus_draw_polys(UINT32 addr_and_count, UINT32 texdata, int logcmd)
681{
682   static UINT32 *loglist[1000];
683   static int loglist_last = 0;
684   UINT32 *data = waveram_ptr_from_addr(addr_and_count);
685   UINT32 val1, val2;
686   int i, logit = FALSE;
687   int texwshift;
688   int testbit = 0;
689
690   val1 = ((texdata >> 10) & 0x3f0000) | (texdata & 0xffff);
691   val2 = (texdata >> 16) & 0x3ff;
692   texwshift = (val2 >> 6) & 7;
693
694   if (logcmd)
695   {
696      int texwshift = (val2 >> 6) & 7;
697      logerror("Zeus cmd 67 : %08X %08X %03X %06X (w=%d adj=%03X%03X)\n",
698         zeuscmd_buffer[0], addr_and_count, val2, val1,
699         512 >> texwshift,
700         ((val1 << (7 - texwshift)) >> 10) & 0xfff,
701         ((val1 << (7 - texwshift)) >> 1) & 0x1ff
702         );
703   }
704
705   for (i = 0; i < last_tex_index; i++)
706      if (last_tex[i][0] == val1 && last_tex[i][1] == val2)
707         break;
708   if (i == last_tex_index)
709   {
710      last_tex[i][0] = val1;
711      last_tex[i][1] = val2;
712      last_tex_index++;
713   }
714
715   if (logcmd)
716   {
717      for (i = 0; i < loglist_last; i++)
718         if (loglist[i] == data)
719            break;
720      logit = (i == loglist_last);
721      if (i == loglist_last)
722         loglist[loglist_last++] = data;
723   }
724
725   if (input_code_pressed(KEYCODE_Z)) testbit = 1;
726   if (input_code_pressed(KEYCODE_X)) testbit = 2;
727   if (input_code_pressed(KEYCODE_C)) testbit = 3;
728   if (input_code_pressed(KEYCODE_V)) testbit = 4;
729   if (input_code_pressed(KEYCODE_B)) testbit = 5;
730   if (input_code_pressed(KEYCODE_N)) testbit = 6;
731   if (input_code_pressed(KEYCODE_M)) testbit = 7;
732
733   if (testbit != 0)
734      texwshift = testbit;
735
736   while (1)
737   {
738      const UINT32 *data = waveram_ptr_from_addr(addr_and_count);
739      int count = ((addr_and_count >> 24) + 1) * 2;
740      UINT32 next_addr_and_count = 0;
741      int datanum;
742      int length;
743
744      for (datanum = 0; datanum < count; datanum += length * 2)
745      {
746         int offs;
747
748         length = ((data[datanum] >> 24) == 0x25 || (data[datanum] >> 24) == 0x30) ? 7 : 1;
749
750         if (logit)
751         {
752            logerror("\t%08X", data[datanum]);
753            for (offs = 1; offs < length * 2; offs++)
754               logerror(" %08X", data[datanum + offs]);
755            logerror("\n");
756         }
757
758         if ((data[datanum] >> 24) == 0x25 || (data[datanum] >> 24) == 0x30 /* invasn */)
759         {
760            poly_draw_scanline callback;
761            poly_extra_data *extra;
762            poly_vertex vert[4];
763            int i;
764
765            callback = (val2 & 0x20) ? render_poly_8bit : render_poly_4bit;
766
767            for (i = 0; i < 4; i++)
768            {
769               UINT32 ixy = data[datanum + 2 + 2*i];
770               UINT32 iuvz = data[datanum + 3 + 2*i];
771               INT32 xo = (INT16)ixy;
772               INT32 yo = (INT16)(ixy >> 16);
773               INT32 zo = (INT16)iuvz;
774               UINT8 u = iuvz >> 16;
775               UINT8 v = iuvz >> 24;
776               float z, ooz;
777
778               vert[i].x = (xo * zeus_matrix[0][0] + yo * zeus_matrix[0][1] + zo * zeus_matrix[0][2] + zeus_point[0]) * (1.0f / 65536.0f);
779               vert[i].y = (xo * zeus_matrix[1][0] + yo * zeus_matrix[1][1] + zo * zeus_matrix[1][2] + zeus_point[1]) * (1.0f / 65536.0f);
780               z = (xo * zeus_matrix[2][0] + yo * zeus_matrix[2][1] + zo * zeus_matrix[2][2] + zeus_point[2]) * (1.0f / (512.0f * 65536.0f));
781
782               ooz = 1.0f / z;
783               vert[i].x *= ooz;
784               vert[i].y *= ooz;
785               vert[i].p[0] = ooz;
786               vert[i].p[1] = u * ooz;
787               vert[i].p[2] = v * ooz;
788
789               vert[i].x += 200.0f;
790               vert[i].y += 128.0f;
791            }
792
793            val1 <<= 7 - texwshift;
794
795            extra = poly_get_extra_data(poly);
796            extra->transcolor = 0x100;
797            extra->texbase = &waveram[val1 & 0x3fffff];
798            extra->texwidth = 512 >> texwshift;
799            extra->palbase = zeus_palbase;
800            extra->alpha = zeus_blend;
801            poly_render_triangle(poly, NULL, &Machine->screen[0].visarea, callback, 3, &vert[0], &vert[1], &vert[2]);
802
803            /* skip empty if not a full quad */
804            if (vert[2].x != vert[3].x || vert[2].y != vert[3].y)
805            {
806               extra = poly_get_extra_data(poly);
807               extra->transcolor = 0x100;
808               extra->texbase = &waveram[val1 & 0x3fffff];
809               extra->texwidth = 512 >> texwshift;
810               extra->palbase = zeus_palbase;
811               extra->alpha = zeus_blend;
812               poly_render_triangle(poly, NULL, &Machine->screen[0].visarea, callback, 3, &vert[0], &vert[2], &vert[3]);
813            }
814
815            poly_wait(poly, "Normal");
816         }
817         else if (data[datanum] == 0x0c018000)
818            next_addr_and_count = data[datanum + 1];
819      }
820      if (datanum != count)
821         logerror("Overran data\n");
822
823      if (next_addr_and_count == 0)
824         break;
825      else
826         addr_and_count = next_addr_and_count;
827   }
828}
829
830
831static void zeuscmd_execute(void)
832{
833   static int colorcount;
834   int logcmd = input_code_pressed(KEYCODE_L);
835   int wordnum;
836
837   switch (zeuscmd_buffer[0] >> 24)
838   {
839      case 0x1c:
840         if (logcmd)
841            logerror("Zeus cmd 1C : ( %04X %04X %04X ) ( %04X %04X %04X ) ( %04X %04X %04X ) %8.2f %8.2f %8.5f\n",
842               zeuscmd_buffer[2] & 0xffff,
843               zeuscmd_buffer[2] >> 16,
844               zeuscmd_buffer[0] & 0xffff,
845               zeuscmd_buffer[3] & 0xffff,
846               zeuscmd_buffer[3] >> 16,
847               zeuscmd_buffer[1] >> 16,
848               zeuscmd_buffer[4] & 0xffff,
849               zeuscmd_buffer[4] >> 16,
850               zeuscmd_buffer[1] & 0xffff,
851               (float)(INT32)zeuscmd_buffer[5] * (1.0f / 65536.0f),
852               (float)(INT32)zeuscmd_buffer[6] * (1.0f / 65536.0f),
853               (float)(INT32)zeuscmd_buffer[7] * (1.0f / (65536.0f * 512.0f)));
854
855         zeus_matrix[0][0] = zeuscmd_buffer[2];
856         zeus_matrix[0][1] = zeuscmd_buffer[2] >> 16;
857         zeus_matrix[0][2] = zeuscmd_buffer[0];
858         zeus_matrix[1][0] = zeuscmd_buffer[3];
859         zeus_matrix[1][1] = zeuscmd_buffer[3] >> 16;
860         zeus_matrix[1][2] = zeuscmd_buffer[1] >> 16;
861         zeus_matrix[2][0] = zeuscmd_buffer[4];
862         zeus_matrix[2][1] = zeuscmd_buffer[4] >> 16;
863         zeus_matrix[2][2] = zeuscmd_buffer[1];
864         zeus_point[0] = zeuscmd_buffer[5];
865         zeus_point[1] = zeuscmd_buffer[6];
866         zeus_point[2] = zeuscmd_buffer[7];
867         break;
868
869      case 0x13:   /* invasn */
870         zeus_draw_polys(zeus_objdata, zeus_texdata, logcmd);
871         break;
872
873      case 0x67:
874         zeus_draw_polys(zeuscmd_buffer[1], zeuscmd_buffer[2], logcmd);
875         break;
876
877      case 0x01:   /* invasn */
878         if (logcmd)
879            logerror("Zeus cmd %02X : %08X %08X\n", zeuscmd_buffer[0] >> 24, zeuscmd_buffer[0], zeuscmd_buffer[1]);
880         if (zeuscmd_buffer[0] == 0x01008000)
881            zeus_objdata = zeuscmd_buffer[1];
882         else if (zeuscmd_buffer[0] == 0x0100c0b0)
883            zeus_texdata = zeuscmd_buffer[1];
884         else if (zeuscmd_buffer[0] == 0x0100C040)
885            zeus_palbase = waveram_ptr_from_addr(zeuscmd_buffer[1]);
886         break;
887
888      default:
889         if ((zeuscmd_buffer[0] >> 16) == 0x1752)
890         {
891            zeusbase[0xb2] = zeuscmd_buffer[0];
892//              zeus_enable_logging = 1;
893         }
894         if ((zeuscmd_buffer[0] >> 16) == 0x1770)
895            zeus_point[0] = zeuscmd_buffer[0] << 16;
896         if ((zeuscmd_buffer[0] >> 16) == 0x1772)
897            zeus_point[1] = zeuscmd_buffer[0] << 16;
898         if ((zeuscmd_buffer[0] >> 16) == 0x1774)
899            zeus_point[2] = zeuscmd_buffer[0] << 16;
900         if ((zeuscmd_buffer[0] >> 16) == 0x18ce)
901            zeus_blend = zeuscmd_buffer[1];
902
903         if (zeuscmd_buffer[0] == 0x0000c040)
904            zeus_palbase = waveram_ptr_from_addr(zeuscmd_buffer[1]);
905
906         if (zeuscmd_buffer[0] == 0x0080C0A5)
907         {
908            /* not right -- just a hack */
909            int x, y;
910            for (y = 0; y <= 255; y++)
911               for (x = 0; x <= 399; x++)
912                  waveram_plot_depth(y, x, 0, 0x7fff);
913            colorcount = 0;
914            last_tex_index = 0;
915         }
916
917         if (logcmd)
918         {
919            logerror("Zeus cmd %02X : %08X", zeuscmd_buffer[0] >> 24, zeuscmd_buffer[0]);
920            for (wordnum = 1; wordnum < zeuscmd_buffer_expected_words; wordnum++)
921               logerror(" %08X", zeuscmd_buffer[wordnum]);
922            logerror("\n");
923         }
924         break;
925   }
926}
927
928
929static UINT8 zeuscmd_length(UINT32 word)
930{
931   switch (word >> 24)
932   {
933      case 0x00:
934      case 0x01:
935         return (word == 0) ? 1 : 2;
936
937      case 0x13:
938      case 0x17:
939      case 0x1a:
940      case 0x2d:      /* invasn */
941      case 0x70:
942         return 1;
943
944      case 0x18:
945      case 0x23:
946      case 0x2e:      /* invasn */
947         return 2;
948
949      case 0x67:
950         return 3;
951
952      case 0x25:
953      case 0x30:      /* invasn */
954         return 4;   /* ??? */
955
956      case 0x1c:
957         return 8;
958
959      default:
960         printf("Unknown command %02X\n", zeusbase[0xe0] >> 24);
961         break;
962   }
963   return 1;
964}
965
966
967READ32_HANDLER( zeus_r )
968{
969   int logit = (offset < 0xb0 || offset > 0xb7);
970   UINT32 result = zeusbase[offset & ~1];
971
972   switch (offset & ~1)
973   {
974      case 0x00:
975         // crusnexo wants bit 0x20 to be non-zero
976         result = 0x20;
977         break;
978
979      case 0x51:
980         // crusnexo expects a reflection of the data at 0x08 here (b425)
981         result = zeusbase[0x08];
982         break;
983
984      case 0xf2:
985         // polled frequently during gametime; expected to change often
986         // as it is polled multiple times and a consistent value is looked for
987         result = video_screen_get_vpos(0);
988         logit = 0;
989         break;
990
991      case 0xf4:
992         result = 6;
993         if (video_screen_get_vblank(0))
994            result |= 0x800;
995         logit = 0;
996         break;
997
998      case 0xf6:      // status -- they wait for this & 9 == 0
999         if (zeusbase[0xb6] == 0x80040000)
1000            result = 1;
1001         else
1002            result = 0;
1003         logit = 0;
1004         break;
1005   }
1006
1007   /* 32-bit mode */
1008   if (zeusbase[0x80] & 0x00020000)
1009   {
1010      if (offset & 1)
1011         result >>= 16;
1012      if (logit)
1013      {
1014         if (offset & 1)
1015            logerror("%06X:zeus32_r(%02X) = %08X -- unexpected in 32-bit mode\n", activecpu_get_pc(), offset, result);
1016         else if (offset != 0xe0)
1017            logerror("%06X:zeus32_r(%02X) = %08X\n", activecpu_get_pc(), offset, result);
1018         else
1019            logerror("%06X:zeus32_r(%02X) = %08X\n", activecpu_get_pc(), offset, result);
1020      }
1021   }
1022
1023   /* 16-bit mode */
1024   else
1025   {
1026      if (offset & 1)
1027         result >>= 16;
1028      else
1029         result &= 0xffff;
1030      if (logit)
1031         logerror("%06X:zeus16_r(%02X) = %04X\n", activecpu_get_pc(), offset, result);
1032   }
1033   return result;
1034}
1035
1036
1037WRITE32_HANDLER( zeus_w )
1038{
1039   int logit = zeus_enable_logging || ((offset < 0xb0 || offset > 0xb7) && (offset < 0xe0 || offset > 0xe1));
1040
1041   /* 32-bit mode */
1042   if (zeusbase[0x80] & 0x00020000)
1043   {
1044      zeusbase[offset & ~1] = data;
1045
1046      if (logit)
1047      {
1048         if (offset & 1)
1049            logerror("%06X:zeus32_w(%02X) = %08X -- unexpected in 32-bit mode\n", activecpu_get_pc(), offset, data);
1050         else if (offset != 0xe0)
1051            logerror("%06X:zeus32_w(%02X) = %08X\n", activecpu_get_pc(), offset, data);
1052         else
1053            logerror("%06X:zeus32_w(%02X) = %08X\n", activecpu_get_pc(), offset, data);
1054      }
1055   }
1056
1057   /* 16-bit mode */
1058   else
1059   {
1060      if (offset & 1)
1061         zeusbase[offset & ~1] = (zeusbase[offset & ~1] & 0x0000ffff) | (data << 16);
1062      else
1063         zeusbase[offset & ~1] = (zeusbase[offset & ~1] & 0xffff0000) | (data & 0xffff);
1064
1065      if (logit)
1066         logerror("%06X:zeus16_w(%02X) = %04X [%08X]\n", activecpu_get_pc(), offset, data & 0xffff, zeusbase[offset & ~1]);
1067   }
1068
1069   /* handle the writes; only trigger on low accesses */
1070   switch (offset)
1071   {
1072      case 0x60:
1073         /* invasn writes here to execute a command (?) */
1074         if (zeusbase[0x60] & 1)
1075         {
1076            if (zeusbase[0x80] == 0x0022FCFF)
1077            {
1078               int startx, stopx, starty, stopy;
1079               int x, y;
1080               // zeusbase[0x00] = color
1081               // zeusbase[0x02] = ??? = 0x000C0000
1082               // zeusbase[0x04] = ??? = 0x00000E01
1083               // zeusbase[0x06] = ??? = 0xFFFF0030
1084               // zeusbase[0x08] = vert[0] = (y0 << 16) | x0
1085               // zeusbase[0x0a] = vert[1] = (y1 << 16) | x1
1086               // zeusbase[0x0c] = vert[2] = (y2 << 16) | x2
1087               // zeusbase[0x0e] = vert[3] = (y3 << 16) | x3
1088               // zeusbase[0x18] = ??? = 0xFFFFFFFF
1089               // zeusbase[0x1a] = ??? = 0xFFFFFFFF
1090               // zeusbase[0x1c] = ??? = 0xFFFFFFFF
1091               // zeusbase[0x1e] = ??? = 0xFFFFFFFF
1092               // zeusbase[0x20] = ??? = 0x00000000
1093               // zeusbase[0x22] = ??? = 0x00000000
1094               // zeusbase[0x24] = ??? = 0x00000000
1095               // zeusbase[0x26] = ??? = 0x00000000
1096               // zeusbase[0x40] = ??? = 0x00000000
1097               // zeusbase[0x42] = ??? = 0x00000000
1098               // zeusbase[0x44] = ??? = 0x00000000
1099               // zeusbase[0x46] = ??? = 0x00000000
1100               // zeusbase[0x4c] = ??? = 0x00808080 (brightness?)
1101               // zeusbase[0x4e] = ??? = 0x00808080 (brightness?)
1102               startx = (zeusbase[0x08] & 0xffff);
1103               starty = zeusbase[0x08] >> 16;
1104               stopx = (zeusbase[0x0c] & 0xffff);
1105               stopy = zeusbase[0x0c] >> 16;
1106               for (y = starty; y <= stopy; y++)
1107                  for (x = startx; x <= stopx; x++)
1108                     waveram[(1 * WAVERAM_HEIGHT + (y % WAVERAM_HEIGHT)) * WAVERAM_WIDTH + x] = zeusbase[0x00];
1109            }
1110            else
1111               logerror("Execute unknown command\n");
1112         }
1113         break;
1114
1115      case 0xb0:
1116      case 0xb2:
1117         if ((zeusbase[0xb6] >> 16) != 0)
1118         {
1119            UINT32 *dest = zeus_pixaddr();
1120            if ((offset == 0xb0 && (zeusbase[0xb6] & 0x02000000) == 0) ||
1121               (offset == 0xb2 && (zeusbase[0xb6] & 0x02000000) != 0))
1122            {
1123               if (zeusbase[0xb6] & 0x00100000)
1124                  dest[0] = (dest[0] & 0xffff0000) | (zeusbase[0xb0] & 0x0000ffff);
1125               if (zeusbase[0xb6] & 0x00200000)
1126                  dest[0] = (dest[0] & 0x0000ffff) | (zeusbase[0xb0] & 0xffff0000);
1127               if (zeusbase[0xb6] & 0x00400000)
1128                  dest[1] = (dest[1] & 0xffff0000) | (zeusbase[0xb2] & 0x0000ffff);
1129               if (zeusbase[0xb6] & 0x00800000)
1130                  dest[1] = (dest[1] & 0x0000ffff) | (zeusbase[0xb2] & 0xffff0000);
1131               if (zeusbase[0xb6] & 0x00020000)
1132                  zeusbase[0xb4]++;
1133            }
1134         }
1135         break;
1136
1137      case 0xb4:
1138         if (zeusbase[0xb6] & 0x00010000)
1139         {
1140            UINT32 *src = zeus_pixaddr();
1141            zeusbase[0xb0] = src[0];
1142            zeusbase[0xb2] = src[1];
1143         }
1144         break;
1145
1146      case 0xe0:
1147         zeuscmd_buffer[zeuscmd_buffer_words++] = zeusbase[0xe0];
1148         if (zeuscmd_buffer_words == 1)
1149            zeuscmd_buffer_expected_words = zeuscmd_length(zeusbase[0xe0]);
1150         if (zeuscmd_buffer_words == zeuscmd_buffer_expected_words)
1151         {
1152            zeuscmd_execute();
1153            zeuscmd_buffer_words = 0;
1154         }
1155         break;
1156   }
1157}
1158
1159
1160READ32_HANDLER( zeus2_r )
1161{
1162   return zeus_r(offset * 2, 0);
1163}
1164
1165
1166WRITE32_HANDLER( zeus2_w )
1167{
1168   zeus_w(offset * 2, data, mem_mask);
1169}
src/mame/video/gaelco3d.c
r1215r1216
77**************************************************************************/
88
99#include "driver.h"
10#include "eminline.h"
1011#include "gaelco3d.h"
12#include "video/rgbutil.h"
1113#include "video/polynew.h"
1214
1315UINT8 *gaelco3d_texture;
r1215r1216
1921#define MAX_POLYGONS      4096
2022#define MAX_POLYDATA      (MAX_POLYGONS * 21)
2123
22#define BILINEAR_FILTER      1         /* should be 1, but can be set to 0 for speed */
23
2424#define DISPLAY_TEXTURE      0
2525#define LOG_POLYGONS      0
2626#define DISPLAY_STATS      0
r1215r1216
3030
3131static mame_bitmap *screenbits;
3232static mame_bitmap *zbuffer;
33static UINT16 *palette;
33static rgb_t *palette;
3434static UINT32 *polydata_buffer;
3535static UINT32 polydata_count;
3636
r1215r1216
258258   mame_bitmap *bitmap = destbase;
259259   UINT16 *dest = BITMAP_ADDR16(bitmap, scanline, 0);
260260   UINT16 *zbuf = BITMAP_ADDR16(zbuffer, scanline, 0);
261   float zbase = 1.0f / extra->ooz_base;
262   float uoz = (extra->uoz_base + scanline * extra->uoz_dy + startx * extra->uoz_dx) * zbase;
263   float voz = (extra->voz_base + scanline * extra->voz_dy + startx * extra->voz_dx) * zbase;
264   float uoz_step = extra->uoz_dx * zbase;
265   float voz_step = extra->voz_dx * zbase;
261   float zbase = recip_approx(extra->ooz_base);
262   float zbase256 = 256.0f * zbase;
263   float uoz = (extra->uoz_base + scanline * extra->uoz_dy + startx * extra->uoz_dx) * zbase256;
264   float voz = (extra->voz_base + scanline * extra->voz_dy + startx * extra->voz_dx) * zbase256;
265   float uoz_step = extra->uoz_dx * zbase256;
266   float voz_step = extra->voz_dx * zbase256;
266267   int zbufval = (int)(-extra->z0 * zbase);
267268   offs_t endmask = gaelco3d_texture_size - 1;
268   UINT16 color = extra->color;
269   const rgb_t *palsource = palette + extra->color;
269270   UINT32 tex = extra->tex;
270271   int x;
271272
272273   for (x = startx; x < stopx; x++)
273274   {
274      int pixeloffs, u, v;
275
276      if (!BILINEAR_FILTER)
275      int u = (int)uoz;
276      int v = (int)voz;
277      int pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
278      if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
277279      {
278         u = (int)(uoz + 0.5f); v = (int)(voz + 0.5f);
279         pixeloffs = (tex + v * 4096 + u) & endmask;
280         if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
281         {
282            dest[x] = palette[color | gaelco3d_texture[pixeloffs]];
283            zbuf[x] = zbufval;
284         }
280         rgb_t rgb00 = palsource[gaelco3d_texture[pixeloffs]];
281         rgb_t rgb01 = palsource[gaelco3d_texture[(pixeloffs + 1) & endmask]];
282         rgb_t rgb10 = palsource[gaelco3d_texture[(pixeloffs + 4096) & endmask]];
283         rgb_t rgb11 = palsource[gaelco3d_texture[(pixeloffs + 4097) & endmask]];
284         rgb_t filtered = rgb_bilinear_filter(rgb00, rgb01, rgb10, rgb11, u, v);
285         dest[x] = (filtered & 0x1f) | ((filtered & 0x1ff800) >> 6);
286         zbuf[x] = zbufval;
285287      }
286      else
287      {
288         u = (int)(uoz * 256.0f); v = (int)(voz * 256.0f);
289         pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
290         if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
291         {
292            int paldata, r, g, b, f, tf;
293288
294            paldata = palette[color | gaelco3d_texture[pixeloffs]];
295            tf = f = (~u & 0xff) * (~v & 0xff);
296            r = (paldata & 0x7c00) * f; g = (paldata & 0x03e0) * f; b = (paldata & 0x001f) * f;
297
298            paldata = palette[color | gaelco3d_texture[(pixeloffs + 1) & endmask]];
299            tf += f = (u & 0xff) * (~v & 0xff);
300            r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
301
302            paldata = palette[color | gaelco3d_texture[(pixeloffs + 4096) & endmask]];
303            tf += f = (~u & 0xff) * (v & 0xff);
304            r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
305
306            paldata = palette[color | gaelco3d_texture[(pixeloffs + 4097) & endmask]];
307            f = 0x10000 - tf;
308            r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
309
310            dest[x] = ((r >> 16) & 0x7c00) | ((g >> 16) & 0x03e0) | (b >> 16);
311            zbuf[x] = zbufval;
312         }
313      }
314
315289      /* advance texture params to the next pixel */
316290      uoz += uoz_step;
317291      voz += voz_step;
r1215r1216
326300   UINT16 *dest = BITMAP_ADDR16(bitmap, scanline, 0);
327301   UINT16 *zbuf = BITMAP_ADDR16(zbuffer, scanline, 0);
328302   float ooz_dx = extra->ooz_dx;
329   float uoz_dx = extra->uoz_dx;
330   float voz_dx = extra->voz_dx;
303   float uoz_dx = extra->uoz_dx * 256.0f;
304   float voz_dx = extra->voz_dx * 256.0f;
331305   float ooz = extra->ooz_base + scanline * extra->ooz_dy + startx * ooz_dx;
332   float uoz = extra->uoz_base + scanline * extra->uoz_dy + startx * uoz_dx;
333   float voz = extra->voz_base + scanline * extra->voz_dy + startx * voz_dx;
306   float uoz = (extra->uoz_base + scanline * extra->uoz_dy) * 256.0f + startx * uoz_dx;
307   float voz = (extra->voz_base + scanline * extra->voz_dy) * 256.0f + startx * voz_dx;
334308   offs_t endmask = gaelco3d_texture_size - 1;
335   UINT16 color = extra->color;
309   const rgb_t *palsource = palette + extra->color;
336310   UINT32 tex = extra->tex;
337311   float z0 = extra->z0;
338312   int x;
r1215r1216
342316      if (ooz > 0)
343317      {
344318         /* compute Z and check the Z buffer value first */
345         float z = 1.0f / ooz;
319         float z = recip_approx(ooz);
346320         int zbufval = (int)(z0 * z);
347         if (zbufval < zbuf[x] || zbufval < 0)
321         if (zbufval < zbuf[x])
348322         {
349            int pixeloffs, u, v;
350
351            if (!BILINEAR_FILTER)
323            int u = (int)(uoz * z);
324            int v = (int)(voz * z);
325            int pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
326            if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
352327            {
353               u = (int)(uoz * z + 0.5f); v = (int)(voz * z + 0.5f);
354               pixeloffs = (tex + v * 4096 + u) & endmask;
355               if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
356               {
357                  dest[x] = palette[color | gaelco3d_texture[pixeloffs]];
358                  zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
359               }
328               rgb_t rgb00 = palsource[gaelco3d_texture[pixeloffs]];
329               rgb_t rgb01 = palsource[gaelco3d_texture[(pixeloffs + 1) & endmask]];
330               rgb_t rgb10 = palsource[gaelco3d_texture[(pixeloffs + 4096) & endmask]];
331               rgb_t rgb11 = palsource[gaelco3d_texture[(pixeloffs + 4097) & endmask]];
332               rgb_t filtered = rgb_bilinear_filter(rgb00, rgb01, rgb10, rgb11, u, v);
333               dest[x] = (filtered & 0x1f) | ((filtered & 0x1ff800) >> 6);
334               zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
360335            }
361            else
362            {
363               u = (int)(uoz * z * 256.0f); v = (int)(voz * z * 256.0f);
364               pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
365               if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
366               {
367                  int paldata, r, g, b, f, tf;
368
369                  paldata = palette[color | gaelco3d_texture[pixeloffs]];
370                  tf = f = (~u & 0xff) * (~v & 0xff);
371                  r = (paldata & 0x7c00) * f; g = (paldata & 0x03e0) * f; b = (paldata & 0x001f) * f;
372
373                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 1) & endmask]];
374                  tf += f = (u & 0xff) * (~v & 0xff);
375                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
376
377                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 4096) & endmask]];
378                  tf += f = (~u & 0xff) * (v & 0xff);
379                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
380
381                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 4097) & endmask]];
382                  f = 0x10000 - tf;
383                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
384
385                  dest[x] = ((r >> 16) & 0x7c00) | ((g >> 16) & 0x03e0) | (b >> 16);
386                  zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
387               }
388            }
389336         }
390337      }
391338
r1215r1216
404351   UINT16 *dest = BITMAP_ADDR16(bitmap, scanline, 0);
405352   UINT16 *zbuf = BITMAP_ADDR16(zbuffer, scanline, 0);
406353   float ooz_dx = extra->ooz_dx;
407   float uoz_dx = extra->uoz_dx;
408   float voz_dx = extra->voz_dx;
354   float uoz_dx = extra->uoz_dx * 256.0f;
355   float voz_dx = extra->voz_dx * 256.0f;
409356   float ooz = extra->ooz_base + extra->ooz_dy * scanline + startx * ooz_dx;
410   float uoz = extra->uoz_base + extra->uoz_dy * scanline + startx * uoz_dx;
411   float voz = extra->voz_base + extra->voz_dy * scanline + startx * voz_dx;
357   float uoz = (extra->uoz_base + extra->uoz_dy * scanline) * 256.0f + startx * uoz_dx;
358   float voz = (extra->voz_base + extra->voz_dy * scanline) * 256.0f + startx * voz_dx;
412359   offs_t endmask = gaelco3d_texture_size - 1;
413   UINT16 color = extra->color;
360   const rgb_t *palsource = palette + extra->color;
414361   UINT32 tex = extra->tex;
415362   float z0 = extra->z0;
416363   int x;
r1215r1216
420367      if (ooz > 0)
421368      {
422369         /* compute Z and check the Z buffer value first */
423         float z = 1.0f / ooz;
370         float z = recip_approx(ooz);
424371         int zbufval = (int)(z0 * z);
425         if (zbufval < zbuf[x] || zbufval < 0)
372         if (zbufval < zbuf[x])
426373         {
427            int pixeloffs, u, v;
428
429            if (!BILINEAR_FILTER)
374            int u = (int)(uoz * z);
375            int v = (int)(voz * z);
376            int pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
377            if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
430378            {
431               u = (int)(uoz * z + 0.5f); v = (int)(voz * z + 0.5f);
432               pixeloffs = (tex + v * 4096 + u) & endmask;
433               if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
434               {
435                  dest[x] = ((dest[x] >> 1) & 0x3def) + ((palette[color | gaelco3d_texture[pixeloffs]] >> 1) & 0x3def);
436                  zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
437               }
379               rgb_t rgb00 = palsource[gaelco3d_texture[pixeloffs]];
380               rgb_t rgb01 = palsource[gaelco3d_texture[(pixeloffs + 1) & endmask]];
381               rgb_t rgb10 = palsource[gaelco3d_texture[(pixeloffs + 4096) & endmask]];
382               rgb_t rgb11 = palsource[gaelco3d_texture[(pixeloffs + 4097) & endmask]];
383               rgb_t filtered = rgb_bilinear_filter(rgb00, rgb01, rgb10, rgb11, u, v) >> 1;
384               dest[x] = ((filtered & 0x0f) | ((filtered & 0x0f7800) >> 6)) + ((dest[x] >> 1) & 0x3def);
385               zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
438386            }
439            else
440            {
441               u = (int)(uoz * z * 256.0f); v = (int)(voz * z * 256.0f);
442               pixeloffs = (tex + (v >> 8) * 4096 + (u >> 8)) & endmask;
443               if (pixeloffs >= gaelco3d_texmask_size || !gaelco3d_texmask[pixeloffs])
444               {
445                  int paldata, r, g, b, f, tf;
446
447                  paldata = palette[color | gaelco3d_texture[pixeloffs]];
448                  tf = f = (~u & 0xff) * (~v & 0xff);
449                  r = (paldata & 0x7c00) * f; g = (paldata & 0x03e0) * f; b = (paldata & 0x001f) * f;
450
451                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 1) & endmask]];
452                  tf += f = (u & 0xff) * (~v & 0xff);
453                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
454
455                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 4096) & endmask]];
456                  tf += f = (~u & 0xff) * (v & 0xff);
457                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
458
459                  paldata = palette[color | gaelco3d_texture[(pixeloffs + 4097) & endmask]];
460                  f = 0x10000 - tf;
461                  r += (paldata & 0x7c00) * f; g += (paldata & 0x03e0) * f; b += (paldata & 0x001f) * f;
462
463                  paldata = ((r >> 17) & 0x7c00) | ((g >> 17) & 0x03e0) | (b >> 17);
464                  dest[x] = ((dest[x] >> 1) & 0x3def) + (paldata & 0x3def);
465                  zbuf[x] = (zbufval < 0) ? -zbufval : zbufval;
466               }
467            }
468387         }
469388      }
470389
r1215r1216
542461{
543462   poly_wait(poly, "Palette change");
544463   COMBINE_DATA(&paletteram16[offset]);
545   palette[offset] = paletteram16[offset];
464   palette[offset] = ((paletteram16[offset] & 0x7fe0) << 6) | (paletteram16[offset] & 0x1f);
546465}
547466
548467
r1215r1216
550469{
551470   poly_wait(poly, "Palette change");
552471   COMBINE_DATA(&paletteram32[offset]);
553   palette[offset*2+0] = paletteram32[offset] >> 16;
554   palette[offset*2+1] = paletteram32[offset];
472   palette[offset*2+0] = ((paletteram32[offset] & 0x7fe00000) >> 10) | ((paletteram32[offset] & 0x1f0000) >> 16);
473   palette[offset*2+1] = ((paletteram32[offset] & 0x7fe0) << 6) | (paletteram32[offset] & 0x1f);
555474}
556475
557476
src/mame/video/namcos22.c
r1215r1216
3434*/
3535
3636#include "driver.h"
37#include "eminline.h"
38#include "video/rgbutil.h"
3739#include "namcos22.h"
3840#include "video/polynew.h"
3941#include <math.h>
r1215r1216
241243   return mpTextureTileData[(tile<<8)|mXYAttrToPixel[mpTextureTileMapAttr[offs]][x&0xf][y&0xf]];
242244} /* texel */
243245
246
247
244248typedef struct _poly_extra_data poly_extra_data;
245249struct _poly_extra_data
246250{
r1215r1216
248252   int bn;
249253   UINT16 flags;
250254   int cmode;
255   int fogFactor;
256   rgbint fogColor;
257   int fadeFactor;
258   rgbint fadeColor;
251259   const UINT8 *source;      /* sprites */
252260   int z;
253261   int alpha;
r1215r1216
255263   int line_modulo;
256264};
257265
266
258267static void renderscanline_uvi_full(void *dest, INT32 scanline, INT32 startx, INT32 stopx, const poly_params *poly, int threadid)
259268{
260269   mame_bitmap *bitmap = dest;
261270   poly_extra_data *extra = poly->extra;
262   UINT16 flags = extra->flags;
263   int cmode = extra->cmode;
264271   int bn = extra->bn;
265   int fadeEnable = (mixer.target&1) && mixer.fadeFactor;
266   int fogDisable = extra->color&0x80;
267272   const pen_t *pens = &Machine->pens[(extra->color&0x7f)<<8];
268   int fogDensity = 0;
269   int prioverchar = (cmode&7)==1;
273   int prioverchar;
270274
271275   const UINT8 *pCharPri = BITMAP_ADDR8(priority_bitmap, scanline, 0);
272276   UINT32 *pDest = BITMAP_ADDR32(bitmap, scanline, 0);
r1215r1216
278282   float dv = poly->param[1].dpdx;
279283   float di = poly->param[2].dpdx;
280284   float dz = poly->param[3].dpdx;
285   int fogFactor = extra->fogFactor;
286   int fadeFactor = extra->fadeFactor;
287   rgbint fogColor = extra->fogColor;
288   rgbint fadeColor = extra->fadeColor;
289   int penmask, penshift;
281290   int x;
282291   bn *= 0x1000;
283292
284   if( mbSuperSystem22 )
293   if (extra->cmode & 4)
285294   {
286      if( !fogDisable )
287      {
288         int cz = flags>>8;
289         static const int cztype_remap[4] = { 3,1,2,0 };
290         int cztype = flags&3;
291         if( nthword(namcos22_czattr,4)&(0x4000>>(cztype*4)) )
292         {
293            int fogDelta = (INT16)nthword(namcos22_czattr, cztype);
294            //          if( fogDelta == 0x8000 ) fogDelta = -0x7fff;
295            //cz = Clamp256(cz+fogDelta);
296            fogDensity = fogDelta + namcos22_czram[cztype_remap[cztype]][cz];
297            if( fogDensity<0x0000 )
298            {
299               fogDensity = 0x0000;
300            }
301            else if( fogDensity>0x1fff )
302            {
303               fogDensity = 0x1fff;
304            }
305         }
306      }
295      prioverchar = 0;
296      pens += 0xec + ((extra->cmode & 8) << 1);
297      penmask = 0x03;
298      penshift = 2 * ~(extra->cmode & 3);
307299   }
300   else if (extra->cmode & 2)
301   {
302      prioverchar = 0;
303      pens += 0xe0 + ((extra->cmode & 8) << 1);
304      penmask = 0x0f;
305      penshift = 4 * ~(extra->cmode & 1);
306   }
307   else if (extra->cmode & 1)
308   {
309      prioverchar = 1;
310      penmask = 0xff;
311      penshift = 0;
312   }
308313   else
309314   {
310      fogDisable = 1;
315      prioverchar = 0;
316      penmask = 0xff;
317      penshift = 0;
311318   }
312319
313320   for( x=startx; x<stopx; x++ )
314321   {
315322      if( pCharPri[x]==0 || prioverchar )
316323      {
317         float ooz = 1.0f/z;
324         float ooz = recip_approx(z);
318325         int pen = texel((int)(u * ooz),bn+(int)(v*ooz));
319         switch( cmode )
320         {
321            case 0x2:
322               pen = 0xe0|(pen>>4);
323               break;
324            case 0x3:
325               pen = 0xe0|(pen&0xf);
326               break;
327            case 0x4:
328               pen = 0xec|(pen>>6);
329               break;
330            case 0x5:
331               pen = 0xec|((pen>>4)&3);
332               break;
333            case 0x6:
334               pen = 0xec|((pen>>2)&3);
335               break;
336            case 0x7:
337               pen = 0xec|(pen&3);
338               break;
339            case 0xa:
340               pen = 0xf0|(pen>>4);
341               break;
342            case 0xb:
343               pen = 0xf0|(pen&0xf);
344               break;
345            case 0xc:
346               pen = 0xfc|(pen>>6);
347               break;
348            case 0xd:
349               pen = 0xfc|((pen>>4)&3);
350               break;
351            case 0xe:
352               pen = 0xfc|((pen>>2)&3);
353               break;
354            case 0xf:
355               pen = 0xfc|(pen&3);
356               break;
357            default:
358               break;
359         }
326         int shade = i*ooz;
327         rgbint rgb;
360328
329         rgb_to_rgbint(&rgb, pens[(pen >> penshift) & penmask]);
330         rgbint_scale_and_clamp(&rgb, shade << 2);
331
332         if( fogFactor != 0 )
333            rgbint_blend(&rgb, &fogColor, 0xff - fogFactor);
334
335         if( fadeFactor != 0 )
336            rgbint_blend(&rgb, &fadeColor, 0xff - fadeFactor);
337
338         if( prioverchar )
361339         {
362            UINT32 rgb = pens[pen];
363            int shade = i*ooz;
364            int r = rgb>>16;
365            int g = (rgb>>8)&0xff;
366            int b = rgb&0xff;
367            r = r*shade/0x40;
368            if( r>0xff ) r = 0xff;
369            g = g*shade/0x40;
370            if( g>0xff ) g = 0xff;
371            b = b*shade/0x40;
372            if( b>0xff ) b = 0xff;
373            if( !fogDisable )
374            {
375               int fogDensity2 = 0x2000 - fogDensity;
376               r = (r*fogDensity2 + fogDensity*mixer.rFogColor)>>13;
377               g = (g*fogDensity2 + fogDensity*mixer.gFogColor)>>13;
378               b = (b*fogDensity2 + fogDensity*mixer.bFogColor)>>13;
379            }
380            if( fadeEnable )
381            {
382               int fade2 = 0x100-mixer.fadeFactor;
383               r = (r*fade2+mixer.fadeFactor*mixer.rFadeColor)>>8;
384               g = (g*fade2+mixer.fadeFactor*mixer.gFadeColor)>>8;
385               b = (b*fade2+mixer.fadeFactor*mixer.bFadeColor)>>8;
386            }
387            if( prioverchar )
388            {
389               UINT32 color = pDest[x];
390               int tr = color>>16;
391               int tg = (color>>8)&0xff;
392               int tb = color&0xff;
393               int trans1 = 0x100 - mixer.poly_translucency;
394               r = (tr*mixer.poly_translucency + r*trans1)>>8;
395               g = (tg*mixer.poly_translucency + g*trans1)>>8;
396               b = (tb*mixer.poly_translucency + b*trans1)>>8;
397            }
398            rgb = (r<<16)|(g<<8)|b;
399            pDest[x] = rgb;
340            rgbint dest;
341            rgb_to_rgbint(&dest, pDest[x]);
342            rgbint_blend(&rgb, &dest, 0xff - mixer.poly_translucency);
400343         }
344
345         pDest[x] = rgbint_to_rgb(&rgb);
401346      }
402347
403348      u += du;
r1215r1216
444389   extra->bn = bn;
445390   extra->flags = flags;
446391   extra->cmode = cmode;
392   extra->fogFactor = 0;
393   extra->fadeFactor = 0;
447394
448   poly_render_triangle(poly, bitmap, clip, renderscanline_uvi_full, 4, &vert[0], &vert[1], &vert[2]);
395   if (mixer.target&1)
396   {
397      extra->fadeFactor = mixer.fadeFactor;
398      rgb_comp_to_rgbint(&extra->fadeColor, mixer.rFadeColor, mixer.gFadeColor, mixer.bFadeColor);
399   }
449400
401   if( mbSuperSystem22 )
402   {
403      if( !(color&0x80) )
404      {
405         int cz = flags>>8;
406         static const int cztype_remap[4] = { 3,1,2,0 };
407         int cztype = flags&3;
408         if( nthword(namcos22_czattr,4)&(0x4000>>(cztype*4)) )
409         {
410            int fogDelta = (INT16)nthword(namcos22_czattr, cztype);
411            int fogDensity = fogDelta + namcos22_czram[cztype_remap[cztype]][cz];
412            //          if( fogDelta == 0x8000 ) fogDelta = -0x7fff;
413            //cz = Clamp256(cz+fogDelta);
414            if( fogDensity<0x0000 )
415            {
416               fogDensity = 0x0000;
417            }
418            else if( fogDensity>0x1fff )
419            {
420               fogDensity = 0x1fff;
421            }
422            extra->fogFactor = fogDensity >> 5;
423            rgb_comp_to_rgbint(&extra->fogColor, mixer.rFogColor, mixer.gFogColor, mixer.bFogColor);
424         }
425      }
426   }
427
428   poly_render_triangle(poly, bitmap, clip, renderscanline_uvi_full, 4, &vert[0], &vert[1], &vert[2]);
450429} /* rendertri */
451430
452431static void
src/mame/video/skykid.c
r1215r1216
33UINT8 *skykid_textram, *skykid_videoram, *skykid_spriteram;
44
55static tilemap *bg_tilemap,*tx_tilemap;
6static int priority,scroll_x,scroll_y;
6static UINT8 priority;
7static UINT16 scroll_x,scroll_y;
78
89
910/***************************************************************************
r1215r1216
135136   spriteram = skykid_spriteram + 0x780;
136137   spriteram_2 = spriteram + 0x0800;
137138   spriteram_3 = spriteram_2 + 0x0800;
139
140   state_save_register_global(priority);
141   state_save_register_global(scroll_x);
142   state_save_register_global(scroll_y);
143   state_save_register_global(flip_screen);
138144}
139145
140146
src/mame/tiny.mak
r1215r1216
6666
6767DRVLIBS = \
6868   $(MAMEOBJ)/tiny.o \
69   $(MACHINE)/6821pia.o \
70   $(MACHINE)/7474.o \
71   $(MACHINE)/74148.o \
72   $(MACHINE)/74153.o \
7369   $(MACHINE)/ticket.o \
74   $(MACHINE)/z80ctc.o \
7570   $(DRIVERS)/carpolo.o $(MACHINE)/carpolo.o $(VIDEO)/carpolo.o \
7671   $(DRIVERS)/circus.o $(AUDIO)/circus.o $(VIDEO)/circus.o \
7772   $(DRIVERS)/exidy.o $(AUDIO)/exidy.o $(VIDEO)/exidy.o \
src/mame/drivers/bfcobra.c
r1215r1216
975975
976976static void z80_acia_irq(int state)
977977{
978   cpunum_set_input_line(0, 0, state ? HOLD_LINE : CLEAR_LINE);
978   cpunum_set_input_line(0, 0, state ? CLEAR_LINE : ASSERT_LINE);
979979}
980980
981981static void m6809_data_irq(int state)
982982{
983   cpunum_set_input_line(1, M6809_IRQ_LINE, state ? HOLD_LINE : CLEAR_LINE);
983   cpunum_set_input_line(1, M6809_IRQ_LINE, state ? CLEAR_LINE : ASSERT_LINE);
984984}
985985
986986static struct acia6850_interface z80_acia_if =
r1215r1216
989989   500000,
990990   &m6809_z80_line,
991991   &z80_m6809_line,
992   NULL,
993   NULL,
994   NULL,
992995   z80_acia_irq
993996};
994997
r1215r1216
9981001   500000,
9991002   &z80_m6809_line,
10001003   &m6809_z80_line,
1004   NULL,
1005   NULL,
1006   NULL,
10011007   NULL
10021008};
10031009
r1215r1216
10071013   500000,
10081014   &data_r,
10091015   &data_t,
1016   NULL,
1017   NULL,
1018   NULL,
10101019   m6809_data_irq
10111020};
10121021
src/mame/drivers/senjyo.c
r1215r1216
649649
650650
651651
652static struct Samplesinterface custom_interface =
652static struct Samplesinterface senjyo_samples_interface =
653653{
654654   1,
655655   NULL,
r1215r1216
700700   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
701701
702702   MDRV_SOUND_ADD(SAMPLES, 0)
703   MDRV_SOUND_CONFIG(custom_interface)
703   MDRV_SOUND_CONFIG(senjyo_samples_interface)
704704   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.15)
705705MACHINE_DRIVER_END
706706
src/mame/drivers/hornet.c
r1215r1216
10891089         rdata[rdata_ptr++] = 0x01;      // report data (normal)
10901090         break;
10911091      }
1092      case 0xfa:
1093      {
1094         break;
1095      }
10921096      default:
10931097      {
10941098         fatalerror("jamma_jvs_cmd_exec: unknown command %02X\n", data[0]);
r1215r1216
13831387ROM_START(sscope)
13841388   ROM_REGION32_BE(0x400000, REGION_USER1, 0)   /* PowerPC program */
13851389   ROM_LOAD16_WORD_SWAP("ss1-1.27p", 0x200000, 0x200000, CRC(3b6bb075) SHA1(babc134c3a20c7cdcaa735d5f1fd5cab38667a14))
1390   ROM_RELOAD(0x000000, 0x200000)
13861391
13871392   ROM_REGION32_BE(0x800000, REGION_USER2, ROMREGION_ERASE00)   /* Data roms */
13881393
r1215r1216
14011406ROM_START(sscopea)
14021407   ROM_REGION32_BE(0x400000, REGION_USER1, 0)   /* PowerPC program */
14031408   ROM_LOAD16_WORD_SWAP("830_a01.bin", 0x200000, 0x200000, CRC(39e353f1) SHA1(569b06969ae7a690f6d6e63cc3b5336061663a37))
1409   ROM_RELOAD(0x000000, 0x200000)
14041410
14051411   ROM_REGION32_BE(0x800000, REGION_USER2, ROMREGION_ERASE00)   /* Data roms */
14061412
r1215r1216
14191425ROM_START(sscope2)
14201426   ROM_REGION32_BE(0x400000, REGION_USER1, 0)   /* PowerPC program */
14211427   ROM_LOAD16_WORD_SWAP("931d01.bin", 0x200000, 0x200000, CRC(4065fde6) SHA1(84f2dedc3e8f61651b22c0a21433a64993e1b9e2))
1428   ROM_RELOAD(0x000000, 0x200000)
14221429
14231430   ROM_REGION32_BE(0x800000, REGION_USER2, 0)   /* Data roms */
14241431      ROM_LOAD32_WORD_SWAP("931a04.bin", 0x000000, 0x200000, CRC(4f5917e6) SHA1(a63a107f1d6d9756e4ab0965d72ea446f0692814))
r1215r1216
14411448ROM_START(gradius4)
14421449   ROM_REGION32_BE(0x400000, REGION_USER1, 0)   /* PowerPC program */
14431450        ROM_LOAD16_WORD_SWAP( "837c01.27p",   0x200000, 0x200000, CRC(ce003123) SHA1(15e33997be2c1b3f71998627c540db378680a7a1) )
1451        ROM_RELOAD(0x000000, 0x200000)
14441452
14451453   ROM_REGION32_BE(0x800000, REGION_USER2, 0)   /* Data roms */
14461454        ROM_LOAD32_WORD_SWAP( "837a04.16t",   0x000000, 0x200000, CRC(18453b59) SHA1(3c75a54d8c09c0796223b42d30fb3867a911a074) )
r1215r1216
14631471ROM_START(nbapbp)
14641472   ROM_REGION32_BE(0x400000, REGION_USER1, 0)   /* PowerPC program */
14651473        ROM_LOAD16_WORD_SWAP( "778a01.27p",   0x200000, 0x200000, CRC(e70019ce) SHA1(8b187b6e670fdc88771da08a56685cd621b139dc) )
1474        ROM_RELOAD(0x000000, 0x200000)
14661475
14671476   ROM_REGION32_BE(0x800000, REGION_USER2, 0)   /* Data roms */
14681477        ROM_LOAD32_WORD_SWAP( "778a04.16t",   0x000000, 0x400000, CRC(62c70132) SHA1(405aed149fc51e0adfa3ace3c644e47d53cf1ee3) )
src/mame/drivers/midzeus.c
r1215r1216
1818#include "driver.h"
1919#include "cpu/tms34010/tms34010.h"
2020#include "cpu/adsp2100/adsp2100.h"
21#include "includes/midzeus.h"
2122#include "machine/midwayic.h"
2223#include "audio/dcs.h"
2324
r1215r1216
2829static mame_timer *timer[2];
2930
3031static UINT32 *tms32031_control;
31static UINT32 *graphics_ram;
3232
3333
34//------------------------------
3534
36#define WAVERAM_WIDTH   512
37#define WAVERAM_HEIGHT   4096
38
39static UINT32 *waveram;
40
41
42VIDEO_START( midzeus )
43{
44   int i;
45
46   waveram = auto_malloc(2 * WAVERAM_WIDTH * WAVERAM_HEIGHT * sizeof(*waveram));
47
48   for (i = 0; i < 32768; i++)
49      palette_set_color_rgb(machine, i, pal5bit(i >> 10), pal5bit(i >> 5), pal5bit(i >> 0));
50}
51
52VIDEO_UPDATE( midzeus )
53{
54   static int yoffs = 0;
55   int p = input_code_pressed(KEYCODE_0) ? 0 : 1;
56   int x, y;
57   if (input_code_pressed(KEYCODE_DOWN) && input_code_pressed(KEYCODE_LCONTROL)) yoffs += 8;
58   if (input_code_pressed(KEYCODE_UP) && input_code_pressed(KEYCODE_LCONTROL)) yoffs -= 8;
59   for (y = cliprect->min_y; y <= cliprect->max_y; y++)
60   {
61      UINT32 *src = &waveram[(p * WAVERAM_HEIGHT + ((y + yoffs) % WAVERAM_HEIGHT)) * WAVERAM_WIDTH + 0];
62      UINT16 *dest = (UINT16 *)bitmap->base + y * bitmap->rowpixels;
63      for (x = cliprect->min_x; x <= cliprect->max_x; x++)
64         dest[x] = src[x] & 0x7fff;
65   }
66   return 0;
67}
68
69/*
70    offset B7 = control....
71
72        8000 = page 1 enable
73        4000 = page 0 enable
74
75        0080 = 2nd pixel enable (maybe Z buff?)
76        0040 = 1st pixel enable (maybe Z buff?)
77        0020 = 2nd pixel enable
78        0010 = 1st pixel enable
79
80
81    writes 80a2 to write an odd pixel at startup
82    writes 80f6 to write the middle pixels
83    writes 8052 to write an odd pixel at the end
84
85    writes 8050 before writing an odd pixel
86    writes 80a0 before writing an even pixel
87
88    writes 44f1 before reading from page 0 of wave ram
89    writes 84f1 before reading from page 1 of wave ram
90
91    writes 42f0 before writing to page 0 of wave ram
92    writes 82f0 before writing to page 1 of wave ram
93
94
95Initialization:
9601BFF4:graphics_w(080) = 0020F023
9701BFF1:graphics_w(081) = 00000020
9801C03E:graphics_w(080) = 00000000
9901C03E:graphics_w(081) = 00008200
10001C03E:graphics_w(08F) = 00000206
10101C03E:graphics_w(08E) = 00000000
10201C03E:graphics_w(08B) = 00000000
10301C03E:graphics_w(08A) = 0000FAFA
10401C03E:graphics_w(08D) = 00000206
10501C03E:graphics_w(08C) = 00000000
10601C03E:graphics_w(089) = 00000000
10701C03E:graphics_w(088) = 0000FAFA
10801C03E:graphics_w(080) = 00000001
10901C03E:graphics_w(0CF) = 000000C8
11001C03E:graphics_w(0CE) = 00007620
11101C03E:graphics_w(0CD) = 00000000
11201C03E:graphics_w(0CC) = 00000000
11301C03E:graphics_w(0CB) = 00000116   = VTOTAL(?)
11401C03E:graphics_w(0CA) = 00000107   = VSYNC END
11501C03E:graphics_w(0C9) = 00000103   = VSYNC START
11601C03E:graphics_w(0C8) = 000000FF   = VBSTART
11701C03E:graphics_w(0C7) = 00000211
11801C03E:graphics_w(0C6) = 0000007F
11901C03E:graphics_w(0C5) = 0000000C
12001C03E:graphics_w(0C4) = 00000042
12101C03E:graphics_w(0C3) = 00000015
12201C03E:graphics_w(0C2) = 0000E591
12301C03E:graphics_w(0C1) = 0000801F
12401C03E:graphics_w(0C0) = 00002500
12501C03E:graphics_w(086) = 00008003
12601C03E:graphics_w(080) = 00000C05
12701C03E:graphics_w(085) = 00000000
12801C03E:graphics_w(084) = 00000000
12901C03E:graphics_w(083) = 00001F1F
13001C03E:graphics_w(082) = 00002011
13101C03E:graphics_w(069) = 00000003
13201C03E:graphics_w(069) = 00000000
13301C03E:graphics_w(08D) = 00000227
13401C03E:graphics_w(08C) = 0000BFFF
13501C03E:graphics_w(08D) = 00000226
13601C03E:graphics_w(08C) = 00000000
13701C03E:graphics_w(08D) = 00000227
13801C03E:graphics_w(08C) = 0000BFFF
13901C03E:graphics_w(08D) = 00000226
14001C03E:graphics_w(08C) = 00000000
14101C03E:graphics_w(08D) = 00000227
14201C03E:graphics_w(08C) = 0000F020
14301C03E:graphics_w(08D) = 00000226
14401C03E:graphics_w(08C) = 00000000
14501C03E:graphics_w(08D) = 00000227
14601C03E:graphics_w(08C) = 0000DFFF
14701C03E:graphics_w(08D) = 00000226
14801C03E:graphics_w(08C) = 00000000
14901C03E:graphics_w(08D) = 00000227
15001C03E:graphics_w(08C) = 0000DFFF
15101C03E:graphics_w(08D) = 00000226
15201C03E:graphics_w(08C) = 00000000
15301C03E:graphics_w(08F) = 00000207
15401C03E:graphics_w(08E) = 0000BFFF
15501C03E:graphics_w(08F) = 00000206
15601C03E:graphics_w(08E) = 00000000
15701C03E:graphics_w(08F) = 00000207
15801C03E:graphics_w(08E) = 0000F020
15901C03E:graphics_w(08F) = 00000206
16001C03E:graphics_w(08E) = 00000000
16101C03E:graphics_w(08F) = 00000207
16201C03E:graphics_w(08E) = 0000DFFF
16301C03E:graphics_w(08F) = 00000206
16401C03E:graphics_w(08E) = 00000000
16501C03E:graphics_w(08F) = 00000207
16601C03E:graphics_w(08E) = 0000DFFF
16701C03E:graphics_w(08F) = 00000206
16801C03E:graphics_w(08E) = 00000000
16901C03E:graphics_w(08F) = 00000206
17001C03E:graphics_w(08E) = 00000000
17101C03E:graphics_w(08D) = 00000226
17201C03E:graphics_w(08C) = 00000000
17301C03E:graphics_w(08B) = 00000000
17401C03E:graphics_w(08A) = 0000D254
17501C03E:graphics_w(089) = 00000000
17601C03E:graphics_w(088) = 0000D794
177
178then:
17901C2CE:graphics_w(0B7) = 00000000
18001C2D0:graphics_w(0B6) = 00000001
18101C2D1:graphics_w(0B0) = 00000000
18201C2D2:graphics_w(0B1) = 00000000
18301C2D3:graphics_w(0B2) = 00007FFF
18401C2D4:graphics_w(0B3) = 00007FFF
18501C2D8:graphics_w(0B5) = 000000FF  y
18601C2DD:graphics_w(0B4) = 00000100  x/yhi
18701C2EA:graphics_w(0B7) = FFFF80F6  page 1
18801C2EB:graphics_w(0B0) = 00000000
18901C2EC:graphics_r(0F6)
19001C2F4:graphics_w(0B0) = 00000000 x 256
191
19201C2F6:graphics_w(0B7) = FFFF8052
19301C2CE:graphics_w(0B7) = 00000000
19401C2D0:graphics_w(0B6) = 00000001
19501C2D1:graphics_w(0B0) = 00000000
19601C2D2:graphics_w(0B1) = 00000000
19701C2D3:graphics_w(0B2) = 00007FFF
19801C2D4:graphics_w(0B3) = 00007FFF
19901C2D8:graphics_w(0B5) = 000000FF  y
20001C2DD:graphics_w(0B4) = 00000000  x/yhi
20101C2EA:graphics_w(0B7) = FFFF80F6
20201C2EB:graphics_w(0B0) = 00000000
20301C2EC:graphics_r(0F6)
20401C2F4:graphics_w(0B0) = 00000000 x 256
205
206etc. to clear all scanlines on page 1
207
208then:
20901C2F6:graphics_w(0B7) = FFFF8052
21001BFF4:graphics_w(080) = 00200001
21101C1B6:graphics_w(0CF) = 000000C9
21201BFF4:graphics_w(080) = 00200C27
21301C1BC:graphics_w(0CF) = 000000C8
21401BFF4:graphics_w(080) = 0020F023
21501BFF1:graphics_w(081) = 00000020
21601BFF1:graphics_w(081) = 00000022
21701BFF4:graphics_w(080) = 0022F023
218
21901C0DB:graphics_w(200) = 00000E00
22001C0DB:graphics_w(202) = 00000025
22101C0DB:graphics_w(204) = 00000E01
22201C0DB:graphics_w(206) = 00000025
22301C0DB:graphics_w(208) = 00000E02
22401C0DB:graphics_w(20A) = 00000025
22501C0DB:graphics_w(20C) = 00000E03
22601C0DB:graphics_w(20E) = 00000025
22701C0DB:graphics_w(210) = 00000E04
22801C0DB:graphics_w(212) = 00000025
22901C0DB:graphics_w(214) = 00000E05
23001C0DB:graphics_w(216) = 00000025
23101C0DB:graphics_w(218) = 00000E06
23201C0DB:graphics_w(21A) = 00000025
23301C0DB:graphics_w(21C) = 00000E07
23401C0DB:graphics_w(21E) = 00000025
23501C0DB:graphics_w(220) = 00000E08
23601C0DB:graphics_w(222) = 00000025
23701C0DB:graphics_w(224) = 00000E09
23801C0DB:graphics_w(226) = 00000025
23901C0DB:graphics_w(228) = 00000E0A
24001C0DB:graphics_w(22A) = 00000025
24101C0DB:graphics_w(22C) = 00000E0B
24201C0DB:graphics_w(22E) = 00000025
24301C0DB:graphics_w(230) = 00000E0C
24401C0DB:graphics_w(232) = 00000025
24501C0DB:graphics_w(234) = 00000E0D
24601C0DB:graphics_w(236) = 00000025
24701C0DB:graphics_w(238) = 00000E0E
24801C0DB:graphics_w(23A) = 00000025
24901C0DB:graphics_w(23C) = 00000E0F
25001C0DB:graphics_w(23E) = 00000025
25101C0DB:graphics_w(240) = 00000E10
25201C0DB:graphics_w(242) = 00000025
25301C0DB:graphics_w(244) = 00000E11
25401C0DB:graphics_w(246) = 00000025
25501C0DB:graphics_w(248) = 00000E12
25601C0DB:graphics_w(24A) = 00000025
25701C0DB:graphics_w(24C) = 00000E13
25801C0DB:graphics_w(24E) = 00000025
25901C0DB:graphics_w(250) = 00000E14
26001C0DB:graphics_w(252) = 00000025
26101C0DB:graphics_w(254) = 00000E15
26201C0DB:graphics_w(256) = 00000025
26301C0DB:graphics_w(258) = 00000E16
26401C0DB:graphics_w(25A) = 00000025
26501C0DB:graphics_w(25C) = 00000E17
26601C0DB:graphics_w(25E) = 00000025
26701C0DB:graphics_w(260) = 00000E18
26801C0DB:graphics_w(262) = 00000025
26901C0DB:graphics_w(264) = 00000E19
27001C0DB:graphics_w(266) = 00000025
27101C0DB:graphics_w(268) = 00000E1A
27201C0DB:graphics_w(26A) = 00000025
27301C0DB:graphics_w(26C) = 00000E1B
27401C0DB:graphics_w(26E) = 00000025
27501C0DB:graphics_w(270) = 00000E1C
27601C0DB:graphics_w(272) = 00000025
27701C0DB:graphics_w(274) = 00000E1D
27801C0DB:graphics_w(276) = 00000025
27901C0DB:graphics_w(278) = 00000E1E
28001C0DB:graphics_w(27A) = 00000025
28101C0DB:graphics_w(27C) = 00000E1F
28201C0DB:graphics_w(27E) = 00000025
28301C0DB:graphics_w(280) = 00000E20
28401C0DB:graphics_w(282) = 00000025
28501C0DB:graphics_w(284) = 00000E21
28601C0DB:graphics_w(286) = 00000025
28701C0DB:graphics_w(288) = 00000E22
28801C0DB:graphics_w(28A) = 00000025
28901C0DB:graphics_w(28C) = 00000E23
29001C0DB:graphics_w(28E) = 00000025
29101C0DB:graphics_w(290) = 00000E24
29201C0DB:graphics_w(292) = 00000025
29301C0DB:graphics_w(294) = 00000E25
29401C0DB:graphics_w(296) = 00000025
29501C0DB:graphics_w(298) = 00000E26
29601C0DB:graphics_w(29A) = 00000025
29701C0DB:graphics_w(29C) = 00000E27
29801C0DB:graphics_w(29E) = 00000025
29901C0DB:graphics_w(2A0) = 00000E28
30001C0DB:graphics_w(2A2) = 00000025
30101C0DB:graphics_w(2A4) = 00000E29
30201C0DB:graphics_w(2A6) = 00000025
30301C0DB:graphics_w(2A8) = 00000E2A
30401C0DB:graphics_w(2AA) = 00000025
30501C0DB:graphics_w(2AC) = 00000E2B
30601C0DB:graphics_w(2AE) = 00000025
30701C0DB:graphics_w(2B0) = 00000E2C
30801C0DB:graphics_w(2B2) = 00000025
30901C0DB:graphics_w(2B4) = 00000E2D
31001C0DB:graphics_w(2B6) = 00000025
31101C0DB:graphics_w(2B8) = 00000E2E
31201C0DB:graphics_w(2BA) = 00000025
31301C0DB:graphics_w(2BC) = 00000E2F
31401C0DB:graphics_w(2BE) = 00000025
31501C0DB:graphics_w(2C0) = 00000E30
31601C0DB:graphics_w(2C2) = 00000025
31701C0DB:graphics_w(2C4) = 00000E31
31801C0DB:graphics_w(2C6) = 00000025
31901C0DB:graphics_w(2C8) = 00000E32
32001C0DB:graphics_w(2CA) = 00000025
32101C0DB:graphics_w(2CC) = 00000E33
32201C0DB:graphics_w(2CE) = 00000025
32301C0DB:graphics_w(2D0) = 00000E34
32401C0DB:graphics_w(2D2) = 00000025
32501C0DB:graphics_w(2D4) = 00000E35
32601C0DB:graphics_w(2D6) = 00000025
32701C0DB:graphics_w(2D8) = 00000E36
32801C0DB:graphics_w(2DA) = 00000025
32901C0DB:graphics_w(2DC) = 00000E37
33001C0DB:graphics_w(2DE) = 00000025
33101C0DB:graphics_w(2E0) = 00000E38
33201C0DB:graphics_w(2E2) = 00000025
33301C0DB:graphics_w(2E4) = 00000E39
33401C0DB:graphics_w(2E6) = 00000025
33501C0DB:graphics_w(2E8) = 00000E3A
33601C0DB:graphics_w(2EA) = 00000025
33701C0DB:graphics_w(2EC) = 00000E3B
33801C0DB:graphics_w(2EE) = 00000025
33901C0DB:graphics_w(2F0) = 00000E3C
34001C0DB:graphics_w(2F2) = 00000025
34101C0DB:graphics_w(2F4) = 00000E3D
34201C0DB:graphics_w(2F6) = 00000025
34301C0DB:graphics_w(2F8) = 00000E3E
34401C0DB:graphics_w(2FA) = 00000025
34501C0DB:graphics_w(2FC) = 00000E3F
34601C0DB:graphics_w(2FE) = 00000025
34701C0DB:graphics_w(300) = 00000E40
34801C0DB:graphics_w(302) = 00000025
34901C0DB:graphics_w(304) = 00000E41
35001C0DB:graphics_w(306) = 00000025
35101C0DB:graphics_w(308) = 00000E42
35201C0DB:graphics_w(30A) = 00000025
35301C0DB:graphics_w(30C) = 00000E43
35401C0DB:graphics_w(30E) = 00000025
35501C0DB:graphics_w(310) = 00000E44
35601C0DB:graphics_w(312) = 00000025
35701C0DB:graphics_w(314) = 00000E45
35801C0DB:graphics_w(316) = 00000025
35901C0DB:graphics_w(318) = 00000E46
36001C0DB:graphics_w(31A) = 00000025
36101C0DB:graphics_w(31C) = 00000E47
36201C0DB:graphics_w(31E) = 00000025
36301C0DB:graphics_w(320) = 00000E48
36401C0DB:graphics_w(322) = 00000025
36501C0DB:graphics_w(324) = 00000E49
36601C0DB:graphics_w(326) = 00000025
36701C0DB:graphics_w(328) = 00000E4A
36801C0DB:graphics_w(32A) = 00000025
36901C0DB:graphics_w(32C) = 00000E4B
37001C0DB:graphics_w(32E) = 00000025
37101C0DB:graphics_w(330) = 00000E4C
37201C0DB:graphics_w(332) = 00000025
37301C0DB:graphics_w(334) = 00000E4D
37401C0DB:graphics_w(336) = 00000025
37501C0DB:graphics_w(338) = 00000E4E
37601C0DB:graphics_w(33A) = 00000025
37701C0DB:graphics_w(33C) = 00000E4F
37801C0DB:graphics_w(33E) = 00000025
37901C0DB:graphics_w(340) = 00000E50
38001C0DB:graphics_w(342) = 00000025
38101C0DB:graphics_w(344) = 00000E51
38201C0DB:graphics_w(346) = 00000025
38301C0DB:graphics_w(348) = 00000E52
38401C0DB:graphics_w(34A) = 00000025
38501C0DB:graphics_w(34C) = 00000E53
38601C0DB:graphics_w(34E) = 00000025
38701C0DB:graphics_w(350) = 00000E54
38801C0DB:graphics_w(352) = 00000025
38901C0DB:graphics_w(354) = 00000E55
39001C0DB:graphics_w(356) = 00000025
39101C0DB:graphics_w(358) = 00000E56
39201C0DB:graphics_w(35A) = 00000025
39301C0DB:graphics_w(35C) = 00000E57
39401C0DB:graphics_w(35E) = 00000025
39501C0DB:graphics_w(360) = 00000E58
39601C0DB:graphics_w(362) = 00000025
39701C0DB:graphics_w(364) = 00000E59
39801C0DB:graphics_w(366) = 00000025
39901C0DB:graphics_w(368) = 00000E5A
40001C0DB:graphics_w(36A) = 00000025
40101C0DB:graphics_w(36C) = 00000E5B
40201C0DB:graphics_w(36E) = 00000025
40301C0DB:graphics_w(370) = 00000E5C
40401C0DB:graphics_w(372) = 00000025
40501C0DB:graphics_w(374) = 00000E5D
40601C0DB:graphics_w(376) = 00000025
40701C0DB:graphics_w(378) = 00000E5E
40801C0DB:graphics_w(37A) = 00000025
40901C0DB:graphics_w(37C) = 00000E5F
41001C0DB:graphics_w(37E) = 00000025
41101C0DB:graphics_w(380) = 00000E60
41201C0DB:graphics_w(382) = 00000025
41301C0DB:graphics_w(384) = 00000E61
41401C0DB:graphics_w(386) = 00000025
41501C0DB:graphics_w(388) = 00000E62
41601C0DB:graphics_w(38A) = 00000025
41701C0DB:graphics_w(38C) = 00000E63
41801C0DB:graphics_w(38E) = 00000025
41901C0DB:graphics_w(390) = 00000E64
42001C0DB:graphics_w(392) = 00000025
42101C0DB:graphics_w(394) = 00000E65
42201C0DB:graphics_w(396) = 00000025
42301C0DB:graphics_w(398) = 00000E66
42401C0DB:graphics_w(39A) = 00000025
42501C0DB:graphics_w(39C) = 00000E67
42601C0DB:graphics_w(39E) = 00000025
42701C0DB:graphics_w(3A0) = 00000E68
42801C0DB:graphics_w(3A2) = 00000025
42901C0DB:graphics_w(3A4) = 00000E69
43001C0DB:graphics_w(3A6) = 00000025
43101C0DB:graphics_w(3A8) = 00000E6A
43201C0DB:graphics_w(3AA) = 00000025
43301C0DB:graphics_w(3AC) = 00000E6B
43401C0DB:graphics_w(3AE) = 00000025
43501C0DB:graphics_w(3B0) = 00000E6C
43601C0DB:graphics_w(3B2) = 00000025
43701C0DB:graphics_w(3B4) = 00000E6D
43801C0DB:graphics_w(3B6) = 00000025
43901C0DB:graphics_w(3B8) = 00000E6E
44001C0DB:graphics_w(3BA) = 00000025
44101C0DB:graphics_w(3BC) = 00000E6F
44201C0DB:graphics_w(3BE) = 00000025
44301C0DB:graphics_w(3C0) = 00000E70
44401C0DB:graphics_w(3C2) = 00000025
44501C0DB:graphics_w(3C4) = 00000E71
44601C0DB:graphics_w(3C6) = 00000025
44701C0DB:graphics_w(3C8) = 00000E72
44801C0DB:graphics_w(3CA) = 00000025
44901C0DB:graphics_w(3CC) = 00000E73
45001C0DB:graphics_w(3CE) = 00000025
45101C0DB:graphics_w(3D0) = 00000E74
45201C0DB:graphics_w(3D2) = 00000025
45301C0DB:graphics_w(3D4) = 00000E75
45401C0DB:graphics_w(3D6) = 00000025
45501C0DB:graphics_w(3D8) = 00000E76
45601C0DB:graphics_w(3DA) = 00000025
45701C0DB:graphics_w(3DC) = 00000E77
45801C0DB:graphics_w(3DE) = 00000025
45901C0DB:graphics_w(3E0) = 00000E78
46001C0DB:graphics_w(3E2) = 00000025
46101C0DB:graphics_w(3E4) = 00000E79
46201C0DB:graphics_w(3E6) = 00000025
46301C0DB:graphics_w(3E8) = 00000E7A
46401C0DB:graphics_w(3EA) = 00000025
46501C0DB:graphics_w(3EC) = 00000E7B
46601C0DB:graphics_w(3EE) = 00000025
46701C0DB:graphics_w(3F0) = 00000E7C
46801C0DB:graphics_w(3F2) = 00000025
46901C0DB:graphics_w(3F4) = 00000E7D
47001C0DB:graphics_w(3F6) = 00000025
47101C0DB:graphics_w(3F8) = 00000E7E
47201C0DB:graphics_w(3FA) = 00000025
47301C0DB:graphics_w(3FC) = 00000E7F
47401C0DB:graphics_w(3FE) = 00000025
475
47601BFB6:graphics_w(05A) = 00000000
47701BFB8:graphics_w(058) = 3F000000
47801BFB9:graphics_r(0F6)
47901BFBE:graphics_w(0E0) = 00000000
48001BFF4:graphics_w(080) = 0022F02B
48101BFC2:graphics_w(068) = 00030000
48201BFC4:graphics_w(068) = 00000000
48301C052:graphics_w(08A) = 8FFFD254
48401C054:graphics_w(088) = 87FFD794
48501BFF4:graphics_w(080) = 0022FC2B
486
487(other stuff)
488
489loop over each scanline:
490    A2DD19:graphics_w(0B7) = 00000000
491    A2DD24:graphics_w(0B6) = 82F00001
492    A2DD30:graphics_r(0F6)
493    A2DD34:graphics_w(0B4) = 01FF0000
494    A2DD37:graphics_w(0B0) = AAAAAAAA
495    A2DD39:graphics_w(0B2) = AAAAAAAA
496    A2DD30:graphics_r(0F6)
497    A2DD34:graphics_w(0B4) = 01FF0001
498    A2DD37:graphics_w(0B0) = AAAAAAAA
499    A2DD39:graphics_w(0B2) = AAAAAAAA
500    A2DD30:graphics_r(0F6)
501    ...
502    A2DD34:graphics_w(0B4) = 01FF01FE
503    A2DD37:graphics_w(0B0) = AAAAAAAA
504    A2DD39:graphics_w(0B2) = AAAAAAAA
505    A2DD30:graphics_r(0F6)
506    A2DD34:graphics_w(0B4) = 01FF01FF
507    A2DD37:graphics_w(0B0) = AAAAAAAA
508    A2DD39:graphics_w(0B2) = AAAAAAAA
509    A2DD45:graphics_w(0B6) = 00000000
510    A2DD58:graphics_w(0B6) = 00000000
511    A2DD6E:graphics_w(0B6) = 84F10001
512    A2DD6F:graphics_w(0B4) = 01FF0000
513    A2DD71:graphics_r(0F6)
514    A2DD76:graphics_w(0B6) = 00000000
515    A2DD77:graphics_r(0B0)
516    A2DD79:graphics_r(0B2)
517    A2DD6E:graphics_w(0B6) = 84F10001
518    A2DD6F:graphics_w(0B4) = 01FF0001
519    A2DD71:graphics_r(0F6)
520    A2DD76:graphics_w(0B6) = 00000000
521    A2DD77:graphics_r(0B0)
522    A2DD79:graphics_r(0B2)
523    ...
524    A2DD6E:graphics_w(0B6) = 84F10001
525    A2DD6F:graphics_w(0B4) = 01FF01FE
526    A2DD71:graphics_r(0F6)
527    A2DD76:graphics_w(0B6) = 00000000
528    A2DD77:graphics_r(0B0)
529    A2DD79:graphics_r(0B2)
530    A2DD6E:graphics_w(0B6) = 84F10001
531    A2DD6F:graphics_w(0B4) = 01FF01FF
532    A2DD71:graphics_r(0F6)
533    A2DD76:graphics_w(0B6) = 00000000
534    A2DD77:graphics_r(0B0)
535    A2DD79:graphics_r(0B2)
536    A2DD82:graphics_w(0B6) = 00000000
537    A2DD19:graphics_w(0B7) = 00000000
538    A2DD24:graphics_w(0B6) = 82F00001
539    A2DD30:graphics_r(0F6)
540
541repeat with 55555555....
542
543repeat with ffffffff....
544
545repeat with 00000000....
546
547A2DD82:graphics_w(0B6) = 00000000
548A2DCAF:graphics_w(0B6) = 00000000
549A2DCB3:graphics_w(0B2) = 7FFF7FFF
550A2DCB7:graphics_w(0B0) = 00000000
551A2DCC2:graphics_w(0B4) = 007F0100
552A2DCCD:graphics_w(0B6) = 80F20001
553A2DD89:graphics_w(0B0) = 00000000
554A2DD8A:graphics_r(0F6)            \  ... x256
555A2DD89:graphics_w(0B0) = 00000000 /
556
557A2DCAF:graphics_w(0B6) = 00000000
558A2DCB3:graphics_w(0B2) = 7FFF7FFF
559A2DCB7:graphics_w(0B0) = 00000000
560A2DCC2:graphics_w(0B4) = 007F0000
561A2DCCD:graphics_w(0B6) = 80F20001
562A2DD89:graphics_w(0B0) = 00000000
563A2DD8A:graphics_r(0F6)            \  ... x256
564A2DD89:graphics_w(0B0) = 00000000 /
565
566drawing:
567A2DCEB:graphics_w(0B6) = 00000000
568A2DCEF:graphics_w(0B2) = 7FFF7FFF
569A2DCF3:graphics_w(0B0) = 001F001F
570A2DCFE:graphics_w(0B4) = 00040104
571A2DD02:graphics_w(0B7) = 80A00000
572A2DD89:graphics_w(0B0) = 001F001F
573A2DD8A:graphics_r(0F6)
574A2DCEB:graphics_w(0B6) = 00000000
575A2DCEF:graphics_w(0B2) = 7FFF7FFF
576A2DCF3:graphics_w(0B0) = 001F001F
577A2DCFE:graphics_w(0B4) = 00040105
578A2DD07:graphics_w(0B7) = 80500000
579A2DD89:graphics_w(0B0) = 001F001F
580A2DD8A:graphics_r(0F6)
581A2DCEB:graphics_w(0B6) = 00000000
582A2DCEF:graphics_w(0B2) = 7FFF7FFF
583A2DCF3:graphics_w(0B0) = 001F001F
584A2DCFE:graphics_w(0B4) = 00040105
585A2DD02:graphics_w(0B7) = 80A00000
586A2DD89:graphics_w(0B0) = 001F001F
587A2DD8A:graphics_r(0F6)
588A2DCEB:graphics_w(0B6) = 00000000
589A2DCEF:graphics_w(0B2) = 7FFF7FFF
590A2DCF3:graphics_w(0B0) = 001F001F
591A2DCFE:graphics_w(0B4) = 00040106
592A2DD07:graphics_w(0B7) = 80500000
593A2DD89:graphics_w(0B0) = 001F001F
594A2DD8A:graphics_r(0F6)
595
596
597Invasion:
598
599011729:graphics_w(0E0) = 1A000000
600011729:graphics_w(0E0) = 187E0000
601011729:graphics_w(0E0) = 0000FFFF
602011729:graphics_w(0E0) = 187C0000
603011729:graphics_w(0E0) = FFFFFFE0
604011729:graphics_w(0E0) = 187A0000
605011729:graphics_w(0E0) = 00800000
606011729:graphics_w(0E0) = 18780000
607011729:graphics_w(0E0) = 000000C7
608011729:graphics_w(0E0) = 18760000
609011729:graphics_w(0E0) = F8800000
610011729:graphics_w(0E0) = 176F0032
611011729:graphics_w(0E0) = 176E0031
612011729:graphics_w(0E0) = 176D003B
613011729:graphics_w(0E0) = 176C002B
614011729:graphics_w(0E0) = 184E0000
615011729:graphics_w(0E0) = 00808080
616011729:graphics_w(0E0) = 184C0000
617011729:graphics_w(0E0) = 00808080
618011729:graphics_w(0E0) = 184A0000
619011729:graphics_w(0E0) = 00FF018E
620011729:graphics_w(0E0) = 18480000
621011729:graphics_w(0E0) = 00FF018E
622011729:graphics_w(0E0) = 176940C4
623011729:graphics_w(0E0) = 17681370
624011729:graphics_w(0E0) = 1707FFFF
625011729:graphics_w(0E0) = 17060030
626011729:graphics_w(0E0) = 17010000
627011729:graphics_w(0E0) = 2D007FFF
628011729:graphics_w(0E0) = 2E000800
629011729:graphics_w(0E0) = 00000000
630011729:graphics_w(0E0) = 1757500A
631011729:graphics_w(0E0) = 175600FF
632011729:graphics_w(0E0) = 17524321
633011729:graphics_w(0E0) = 0100C0B0
634011729:graphics_w(0E0) = 3F001059
635
636011729:graphics_w(0E0) = 0100C0B0
637011729:graphics_w(0E0) = 3F001059
638
639011841:graphics_w(0E0) = 1A000000
640011841:graphics_w(0E0) = 1A000000
641
64200D09A:graphics_w(080) = FB22FC3F
64300D01E:graphics_w(076) = F8800000
64400D020:graphics_w(0CC) = 00800000
64500D034:graphics_w(084) = 00000000
64600D0A7:graphics_r(0F2) = 00000000
64700D0C9:graphics_w(068) = 00000100
64800D0CA:graphics_w(000) = 00000000
64900D0CC:graphics_w(05C) = 00000000
65000D0CE:graphics_w(006) = FFFF0030
65100D0D0:graphics_w(002) = 000C0000
65200D0D2:graphics_w(004) = 00000E01
65300D0D4:graphics_w(04C) = 00808080
65400D0D5:graphics_w(04E) = 00808080
65500D0D6:graphics_w(008) = 00000000
65600D0D7:graphics_w(00C) = 00FF018F
65700D0DD:graphics_w(00A) = 0000018F
65800D0E3:graphics_w(00E) = 00FF0000
65900D0E5:graphics_w(01E) = FFFFFFFF
66000D0E6:graphics_w(01C) = FFFFFFFF
66100D0E7:graphics_w(01A) = FFFFFFFF
66200D0E8:graphics_w(018) = FFFFFFFF
66300D0EA:graphics_w(046) = 00000000
66400D0EB:graphics_w(044) = 00000000
66500D0EC:graphics_w(042) = 00000000
66600D0ED:graphics_w(040) = 00000000
66700D0EE:graphics_w(026) = 00000000
66800D0EF:graphics_w(024) = 00000000
66900D0F0:graphics_w(022) = 00000000
67000D0F1:graphics_w(020) = 00000000
67100D09A:graphics_w(080) = FB22FCFF
67200D0F6:graphics_w(060) = 00000001
67300D09A:graphics_w(080) = FB22FC3F
674011729:graphics_w(0E0) = 1757500A
675011729:graphics_w(0E0) = 175600FF
67600D09A:graphics_w(080) = 0222FC3F
677
678*/
679
680INLINE UINT32 *graphics_pixaddr(void)
681{
682   int p = (graphics_ram[0xb7] >> 15) & 1;
683   int x = (graphics_ram[0xb4] & 0xff) << 1;
684   int y = ((graphics_ram[0xb4] >> 8) & 0x01) | ((graphics_ram[0xb5] << 1) & 0xffe);
685   return &waveram[(p * WAVERAM_HEIGHT + (y % WAVERAM_HEIGHT)) * WAVERAM_WIDTH + x];
686}
687
688
689static READ32_HANDLER( graphics_r )
690{
691   UINT32 result;
692   int logit = 1;
693
694   if (offset >= 0xb0 && offset <= 0xb7)
695      logit = graphics_ram[0xb4] < 8;
696
697   result = graphics_ram[offset & ~1] | (graphics_ram[offset | 1] << 16);
698
699   switch (offset)
700   {
701      case 0x00:
702         // crusnexo wants bit 0x20 to be non-zero
703         result = 0x20;
704         break;
705      case 0x51:
706         // crusnexo expects a reflection of the data at 0x08 here (b425)
707         result = graphics_ram[0x08];
708         break;
709      case 0xf4:
710         result = 6;
711         logit = 0;
712         break;
713      case 0xf6:      // status -- they wait for this & 9 == 0
714         result = 0;
715         logit = 0;
716         break;
717   }
718
719   if (logit || input_code_pressed(KEYCODE_F11))
720      logerror("%06X:graphics_r(%03X) = %08X\n", activecpu_get_pc(), offset, result);
721   return result;
722}
723
724
725/*
726    Writes to even addresses: reg[offs] = data & 0xffff; reg[offs+1] = data >> 16;
727    Writes to odd addresses:  reg[offs] = data & 0xffff;
728
729    Control in $B7.
730    Enable in $B6.
731    Y/2 in $B5.
732    X | ((Y & 1) << 8) in $B4.
733    Depth data in $B2/$B3.
734    Pixel data in $B0/$B1.
735
736    Control = $80F6 when doing initial screen clear.
737       Writes 256 consecutive values to $B0, must mean autoincrement
738       Uses latched value in $B2 (maybe also in $B0)
739
740    Control = $82F0 when doing video RAM test write phase.
741       Writes 512 values across, but updates address before each one.
742
743    Control = $84F1 when doing video RAM test read phase.
744       Reads 512 values across, but updates address before each one.
745
746    Control = $80F2 when doing screen clear.
747       Writes 256 consecutive values to $B0, must mean autoincrement.
748       Uses latched value in $B2 (maybe also in $B0)
749
750    Control = $80A0/$8050 when plotting pixels.
751
752    Control = $42F0 when doing wave RAM test write phase.
753       Writes 512 values across, but updates address before each one.
754
755    Control = $44F1 when doing wave RAM test read phase.
756       Reads 512 values across, but updates address before each one.
757
758
759    Low bits = operation?
760      $0 = write single
761      $1 = read single
762      $2 = write autoinc
763*/
764
765static WRITE32_HANDLER( graphics_w )
766{
767   int logit = 1;
768
769   if (offset >= 0xb0 && offset <= 0xb7)
770      logit = graphics_ram[0xb4] < 8;
771
772   if (!(offset & 1))
773      graphics_ram[offset | 0] = data & 0xffff;
774   graphics_ram[offset | 1] = data >> 16;
775
776   switch (offset)
777   {
778      case 0xb0:
779      case 0xb2:
780      {
781         UINT32 *dest = graphics_pixaddr();
782         if (input_code_pressed(KEYCODE_F11)) logerror("B7=%04X x=%3d y=%3d B0=%04X%04X B2=%04X%04X\n",
783               graphics_ram[0xb7],
784               (graphics_ram[0xb4] & 0xff) << 1,
785               ((graphics_ram[0xb4] >> 8) & 0x01) | ((graphics_ram[0xb5] << 1) & 0xffe),
786               graphics_ram[0xb0],graphics_ram[0xb1],
787               graphics_ram[0xb2],graphics_ram[0xb3]);
788
789         if (graphics_ram[0xb7] != 0)
790         {
791            if (graphics_ram[0xb7] & 0x0050)
792               dest[0] = (graphics_ram[0xb2] << 16) | graphics_ram[0xb0];
793            if (graphics_ram[0xb7] & 0x00a0)
794               dest[1] = (graphics_ram[0xb3] << 16) | graphics_ram[0xb1];
795            switch (graphics_ram[0xb7] & 3)
796            {
797               case 0:
798               case 1:
799                  break;
800               case 2:
801               case 3:
802                  graphics_ram[0xb4]++;
803                  break;
804            }
805{
806   static int count = 0;
807   popmessage("WaveRAM writes = %X", ++count);
808}
809         }
810         break;
811      }
812
813      case 0xb4:
814      {
815         if (graphics_ram[0xb7] & 1)
816         {
817            UINT32 *src = graphics_pixaddr();
818            graphics_ram[0xb0] = src[0] & 0xffff;
819            graphics_ram[0xb1] = src[1] & 0xffff;
820            graphics_ram[0xb2] = src[0] >> 16;
821            graphics_ram[0xb3] = src[1] >> 16;
822         }
823         break;
824      }
825   }
826
827   if (logit || input_code_pressed(KEYCODE_F11))
828      logerror("%06X:graphics_w(%03X) = %08X\n", activecpu_get_pc(), offset, data);
829}
830
831
832static READ32_HANDLER( graphics2_r )
833{
834   return graphics_r(offset * 2, 0);
835}
836
837
838static WRITE32_HANDLER( graphics2_w )
839{
840   graphics_w(offset * 2, data, mem_mask);
841}
842
843
844
84535/*************************************
84636 *
84737 *  Machine init
r1215r1216
960150   AM_RANGE(0x400000, 0x41ffff) AM_RAM
961151   AM_RANGE(0x808000, 0x80807f) AM_READWRITE(tms32031_control_r, tms32031_control_w) AM_BASE(&tms32031_control)
962152   AM_RANGE(0x87fe00, 0x87ffff) AM_RAM
963   AM_RANGE(0x880000, 0x8803ff) AM_READWRITE(graphics_r, graphics_w) AM_BASE(&graphics_ram)
153   AM_RANGE(0x880000, 0x8803ff) AM_READWRITE(zeus_r, zeus_w) AM_BASE(&zeusbase)
964154   AM_RANGE(0x8d0000, 0x8d0003) AM_READWRITE(unknown_8d0000_r, unknown_8d0000_w) AM_BASE(&unknown_8d0000)
965155   AM_RANGE(0x990000, 0x99000f) AM_READWRITE(midway_ioasic_r, midway_ioasic_w)
966156//9d0000 -- page select?
r1215r1216
977167   AM_RANGE(0x400000, 0x43ffff) AM_RAM
978168   AM_RANGE(0x808000, 0x80807f) AM_READWRITE(tms32031_control_r, tms32031_control_w) AM_BASE(&tms32031_control)
979169   AM_RANGE(0x87fe00, 0x87ffff) AM_RAM
980   AM_RANGE(0x880000, 0x8801ff) AM_READWRITE(graphics2_r, graphics2_w) AM_BASE(&graphics_ram)
170   AM_RANGE(0x880000, 0x8801ff) AM_READWRITE(zeus2_r, zeus2_w) AM_BASE(&zeusbase)
981171   AM_RANGE(0x8d0000, 0x8d0003) AM_READWRITE(unknown_8d0000_r, unknown_8d0000_w) AM_BASE(&unknown_8d0000)
982172   AM_RANGE(0x990000, 0x99000f) AM_READWRITE(midway_ioasic_r, midway_ioasic_w)
983173//9d0000 -- page select?
r1215r1216
997187
998188INPUT_PORTS_START( mk4 )
999189   PORT_START       /* DS1 */
1000    PORT_DIPNAME( 0x0001, 0x0001, "Fatalities" )
1001   PORT_DIPSETTING(      0x0001, DEF_STR( Off ))
190   PORT_DIPNAME( 0x0001, 0x0001, "Coinage Source" )
191   PORT_DIPSETTING(      0x0001, "Dipswitch" )
192   PORT_DIPSETTING(      0x0000, "CMOS" )
193   PORT_DIPNAME( 0x003e, 0x003e, DEF_STR( Coinage ))
194   PORT_DIPSETTING(      0x003e, "USA-1" )
195   PORT_DIPSETTING(      0x003c, "USA-2" )
196   PORT_DIPSETTING(      0x003a, "USA-3" )
197   PORT_DIPSETTING(      0x0038, "USA-4" )
198   PORT_DIPSETTING(      0x0034, "USA-9" )
199   PORT_DIPSETTING(      0x0032, "USA-11" )
200   PORT_DIPSETTING(      0x0036, "USA-ECA" )
201   PORT_DIPSETTING(      0x002e, "German-1" )
202   PORT_DIPSETTING(      0x002c, "German-2" )
203   PORT_DIPSETTING(      0x002a, "German-3" )
204   PORT_DIPSETTING(      0x0028, "German-4" )
205   PORT_DIPSETTING(      0x0026, "German-ECA" )
206   PORT_DIPSETTING(      0x001e, "French-1" )
207   PORT_DIPSETTING(      0x001c, "French-2" )
208   PORT_DIPSETTING(      0x001a, "French-3" )
209   PORT_DIPSETTING(      0x0018, "French-4" )
210   PORT_DIPSETTING(      0x0016, "French-ECA" )
211   PORT_DIPSETTING(      0x0030, DEF_STR( Free_Play ))
212   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ))   /* Manual lists this dip as Unused */
213   PORT_DIPSETTING(      0x0040, DEF_STR( Off ))
1002214   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1003    PORT_DIPNAME( 0x0002, 0x0002, "Blood" )
1004   PORT_DIPSETTING(      0x0002, DEF_STR( Off ))
215   PORT_DIPNAME( 0x0080, 0x0080, "Test Switch" )
216   PORT_DIPSETTING(      0x0080, DEF_STR( Off ))
1005217   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1006    PORT_DIPNAME( 0x0004, 0x0004, DEF_STR( Unknown )) /* Manual states that switches 3-7 are Unused */
1007   PORT_DIPSETTING(      0x0004, DEF_STR( Off ))
1008   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1009    PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ))
218    PORT_DIPNAME( 0x0100, 0x0100, "Fatalities" )
1010219   PORT_DIPSETTING(      0x0000, DEF_STR( Off ))
1011   PORT_DIPSETTING(      0x0008, DEF_STR( On ))
1012    PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ))
1013    PORT_DIPSETTING(      0x0010, DEF_STR( Off ))
1014    PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1015   PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ))
1016   PORT_DIPSETTING(      0x0020, DEF_STR( Off ))
220   PORT_DIPSETTING(      0x0100, DEF_STR( On ))
221    PORT_DIPNAME( 0x0200, 0x0200, "Blood" )
222   PORT_DIPSETTING(      0x0000, DEF_STR( Off ))
223   PORT_DIPSETTING(      0x0200, DEF_STR( On ))
224    PORT_DIPNAME( 0x0400, 0x0400, DEF_STR( Unknown )) /* Manual states that switches 3-7 are Unused */
225   PORT_DIPSETTING(      0x0400, DEF_STR( Off ))
1017226   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1018   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ))
1019   PORT_DIPSETTING(      0x0040, DEF_STR( Off ))
227    PORT_DIPNAME( 0x0800, 0x0800, DEF_STR( Unknown ))
228   PORT_DIPSETTING(      0x0800, DEF_STR( Off ))
1020229   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1021   PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ))
1022   PORT_DIPSETTING(      0x0080, DEF_STR( Off ))
230    PORT_DIPNAME( 0x1000, 0x1000, DEF_STR( Unknown ))
231    PORT_DIPSETTING(      0x1000, DEF_STR( Off ))
232    PORT_DIPSETTING(      0x0000, DEF_STR( On ))
233   PORT_DIPNAME( 0x2000, 0x2000, DEF_STR( Unknown ))
234   PORT_DIPSETTING(      0x2000, DEF_STR( Off ))
1023235   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1024   PORT_DIPNAME( 0x0100, 0x0100, "Coinage Source" )
1025   PORT_DIPSETTING(      0x0100, "Dipswitch" )
1026   PORT_DIPSETTING(      0x0000, "CMOS" )
1027   PORT_DIPNAME( 0x3e00, 0x3e00, DEF_STR( Coinage ))
1028   PORT_DIPSETTING(      0x3e00, "USA-1" )
1029   PORT_DIPSETTING(      0x3c00, "USA-2" )
1030   PORT_DIPSETTING(      0x3a00, "USA-3" )
1031   PORT_DIPSETTING(      0x3800, "USA-4" )
1032   PORT_DIPSETTING(      0x3400, "USA-9" )
1033   PORT_DIPSETTING(      0x3200, "USA-11" )
1034   PORT_DIPSETTING(      0x3600, "USA-ECA" )
1035   PORT_DIPSETTING(      0x2e00, "German-1" )
1036   PORT_DIPSETTING(      0x2c00, "German-2" )
1037   PORT_DIPSETTING(      0x2a00, "German-3" )
1038   PORT_DIPSETTING(      0x2800, "German-4" )
1039   PORT_DIPSETTING(      0x2600, "German-ECA" )
1040   PORT_DIPSETTING(      0x1e00, "French-1" )
1041   PORT_DIPSETTING(      0x1c00, "French-2" )
1042   PORT_DIPSETTING(      0x1a00, "French-3" )
1043   PORT_DIPSETTING(      0x1800, "French-4" )
1044   PORT_DIPSETTING(      0x1600, "French-ECA" )
1045   PORT_DIPSETTING(      0x3000, DEF_STR( Free_Play ))
1046   PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ))   /* Manual lists this dip as Unused */
236   PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Unknown ))
1047237   PORT_DIPSETTING(      0x4000, DEF_STR( Off ))
1048238   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1049   PORT_DIPNAME( 0x8000, 0x8000, "Test Switch" )
239   PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ))
1050240   PORT_DIPSETTING(      0x8000, DEF_STR( Off ))
1051241   PORT_DIPSETTING(      0x0000, DEF_STR( On ))
1052242
r1215r1216
1443633   /* video hardware */
1444634   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
1445635   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1446   MDRV_SCREEN_SIZE(512, 432)
1447   MDRV_SCREEN_VISIBLE_AREA(0, 511, 0, 399)
636   MDRV_SCREEN_SIZE(512, 278)
637   MDRV_SCREEN_VISIBLE_AREA(0, 399, 0, 255)
1448638   MDRV_PALETTE_LENGTH(32768)
1449639
1450640   MDRV_VIDEO_START(midzeus)
r1215r1216
1625815 *
1626816 *************************************/
1627817
1628GAME( 1997, mk4,      0,     midzeus,  mk4,      mk4,      ROT0, "Midway", "Mortal Kombat 4 (rev L3)", GAME_NOT_WORKING | GAME_NO_SOUND )
1629GAME( 1997, mk4a,     mk4,   midzeus,  mk4,      mk4,      ROT0, "Midway", "Mortal Kombat 4 (? rev)", GAME_NOT_WORKING | GAME_NO_SOUND )
818GAME( 1997, mk4,      0,     midzeus,  mk4,      mk4,      ROT0, "Midway", "Mortal Kombat 4 (3.0)", GAME_NOT_WORKING | GAME_NO_SOUND )
819GAME( 1997, mk4a,     mk4,   midzeus,  mk4,      mk4,      ROT0, "Midway", "Mortal Kombat 4 (2.1)", GAME_NOT_WORKING | GAME_NO_SOUND )
1630820GAME( 1999, invasn,   0,     midzeus,  invasn,   invasn,   ROT0, "Midway", "Invasion (Midway)", GAME_NOT_WORKING | GAME_NO_SOUND )
1631821GAME( 1999, crusnexo, 0,     midzeus2, crusnexo, crusnexo, ROT0, "Midway", "Cruis'n Exotica", GAME_NOT_WORKING | GAME_NO_SOUND )
1632822GAME( 2001, thegrid,  0,     midzeus2, thegrid,  thegrid,  ROT0, "Midway", "The Grid (version 1.1)", GAME_NOT_WORKING | GAME_NO_SOUND )
src/mame/drivers/cclimber.c
r1215r1216
859859   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
860860
861861   MDRV_SOUND_ADD(SAMPLES, 0)
862   MDRV_SOUND_CONFIG(cclimber_custom_interface)
862   MDRV_SOUND_CONFIG(cclimber_samples_interface)
863863   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
864864MACHINE_DRIVER_END
865865
r1215r1216
897897   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
898898
899899   MDRV_SOUND_ADD(SAMPLES, 0)
900   MDRV_SOUND_CONFIG(cclimber_custom_interface)
900   MDRV_SOUND_CONFIG(cclimber_samples_interface)
901901   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
902902MACHINE_DRIVER_END
903903
src/mame/drivers/mpu4.c
r1215r1216
11/***************************************************************************
22  MPU4 highly preliminary driver by J.Wallace, and Anonymous.
33
4     09-2007: Haze: Added Deal 'Em video support.
45  03-08-2007: J Wallace: Removed audio filter for now, since sound is more accurate without them.
56                         Connect 4 now has the right sound.
67  03-07-2007: J Wallace: Several major changes, including input relabelling, and system timer improvements.
r1215r1216
1011                         Revisionism, if you will.
1112  17-02-2007: J Wallace: Added Deal 'Em - still needs some work.
1213  10-02-2007: J Wallace: Improved input timing.
13              It appears Connect 4 uses a different sound mapping to regular Barcrest games.
1414  30-01-2007: J Wallace: Characteriser rewritten to run the 'extra' data needed by some games.
1515  24-01-2007: J Wallace: With thanks to Canonman and HIGHWAYMAN/System 80, I was able to confirm a seemingly
1616              ghastly misuse of a PIA is actually on the real hardware. This fixes the meters.
r1215r1216
262262       - Confirm that MC6850 emulation is sufficient.
263263       - MPU4 Master clock value taken from schematic, but 68k value is not.
264264       - On IRQ, inhibit line goes low.
265
266       - Test mode appears to malfunction in Refill mode in Deal 'Em
267       - Distinguish door switches using manual
265268*****************************************************************************************/
266269
267270#include "driver.h"
r1215r1216
274277#include "cpu/m6809/m6809.h"
275278#include "sound/ay8910.h"
276279#include "sound/flt_rc.h"
277#include "sound/2413intf.h"
278280#include "machine/steppers.h"   // stepper motor
279281#include "machine/roc10937.h"   // vfd
280282#include "machine/mmtr.h"
r1215r1216
288290#include "video/crtc6845.h"
289291
290292#ifdef MAME_DEBUG
291#define LOG(x)
292#define LOG_CHR(x)
293#define LOG_IC3(x)
294#define LOG_IC8(x)
295#define LOGSTUFF(x)
293#define LOG(x)logerror x
294#define LOG_CHR(x)logerror x
295#define LOG_CHR_FULL(x)logerror x
296#define LOG_IC3(x)logerror x
297#define LOG_IC8(x)logerror x
298#define LOGSTUFF(x)logerror x
296299#else
297300#define LOG(x)
298301#define LOG_CHR(x)
302#define LOG_CHR_FULL(x)
299303#define LOG_IC3(x)
300304#define LOG_IC8(x)
301305#define LOGSTUFF(x)
r1215r1216
323327static int IC23GA;
324328static int prot_col;
325329static int lamp_col;
326static int ic24_active;
330static int ic23_active;
327331static int led_extend;
328332static mame_timer *ic24_timer;
329333static mame_timer *freq_timer;
r1215r1216
339343UINT8 MPU4_chr_data[72];
340344static UINT8 led_segs[8];
341345static UINT8 Lamps[128];      // 128 multiplexed lamps
342//static UINT8 Lampscopy[128];
343346                        // 32  multiplexed inputs - but a further 8 possible per AUX.
344347                        // Two connectors 'orange' (sampled every 8ms) and 'black' (sampled every 16ms)
345348                        // Each connector carries two banks of eight inputs and two enable signals
r1215r1216
395398   output_set_digit_value(id,value);
396399}
397400
401static void draw_lamps(void)
402{
403   int i;
404
405   for (i=0; i<8; i++)
406   {
407      output_set_lamp_value((8*input_strobe)+i, (Lamps[(8*input_strobe)+i]));
408      output_set_lamp_value((8*input_strobe)+i+64, (Lamps[(8*input_strobe)+i+64]));
409   }
410
411}
412
398413static void update_lamps(void)
399414{
400415   int i;
r1215r1216
422437      mpu4_draw_led(8, pled_segs[0]);
423438      mpu4_draw_led(9, pled_segs[1]);
424439   }
425}
426440
427static void draw_lamps(void)
428{
429   int i;
430
431   for (i=0; i<8; i++)
432   {
433      output_set_lamp_value((8*input_strobe)+i, (Lamps[(8*input_strobe)+i]));
434      output_set_lamp_value((8*input_strobe)+i+64, (Lamps[(8*input_strobe)+i+64]));
435   }
436441}
437442
438443// palette initialisation /////////////////////////////////////////////////
r1215r1216
585590    6821 PIA handlers
586591***************************************************************************/
587592
593// IC3
588594static WRITE8_HANDLER( pia_ic3_porta_w )
589595{
590596   LOG_IC3(("%04x IC3 PIA Port A Set to %2x (lamp strobes 1 - 9)\n", activecpu_get_previouspc(),data));
591597
592   lamp_strobe = data;
593   update_lamps();
598   if(ic23_active)
599   {
600      lamp_strobe = data;
601      update_lamps();
602   }
594603}
595604
596605static WRITE8_HANDLER( pia_ic3_portb_w )
597606{
598607   LOG_IC3(("%04x IC3 PIA Port B Set to %2x  (lamp strobes 10 - 17)\n", activecpu_get_previouspc(),data));
599608
600   lamp_strobe2 = data;
601   update_lamps();
609   if(ic23_active)
610   {
611      lamp_strobe2 = data;
612      update_lamps();
613   }
602614}
603615
604616static WRITE8_HANDLER( pia_ic3_ca2_w )
605617{
606   LOG_IC3(("%04x IC3 PIA Write CA2 (alpha data), %02X\n", activecpu_get_previouspc(),data&0xFF));
618   LOG_IC3(("%04x IC3 PIA Write CA2 (alpha data), %02X\n", activecpu_get_previouspc(),data&0xff));
607619
608620   alpha_data_line = data;
609621   ROC10937_draw_16seg(0);
r1215r1216
659671   {
660672      input_strobe = 0x00;
661673   }
674   draw_lamps();
662675}
663676/*---------------------------------------
664677   IC24 emulation
r1215r1216
679692   if (IC23GA)
680693   {
681694      double duration = TIME_OF_74LS123((220*1000),(0.1*0.000001));
682      if (!ic24_active)
683695      {
696         ic23_active=1;
684697         ic24_output(0);
685698         mame_timer_adjust(ic24_timer, double_to_mame_time(duration), 0, time_zero);
686         ic24_active = 1;
687699      }
688      draw_lamps();
689700   }
690701}
691702
692703static TIMER_CALLBACK( ic24_timeout )
693704{
694   ic24_active = 0;
705   ic23_active=0;
695706   ic24_output(1);
696707}
697708
709// IC4
710
698711static WRITE8_HANDLER( pia_ic4_porta_w )
699712{
700   led_segs[input_strobe] = data;
701   mpu4_draw_led(input_strobe, led_segs[input_strobe]);
713   if(ic23_active)
714   {
715      led_segs[input_strobe] = data;
716      mpu4_draw_led(input_strobe, led_segs[input_strobe]);
717   }
702718}
703719
704720static READ8_HANDLER( pia_ic4_portb_r )
r1215r1216
753769   /*irqs   : A/B             */ cpu0_irq, cpu0_irq
754770};
755771
772//IC5
756773static READ8_HANDLER( pia_ic5_porta_r )
757774{
758775   LOG(("%04x IC5 PIA Read of Port A (AUX1)\n",activecpu_get_previouspc()));
r1215r1216
847864   /*irqs   : A/B             */ cpu0_irq, cpu0_irq
848865};
849866
867//IC6
850868static WRITE8_HANDLER( pia_ic6_portb_w )
851869{
852870   LOG(("%04x IC6 PIA Port B Set to %2x (Reel A and B)\n", activecpu_get_previouspc(),data));
871   Stepper_update(0, data & 0x0F );
872   Stepper_update(1, (data>>4) & 0x0F );
853873
854   Stepper_update(0, (data >> 4) & 0x0F );
855   Stepper_update(1, data        & 0x0F );
856
857   if ( pia_get_output_cb2(1))
874//  if ( pia_get_output_cb2(1))
858875   {
859876      if ( Stepper_optic_state(0) ) optic_pattern |=  0x01;
860877      else                          optic_pattern &= ~0x01;
878
861879      if ( Stepper_optic_state(1) ) optic_pattern |=  0x02;
862880      else                          optic_pattern &= ~0x02;
863881   }
882//  awp_draw_reel(0);
883//  awp_draw_reel(1);
864884}
865885
866886static WRITE8_HANDLER( pia_ic6_porta_w )
r1215r1216
902922   /*irqs   : A/B             */ cpu0_irq, cpu0_irq
903923};
904924
925//IC7
905926static WRITE8_HANDLER( pia_ic7_porta_w )
906927{
907928   LOG(("%04x IC7 PIA Port A Set to %2x (Reel C and D)\n", activecpu_get_previouspc(),data));
929   Stepper_update(2, data & 0x0F );
930   Stepper_update(3, (data >> 4)& 0x0F );
908931
909   Stepper_update(2, (data >> 4) & 0x0F );
910   Stepper_update(3, data        & 0x0F );
911
912   if ( pia_get_output_cb2(1))
932//  if ( pia_get_output_cb2(1))
913933   {
914934      if ( Stepper_optic_state(2) ) optic_pattern |=  0x04;
915935      else                          optic_pattern &= ~0x04;
916936      if ( Stepper_optic_state(3) ) optic_pattern |=  0x08;
917937      else                          optic_pattern &= ~0x08;
918938   }
939//  awp_draw_reel(2);
940//  awp_draw_reel(3);
919941}
920942
921943static WRITE8_HANDLER( pia_ic7_portb_w )
r1215r1216
10781100// Communications ////////////////////////////////////////////////////////
10791101/* Clock values are currently unknown, and are derived from the 68k board.
10801102For now, it's fixed to the frequency set by the PTM on initialisation.*/
1081
1103static void cpu1a_acia_irq(int state)
1104{
1105   cpunum_set_input_line(0, M6809_IRQ_LINE, state ? CLEAR_LINE : ASSERT_LINE);
1106//  m6850_irq_state = state;
1107//  update_mpu68_interrupts();
1108   logerror("6809 acia irq \n");
1109}
10821110static void cpu1_acia_irq(int state)
10831111{
1084   cpunum_set_input_line(0, M6809_IRQ_LINE, state?ASSERT_LINE:CLEAR_LINE);
1085   m6850_irq_state = state;
1086   update_mpu68_interrupts();
1087   LOG(("acia irq \n"));
1112//  cpunum_set_input_line(0, M6809_IRQ_LINE, state?ASSERT_LINE:CLEAR_LINE);
1113     m6850_irq_state = state;
1114     update_mpu68_interrupts();
1115   logerror("68k acia irq \n");
10881116}
10891117
10901118static struct acia6850_interface m6809_acia_if =
r1215r1216
10931121   MPU4_MASTER_CLOCK/44,//the ACIA code's hard coding
10941122   &m68k_m6809_line,
10951123   &m6809_m68k_line,
1096   cpu1_acia_irq
1124   NULL,
1125   NULL,
1126   NULL,
1127   cpu1a_acia_irq
10971128};
10981129
10991130static struct acia6850_interface m68k_acia_if =
r1215r1216
11021133   MPU4_MASTER_CLOCK/44,
11031134   &m6809_m68k_line,
11041135   &m68k_m6809_line,
1105   0
1136   NULL,
1137   NULL,
1138   NULL,
1139   cpu1_acia_irq
11061140};
11071141
11081142static void cpu1_irq(int state)
r1215r1216
21422176
21432177INPUT_PORTS_START( dealem )
21442178   PORT_START_TAG("ORANGE1")
2145   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("00")
2146   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("01")
2147   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("02")
2148   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("03")
2149   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("04")
2150   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("05")
2151   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("06")
2152   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("07")
2179   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Gamble")
2180   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_START2) PORT_NAME("Pontoon")
2181   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_UNUSED)
2182   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
2183   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
2184   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_UNUSED)
2185   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED)
2186   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_INTERLOCK) PORT_NAME("Rear Door") PORT_TOGGLE
21532187
21542188   PORT_START_TAG("ORANGE2")
2155   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("08")
2156   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("09")
2157   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("10")
2158   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("11")
2159   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("12")
2160   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("13")
2161   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("14")
2162   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("15")
2189   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_COIN5) PORT_NAME("20p Token")PORT_IMPULSE(3)
2190   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
2191   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_UNUSED)
2192   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
2193   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
2194   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_UNUSED)
2195   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED)
2196   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_UNUSED)
21632197
21642198   PORT_START_TAG("BLACK1")
2165   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("16")
2166   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("17")
2167   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("18")
2168   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("19")
2169   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("20")
2170   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("Test Switch")
2199   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON5) PORT_NAME("Collect")
2200   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN) //Duplicate for Pontoon button
2201   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_UNUSED)
2202   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
2203   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
2204   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_SERVICE) PORT_NAME("Test Button") PORT_CODE(KEYCODE_W)
21712205   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_SERVICE) PORT_NAME("Refill Key") PORT_CODE(KEYCODE_R) PORT_TOGGLE
2172   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("Door Switch?") PORT_TOGGLE
2206   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_INTERLOCK) PORT_NAME("Cashbox Door")  PORT_CODE(KEYCODE_Q) PORT_TOGGLE
21732207
21742208   PORT_START_TAG("BLACK2")
2175   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("24")
2176   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("25")
2177   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("26")
2178   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("27")
2179   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("28")
2180   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("29")
2181   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("30")
2182   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("31")
2209   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_START1) PORT_NAME("Hi-Lo")
2210   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
2211   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_BUTTON6) PORT_NAME("Twist")
2212   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_BUTTON3) PORT_NAME("Lo")
2213   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON2) PORT_NAME("Hi")
2214   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_BUTTON7) PORT_NAME("Stick")
2215   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED)
2216   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_BUTTON4) PORT_NAME("Deal")
21832217
21842218   PORT_START_TAG("DIL1")
21852219   PORT_DIPNAME( 0x0f, 0x00, "Cabinet Set Up Mode" ) PORT_DIPLOCATION("DIL1:01,02,03,04")
r1215r1216
22082242
22092243   PORT_START_TAG("DIL2")
22102244   PORT_DIPNAME( 0x01, 0x00, "Payout Limit" ) PORT_DIPLOCATION("DIL2:01")
2211   PORT_DIPSETTING(    0x00, "GBP 2.00 (All Cash)")
2212   PORT_DIPSETTING(    0x01, "GBP 4.00 (Token)")
2245   PORT_DIPSETTING(    0x00, "200p (All Cash)")
2246   PORT_DIPSETTING(    0x01, "200p (Cash)+400p (Token)")
22132247   PORT_DIPNAME( 0x02, 0x00, "10p Payout Priority" ) PORT_DIPLOCATION("DIL2:02")
22142248   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
22152249   PORT_DIPSETTING(    0x02, DEF_STR( On  ) )
r1215r1216
22192253   PORT_DIPNAME( 0x08, 0x00, "50p Payout Solenoid fitted?" ) PORT_DIPLOCATION("DIL2:04")
22202254   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
22212255   PORT_DIPSETTING(    0x08, DEF_STR( Yes  ) )
2222   PORT_DIPNAME( 0x10, 0x00, "GBP 1.00 Payout Solenoid fitted?" ) PORT_DIPLOCATION("DIL2:05")
2256   PORT_DIPNAME( 0x10, 0x00, "100p Payout Solenoid fitted?" ) PORT_DIPLOCATION("DIL2:05")
22232257   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
22242258   PORT_DIPSETTING(    0x10, DEF_STR( Yes  ) )
2225   PORT_DIPNAME( 0x20, 0x00, "Coin alarm active?" ) PORT_DIPLOCATION("DIL2:06")
2226   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
2227   PORT_DIPSETTING(    0x20, DEF_STR( Yes  ) )
2228   PORT_DIPNAME( 0x40, 0x00, "Stake" ) PORT_DIPLOCATION("DIL2:07")
2259   PORT_DIPNAME( 0x20, 0x00, "Coin alarms active?" ) PORT_DIPLOCATION("DIL2:06")
2260   PORT_DIPSETTING(    0x20, DEF_STR( No ) )
2261   PORT_DIPSETTING(    0x00, DEF_STR( Yes  ) )
2262   PORT_DIPNAME( 0x40, 0x00, "Price of Play" ) PORT_DIPLOCATION("DIL2:07")
22292263   PORT_DIPSETTING(    0x00, "10p 1 Game" )
22302264   PORT_DIPSETTING(    0x40, "10p 2 Games" )
2231   PORT_DIPNAME( 0x80, 0x00, "DIL208" ) PORT_DIPLOCATION("DIL2:08")
2232   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
2233   PORT_DIPSETTING(    0x80, DEF_STR( On  ) )
2265   PORT_DIPNAME( 0x80, 0x00, "Coin Entry" ) PORT_DIPLOCATION("DIL2:08")
2266   PORT_DIPSETTING(    0x00, "Multi" )
2267   PORT_DIPSETTING(    0x80, DEF_STR(Single))
22342268
22352269   PORT_START_TAG("AUX1")
2236   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("0")
2237   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("1")
2238   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("2")
2239   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("3")
2240   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("4")
2241   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("5")
2242   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("6")
2243   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("7")
2270   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_UNUSED)
2271   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_UNUSED)
2272   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_UNUSED)
2273   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED)
2274   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_UNUSED)
2275   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_UNUSED)
2276   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED)
2277   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_UNUSED)
22442278
22452279   PORT_START_TAG("AUX2")
22462280   PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_SPECIAL)
r1215r1216
22682302//  if (cpu_getiloops()&1)
22692303//      cpunum_set_input_line(1, 1, ASSERT_LINE);
22702304//  else
2271//  LOGSTUFF(("scn2674_irq_mask %02x",scn2674_irq_mask));
2305  LOGSTUFF(("scn2674_irq_mask %02x",scn2674_irq_mask));
22722306
22732307   if (cpu_getiloops()==0) // vbl
22742308   {
r1215r1216
23282362   Stepper_init(2, BARCREST_48STEP_REEL);
23292363   Stepper_init(3, BARCREST_48STEP_REEL);
23302364
2365/*  Stepper_set_index(0,92,8,0);
2366    Stepper_set_index(1,92,8,0);
2367    Stepper_set_index(2,92,8,0);
2368    Stepper_set_index(3,92,8,0);*/
2369
23312370// setup the standard oki MSC1937 display ///////////////////////////////
23322371
23332372   ROC10937_init(0, MSC1937,0);   // ?
r1215r1216
23502389   Stepper_init(2, BARCREST_48STEP_REEL);
23512390   Stepper_init(3, BARCREST_48STEP_REEL);
23522391
2392/*  Stepper_set_index(0,92,8,0);
2393    Stepper_set_index(1,5,6,0);
2394    Stepper_set_index(2,92,8,0);
2395    Stepper_set_index(3,1,6,0);*/
2396
23532397// setup the standard oki MSC1937 display ///////////////////////////////
23542398   ROC10937_init(0, MSC1937,0);
23552399}
r1215r1216
23582402Characteriser (CHR)
23592403
23602404I haven't been able to work out all the ways of finding the CHR data, but there must be a flag in the ROMs
2361somewhere to pick it out. As built, the CHR is a PAL which holds an internal data table that is inaccessible to
2362anything other than the CPU. However, the programmers decided to best use this protection device in read/write/compare
2405somewhere to pick it out. As built, the CHR is a PAL which can perform basic bit manipulation according to an as yet unknown unique key. However, the programmers decided to best use this protection device in read/write/compare
23632406cycles, storing almost the entire 'hidden' data table in the ROMs in plain sight. Only later rebuilds by BwB
23642407avoided this 'feature' of the development kit, and as such, only low level access can defeat their protection.
23652408
2366This information has been used to generate the CHR tables loaded by the programs.
2409This information has been used to generate the CHR tables loaded by the programs, until a key can be determined.
23672410
23682411For most Barcrest games, the following method was used:
23692412
r1215r1216
24002443{
24012444   UINT8 x;
24022445   int call=data;
2403      for ( x = 0; x < 64; x++ )
2404      {
2405         LOG_CHR(("Characteriser %02X:",MPU4_chr_data[x]));
2406      }
2407
2446   LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X", activecpu_get_previouspc(),offset,data));
24082447   if (offset == 0)
24092448   {
2410      for ( x = prot_col; x < 64; x++ )
2449      if (call == 0)
24112450      {
2412         if   (MPU4_chr_lut[(x)] == call)
2451         prot_col = 0;
2452      }
2453      else
2454      {
2455         for ( x = prot_col; x < 64; x++ )
24132456         {
2414            prot_col = x;
2415            LOG_CHR(("Characteriser find column %02X\n",prot_col));
2416            LOG_CHR(("Characteriser find data %02X\n",MPU4_chr_data[prot_col]));
2417            break;
2457            if   (MPU4_chr_lut[(x)] == call)
2458            {
2459               prot_col = x;
2460               LOG_CHR(("Characteriser find column %02X\n",prot_col));
2461               LOG_CHR(("Characteriser find data %02X\n",MPU4_chr_data[prot_col]));
2462               break;
2463            }
24182464         }
24192465      }
2420         if (prot_col > 63)
2421         {
2422            prot_col = 0;
2423         }
2424
24252466   }
24262467   else if (offset == 2)
24272468   {
r1215r1216
24452486static READ8_HANDLER( characteriser_r )
24462487{
24472488   LOG_CHR(("Characteriser read offset %02X \n",offset));
2489   LOG_CHR_FULL(("%04x Characteriser read offset %02X", activecpu_get_previouspc(),offset));
24482490   if (offset == 0)
24492491   {
24502492      LOG_CHR(("Characteriser read data %02X \n",MPU4_chr_data[prot_col]));
r1215r1216
24622504{
24632505   int x;
24642506   int call=data;
2465   LOG_CHR(("Characteriser write offset %02X data %02X\n",offset,data));
2507   LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X", activecpu_get_previouspc(),offset,data));
24662508   for ( x = prot_col; x < 64; x++ )
24672509   {
2468      if   (MPU4_chr_lut[(x)] == call)
2510      if (call == 0)
24692511      {
2470         prot_col = x;
2471         LOG_CHR(("Characteriser find column %02X\n",prot_col));
2472         break;
2512         prot_col = 0;
24732513      }
2474         if (prot_col > 63)
2475         prot_col = 0;
2514      else
2515      {
2516         if   (MPU4_chr_lut[(x)] == call)
2517         {
2518            prot_col = x;
2519            LOG_CHR(("Characteriser find column %02X\n",prot_col));
2520            break;
2521         }
2522      }
24762523   }
24772524}
24782525
24792526static READ16_HANDLER( characteriser16_r )
24802527{
2528   LOG_CHR_FULL(("%04x Characteriser read offset %02X,data %02X", activecpu_get_previouspc(),offset,MPU4_chr_data[prot_col]));
24812529   LOG_CHR(("Characteriser read offset %02X \n",offset));
24822530   LOG_CHR(("Characteriser read data %02X \n",MPU4_chr_data[prot_col]));
24832531   return MPU4_chr_data[prot_col];
r1215r1216
26762724
26772725VIDEO_START(dealem)
26782726{
2679
26802727}
26812728
2682
26832729VIDEO_UPDATE(dealem)
26842730{
26852731   int x,y;
r1215r1216
26982744   return 0;
26992745}
27002746
2701#ifdef UNUSED_FUNCTION
2702static WRITE8_HANDLER( dealem_pal_w )
2703{
2704   switch (data)
2705   {
2706      default:
2707      {
2708         logerror("Deal 'em PAL write %d",data);
2709         break;
2710      }
2711   }
2712}
2713#endif
2714
27152747static ADDRESS_MAP_START( dealem_memmap, ADDRESS_SPACE_PROGRAM, 8 )
27162748
27172749   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size)
r1215r1216
30153047   ROM_LOAD16_BYTE( "st.qa",  0x0c0001, 0x010000,  CRC(3fc62a0e) SHA1(0628de4b962d3fcca3757cd4e89b3005c9bfd218) )
30163048ROM_END
30173049
3050ROM_START( timemchn )
3051   ROM_REGION( 0x10000, REGION_CPU1, 0 )
3052   VID_BIOS
3053
3054   ROM_REGION( 0x800000, REGION_CPU2, 0 )
3055   ROM_LOAD16_BYTE( "tm20.p1",  0x000000, 0x010000,  CRC(6919697c) SHA1(786d7b9ab218dbf54ff839d1f83580c409c725b3) )
3056   ROM_LOAD16_BYTE( "tm20.p2",  0x000001, 0x010000,  CRC(d13b56e4) SHA1(623e73995da93c07b51ce0a5843dba1f853529dd) )
3057   ROM_LOAD16_BYTE( "tm20.p3",  0x020000, 0x010000,  CRC(efd3ae64) SHA1(9d2a3b65048e04842205751c6921d2550f38bd52) )
3058   ROM_LOAD16_BYTE( "tm20.p4",  0x020001, 0x010000,  CRC(602ba3fb) SHA1(7243f58df9a26adfd1a149a1e60630b187787dd0) )
3059   ROM_LOAD16_BYTE( "q12.p5" ,  0x040000, 0x010000,  CRC(adddd8a7) SHA1(73a8dd191eda2f4b41b79d4b55723731953b8970) )
3060   ROM_LOAD16_BYTE( "q11.p6" ,  0x040001, 0x010000,  CRC(e8ed736f) SHA1(e7068c550aa39a6e8f1692a16794147e996D36b4) )
3061   ROM_LOAD16_BYTE( "q14.p7" ,  0x060000, 0x010000,  CRC(02abb026) SHA1(42224678e5913090c91c21672661beb8e27127a8) )
3062   ROM_LOAD16_BYTE( "q13.p8" ,  0x060001, 0x010000,  CRC(3de147dd) SHA1(d2111d54d1604fe2da0133102bbfee706f8f542e) )
3063   ROM_LOAD16_BYTE( "q16.p9" ,  0x080000, 0x010000,  CRC(ce2bf15e) SHA1(29c7f2e718bce415b0b8dc6d902bf74dad6b1ef4) )
3064   ROM_LOAD16_BYTE( "q15.p10",  0x080001, 0x010000,  CRC(7894ac8b) SHA1(dc46bd108ac4f67a9062bb7ace91aa51f069cbc8) )
3065   ROM_LOAD16_BYTE( "q18.p11",  0x0a0000, 0x010000,  CRC(27de90b3) SHA1(625c98e555f7b627ea96653926b8917996a2fdb7) )
3066   ROM_LOAD16_BYTE( "q17.p12",  0x0a0001, 0x010000,  CRC(5cab773e) SHA1(59a235c51a975b341bdbb88e909729507408f75b) )
3067   ROM_LOAD16_BYTE( "q20.p13",  0x0c0000, 0x010000,  CRC(083f6c65) SHA1(291ad39ee5f8eba9da293d9206b1f6a6d852f9bd) )
3068   ROM_LOAD16_BYTE( "q19.p14",  0x0c0001, 0x010000,  CRC(73747644) SHA1(ae252fc95c069a3c82e155220fbfcb74dd43bf89) )
3069ROM_END
3070
30183071ROM_START( mating )
30193072   ROM_REGION( 0x10000, REGION_CPU1, 0 )
30203073   VID_BIOS
r1215r1216
30653118
30663119ROM_START( connect4 )
30673120   ROM_REGION( 0x10000, REGION_CPU1, ROMREGION_ERASE00  )
3068   ROM_LOAD( "connect4.p2",  0x8000, 0x4000,  CRC(6090633c) )
3069   ROM_LOAD( "connect4.p1",  0xC000, 0x4000,  CRC(b1af50c0) )
3121   ROM_LOAD( "connect4.p2",  0x8000, 0x4000,  CRC(6090633c) SHA1(0cd2725a235bf93cfe94f2ca648d5fccb87b8e5c) )
3122   ROM_LOAD( "connect4.p1",  0xC000, 0x4000,  CRC(b1af50c0) SHA1(7c9645ea378f0857b849ca24a239d9114f62da7f) )
30703123ROM_END
30713124
30723125ROM_START( dealem )
r1215r1216
30773130   ROM_LOAD( "zenndlem.u24",   0x0000, 0x10000, CRC(3a1950c4) SHA1(7138346d4e8b3cffbd9751b4d7ebd367b9ad8da9) )    /* text layer */
30783131
30793132   ROM_REGION( 0x020, REGION_PROMS, 0 )
3080   ROM_LOAD( "zenndlem.u22",      0x000, 0x020, CRC(29988304) SHA1(42f61b8f9e1ee96b65db3b70833eb2f6e7a6ae0a) )
3133   ROM_LOAD( "zenndlem.u22",   0x000, 0x020, CRC(29988304) SHA1(42f61b8f9e1ee96b65db3b70833eb2f6e7a6ae0a) )
30813134
30823135   ROM_REGION( 0x200, REGION_PLDS, 0 )
3083   ROM_LOAD( "zenndlem.u10",      0x000, 0x104, CRC(e3103c05) SHA1(91b7be75c5fb37025039ab54b484e46a033969b5) )
3136   ROM_LOAD( "zenndlem.u10",   0x000, 0x104, CRC(e3103c05) SHA1(91b7be75c5fb37025039ab54b484e46a033969b5) )
30843137ROM_END
30853138
30863139GAMEL(1989?,connect4,0,       mpu4mod2, connect4, connect4, 0,   "Dolbeck Systems", "Connect 4",                                          GAME_IMPERFECT_GRAPHICS,layout_connect4 )
r1215r1216
30903143//and reel assembly with this kit and a supplied monitor.
30913144//The real Deal 'Em ran on Summit Coin hardware, and was made by someone else.
30923145//A further different release was made in 2000, running on the Barcrest MPU4 Video, rather than this one.
3093GAME( 1987, dealem,    0,        dealem,   dealem,   0,    ROT0,   "Zenitone",       "Deal 'Em (MPU4 Conversion Kit)",                           GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS|GAME_WRONG_COLORS )
3146GAME( 1987, dealem,    0,        dealem,   dealem,   0,    ROT0,   "Zenitone",       "Deal 'Em (MPU4 Conversion Kit, v7.0)",                        GAME_IMPERFECT_GRAPHICS )
30943147
30953148GAME( 1994?,crmaze,  bctvidbs,mpu4_vid, crmaze,   crmaze,ROT0,   "Barcrest",       "The Crystal Maze: Team Challenge (SWP)",                     GAME_NOT_WORKING|GAME_NO_SOUND )
30963149GAME( 1992?,crmazea, crmaze,  mpu4_vid, crmaze,   crmaze,ROT0,   "Barcrest",       "The Crystal Maze (AMLD version SWP)",                        GAME_NOT_WORKING|GAME_NO_SOUND )
30973150GAME( 1993?,crmazeb, crmaze,  mpu4_vid, crmaze,   0,     ROT0,   "Barcrest",       "The Crystal Maze - Now Featuring Ocean Zone (AMLD Version SWP)",   GAME_NOT_WORKING|GAME_NO_SOUND ) // unprotected?
30983151GAME( 1990, turnover,bctvidbs,mpu4_vid, mpu4,     0,     ROT0,   "Barcrest",       "Turnover",                                             GAME_NOT_WORKING|GAME_NO_SOUND ) // unprotected?
3099GAME( 1992, skiltrek,bctvidbs,mpu4_vid, mpu4,     0,     ROT0,   "Barcrest",       "Skill Trek",                                          GAME_NOT_WORKING|GAME_NO_SOUND )
3152GAME( 1992, skiltrek,bctvidbs,mpu4_vid, mpu4,     0,     ROT0,   "Barcrest",       "Skill Trek",                                          GAME_NOT_WORKING|GAME_NO_SOUND ) // unprotected?
3153GAME( 1990, timemchn,bctvidbs,mpu4_vid, mpu4,     0,     ROT0,   "Barcrest",       "Time Machine v2.0",                                    GAME_NOT_WORKING|GAME_NO_SOUND ) // unprotected?
31003154GAME( 199?, mating,  bctvidbs,mpu4_vid, mpu4,     mating,ROT0,   "Barcrest",       "The Mating Game (Datapak)",                              GAME_NOT_WORKING|GAME_NO_SOUND )
31013155GAME( 199?, matinga, mating,  mpu4_vid, mpu4,     mating,ROT0,   "Barcrest",       "The Mating Game (Standard)",                              GAME_NOT_WORKING|GAME_NO_SOUND )
src/mame/drivers/suna8.c
r1215r1216
15391539   suna8_samples_number_w
15401540};
15411541
1542static struct Samplesinterface custom_interface =
1542static struct Samplesinterface suna8_samples_interface =
15431543{
15441544   1,
15451545   NULL,
r1215r1216
15871587   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.30)
15881588
15891589   MDRV_SOUND_ADD(SAMPLES, 0)
1590   MDRV_SOUND_CONFIG(custom_interface)
1590   MDRV_SOUND_CONFIG(suna8_samples_interface)
15911591   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 0.50)
15921592   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.50)
15931593MACHINE_DRIVER_END
r1215r1216
18041804   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.50)
18051805
18061806   MDRV_SOUND_ADD(SAMPLES, 0)
1807   MDRV_SOUND_CONFIG(custom_interface)
1807   MDRV_SOUND_CONFIG(suna8_samples_interface)
18081808   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 0.50)
18091809   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.50)
18101810MACHINE_DRIVER_END
r1215r1216
18631863   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.30)
18641864
18651865   MDRV_SOUND_ADD(SAMPLES, 0)
1866   MDRV_SOUND_CONFIG(custom_interface)
1866   MDRV_SOUND_CONFIG(suna8_samples_interface)
18671867   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 0.50)
18681868   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.50)
18691869MACHINE_DRIVER_END
src/mame/drivers/galaxian.c
r1215r1216
42804280
42814281   /* sound hardware */
42824282   MDRV_SOUND_ADD(SAMPLES, 0)
4283   MDRV_SOUND_CONFIG(galaxian_custom_interface)
4283   MDRV_SOUND_CONFIG(galaxian_samples_interface)
42844284   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
42854285MACHINE_DRIVER_END
42864286
r1215r1216
44194419   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
44204420
44214421   MDRV_SOUND_ADD(SAMPLES, 0)
4422   MDRV_SOUND_CONFIG(cclimber_custom_interface)
4422   MDRV_SOUND_CONFIG(cclimber_samples_interface)
44234423   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.5)
44244424MACHINE_DRIVER_END
44254425
r1215r1216
45254525   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
45264526
45274527   MDRV_SOUND_ADD(SAMPLES, 0)
4528   MDRV_SOUND_CONFIG(galaxian_custom_interface)
4528   MDRV_SOUND_CONFIG(galaxian_samples_interface)
45294529   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
45304530MACHINE_DRIVER_END
45314531
r1215r1216
47244724   /* sound hardware */
47254725   MDRV_SPEAKER_STANDARD_MONO("mono")
47264726   MDRV_SOUND_ADD(SAMPLES, 0)
4727   MDRV_SOUND_CONFIG(galaxian_custom_interface)
4727   MDRV_SOUND_CONFIG(galaxian_samples_interface)
47284728   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
47294729MACHINE_DRIVER_END
47304730
r1215r1216
47674767   /* sound hardware */
47684768   MDRV_SPEAKER_STANDARD_MONO("mono")
47694769   MDRV_SOUND_ADD(SAMPLES, 0)
4770   MDRV_SOUND_CONFIG(galaxian_custom_interface)
4770   MDRV_SOUND_CONFIG(galaxian_samples_interface)
47714771   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
47724772MACHINE_DRIVER_END
47734773
src/mame/drivers/cps2.c
r1215r1216
30473047
30483048ROM_START( ecofghtu )
30493049   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
3050   ROM_LOAD16_WORD_SWAP( "uecu.03a", 0x000000, 0x80000, CRC(22d88a4d) SHA1(0aa5a4b51ae98b8b3bfc65aef9449796ffad7f10) )
3051   ROM_LOAD16_WORD_SWAP( "uecu.04a", 0x080000, 0x80000, CRC(6436cfcd) SHA1(adb4e1ab2a01a1ea1b08a76ecf58654450e13cf9) )
3052   ROM_LOAD16_WORD_SWAP( "uecu.05a", 0x100000, 0x80000, CRC(336f121b) SHA1(93800c459b516382cc62cebeb456274f48322fab) )
3053   ROM_LOAD16_WORD_SWAP( "uecu.06a", 0x180000, 0x80000, CRC(6f99d984) SHA1(3f962197edab648bf87c1f2976956ea21e7ac3c4) )
3054
3055   ROM_REGION( 0xc00000, REGION_GFX1, 0 )
3056   ROMX_LOAD( "uec.13m",   0x000000, 0x200000, CRC(dcaf1436) SHA1(ba124cc0bb10c1d1c07592a3623add4ed054182e) , ROM_GROUPWORD | ROM_SKIP(6) )
3057   ROMX_LOAD( "uec.15m",   0x000002, 0x200000, CRC(2807df41) SHA1(66a9800af435055737ce50a0b0ced7c5718c2004) , ROM_GROUPWORD | ROM_SKIP(6) )
3058   ROMX_LOAD( "uec.17m",   0x000004, 0x200000, CRC(8a708d02) SHA1(95ec527edc904a66e325667521b4d07d72579211) , ROM_GROUPWORD | ROM_SKIP(6) )
3059   ROMX_LOAD( "uec.19m",   0x000006, 0x200000, CRC(de7be0ef) SHA1(bf8df9a31f8923f4b726ea12fe8327368463ebe1) , ROM_GROUPWORD | ROM_SKIP(6) )
3060   ROMX_LOAD( "uec.14m",   0x800000, 0x100000, CRC(1a003558) SHA1(64bbd89e65dc0cf6f4ab5ea93a4cc6312d0d0802) , ROM_GROUPWORD | ROM_SKIP(6) )
3061   ROMX_LOAD( "uec.16m",   0x800002, 0x100000, CRC(4ff8a6f9) SHA1(03968a301417e8843d42d4e0db42aa0a3a38664b) , ROM_GROUPWORD | ROM_SKIP(6) )
3062   ROMX_LOAD( "uec.18m",   0x800004, 0x100000, CRC(b167ae12) SHA1(48c552d02caad27d680aa51170560794f2a51478) , ROM_GROUPWORD | ROM_SKIP(6) )
3063   ROMX_LOAD( "uec.20m",   0x800006, 0x100000, CRC(1064bdc2) SHA1(c51f75ac8d3f02a771feda0a933314a928555c4e) , ROM_GROUPWORD | ROM_SKIP(6) )
3064
3065   ROM_REGION( QSOUND_SIZE, REGION_CPU2, 0 ) /* 64k for the audio CPU (+banks) */
3066   ROM_LOAD( "uec.01",   0x00000, 0x08000, CRC(c235bd15) SHA1(feb7cd7db9dc0b9887b33eed9796bb0205fb719d) )
3067   ROM_CONTINUE(         0x10000, 0x18000 )
3068
3069   ROM_REGION( 0x400000, REGION_SOUND1, 0 ) /* QSound samples */
3070   ROM_LOAD16_WORD_SWAP( "uec.11m",   0x000000, 0x200000, CRC(81b25d39) SHA1(448adfcc7d98873a48c710d857225cdd1580e5c9) )
3071   ROM_LOAD16_WORD_SWAP( "uec.12m",   0x200000, 0x200000, CRC(27729e52) SHA1(a55c8159adf766dda70cb047f5ac85ce6bc0a3f3) )
3072ROM_END
3073
3074ROM_START( ecofgtu1 )
3075   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
30503076   ROM_LOAD16_WORD_SWAP( "uecu.03", 0x000000, 0x80000, CRC(6792480c) SHA1(89d7095a36a1094237f9e1d82a0dc482409999ca) )
30513077   ROM_LOAD16_WORD_SWAP( "uecu.04", 0x080000, 0x80000, CRC(95ce69d5) SHA1(d32c7e2a99ae29cbf9fee1e092a418f300a218ca) )
30523078   ROM_LOAD16_WORD_SWAP( "uecu.05", 0x100000, 0x80000, CRC(3a1e78ad) SHA1(133b65cd4bfd45a9d9d3feec9ccb1e6fc2891818) )
r1215r1216
72207246GAME( 1993, ddtoda,   ddtod,   cps2, ddtod,   cps2, ROT0,   "Capcom", "Dungeons & Dragons: Tower of Doom (Asia 940113)", 0 )
72217247GAME( 1993, ddtodh,   ddtod,   cps2, ddtod,   cps2, ROT0,   "Capcom", "Dungeons & Dragons: Tower of Doom (Hispanic 940125)", 0 )
72227248GAME( 1993, ecofghtr, 0,       cps2, sgemf,   cps2, ROT0,   "Capcom", "Eco Fighters (World 931203)", 0 )
7223GAME( 1993, ecofghtu, ecofghtr,cps2, sgemf,   cps2, ROT0,   "Capcom", "Eco Fighters (USA 931203)", 0 )
7249GAME( 1993, ecofghtu, ecofghtr,cps2, sgemf,   cps2, ROT0,   "Capcom", "Eco Fighters (USA 940215)", 0 )
7250GAME( 1993, ecofgtu1, ecofghtr,cps2, sgemf,   cps2, ROT0,   "Capcom", "Eco Fighters (USA 931203)", 0 )
72247251GAME( 1993, uecology, ecofghtr,cps2, sgemf,   cps2, ROT0,   "Capcom", "Ultimate Ecology (Japan 931203)", 0 )
72257252GAME( 1993, ecofghta, ecofghtr,cps2, sgemf,   cps2, ROT0,   "Capcom", "Eco Fighters (Asia 931203)", 0 )
72267253GAME( 1994, ssf2t,    ssf2,    cps2, ssf2,    cps2, ROT0,   "Capcom", "Super Street Fighter II Turbo (World 940223)", 0 )
src/mame/drivers/firebeat.c
r1215r1216
111111#include "driver.h"
112112#include "cpu/powerpc/ppc.h"
113113#include "machine/intelfsh.h"
114#include "machine/scsidev.h"
114#include "machine/scsicd.h"
115115#include "machine/rtc65271.h"
116116#include "machine/pc16552d.h"
117117#include "sound/ymz280b.h"
r1215r1216
817817#define ATAPI_CYCLES_PER_SECTOR (32000)   // plenty of time to allow DMA setup etc.  BIOS requires this be at least 2000, individual games may vary.
818818
819819static UINT8 atapi_regs[16];
820static pSCSIDispatch atapi_device[2];
821static void *atapi_device_data[2];
820static SCSIInstance *atapi_device_data[2];
822821
823822#define ATAPI_STAT_BSY      0x80
824823#define ATAPI_STAT_DRDY    0x40
r1215r1216
864863   atapi_cdata_wait = 0;
865864
866865   // allocate two SCSI CD-ROM devices
867   atapi_device[0] = SCSI_DEVICE_CDROM;
868   atapi_device[0](SCSIOP_ALLOC_INSTANCE, &atapi_device_data[0], 0, (UINT8 *)NULL);
866   SCSIAllocInstance( SCSI_DEVICE_CDROM, &atapi_device_data[0], 0 );
869867   // TODO: the slave drive can be either CD-ROM, DVD-ROM or HDD
870   atapi_device[1] = SCSI_DEVICE_CDROM;
871   atapi_device[1](SCSIOP_ALLOC_INSTANCE, &atapi_device_data[1], 1, (UINT8 *)NULL);
868   SCSIAllocInstance( SCSI_DEVICE_CDROM, &atapi_device_data[1], 1 );
872869}
873870
874871static void atapi_reset(void)
r1215r1216
903900         atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
904901
905902         // get the data from the device
906         atapi_device[atapi_drivesel](SCSIOP_READ_DATA, atapi_device_data[atapi_drivesel], atapi_xferlen, temp_data);
903         SCSIReadData( atapi_device_data[atapi_drivesel], temp_data, atapi_xferlen );
907904
908905         // fix it up in an endian-safe way
909906         for (i = 0; i < atapi_xferlen; i += 2)
r1215r1216
970967            }
971968
972969            // send it to the device
973            atapi_device[atapi_drivesel](SCSIOP_WRITE_DATA, atapi_device_data[atapi_drivesel], atapi_cdata_wait, atapi_scsi_packet);
970            SCSIWriteData( atapi_device_data[atapi_drivesel], atapi_scsi_packet, atapi_cdata_wait );
974971
975972            // assert IRQ
976973            atapi_cause_irq();
r1215r1216
982979
983980      if ((!atapi_cdata_wait) && (atapi_data_ptr == 6))
984981      {
982         int phase;
983
985984         // reset data pointer for reading SCSI results
986985         atapi_data_ptr = 0;
987986
r1215r1216
998997         }
999998
1000999         // send it to the SCSI device
1001         atapi_xferlen = atapi_device[atapi_drivesel](SCSIOP_EXEC_COMMAND, atapi_device_data[atapi_drivesel], 0, atapi_scsi_packet);
1000         SCSISetCommand( atapi_device_data[atapi_drivesel], atapi_scsi_packet, 12 );
1001         SCSIExecCommand( atapi_device_data[atapi_drivesel], &atapi_xferlen );
1002         SCSIGetPhase( atapi_device_data[atapi_drivesel], &phase );
10021003
10031004         if (atapi_xferlen != -1)
10041005         {
r1215r1216
10191020            atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
10201021            atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;
10211022
1023            switch( phase )
1024            {
1025            case SCSI_PHASE_DATAOUT:
1026               atapi_data_ptr = 0;
1027               atapi_cdata_wait = atapi_xferlen;
1028               logerror("ATAPI: Waiting for %x bytes of data\n", atapi_cdata_wait);
1029               break;
1030            }
1031
10221032            // perform special ATAPI processing of certain commands
10231033            switch (atapi_data[0]&0xff)
10241034            {
1025               case 0x55:   // MODE SELECT
1026                  atapi_cdata_wait = atapi_data[4]/2;
1027                  atapi_data_ptr = 0;
1028                  logerror("ATAPI: Waiting for %x bytes of MODE SELECT data\n", atapi_cdata_wait);
1029                  break;
1030
10311035               case 0xa8:   // READ (12)
10321036                  // indicate data ready: set DRQ and DMA ready, and IO in INTREASON
10331037                  atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
r1215r1216
10361040                  fatalerror("ATAPI: DMA read command attempted\n");
10371041                  break;
10381042
1039               case 0x00:   // BUS RESET / TEST UNIT READY
1040                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1041                  break;
1042
1043               case 0xbb:   // SET CD SPEED
1044                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1045                  break;
1046
1047               case 0xa5:   // PLAY AUDIO
1048                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1049                  break;
1050
1043               case 0x00: // BUS RESET / TEST UNIT READY
1044               case 0xbb: // SET CD SPEED
1045               case 0xa5: // PLAY AUDIO
10511046               case 0x1b:
1052                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1053                  break;
1054
10551047               case 0x4e:
10561048                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
10571049                  break;
r1215r1216
19781970      sound[i+0x200000] = intelflash_read(2, i);
19791971   }
19801972
1981   atapi_device[1](SCSIOP_GET_DEVICE, atapi_device_data[1], 0, (UINT8 *)&cd);
1973   SCSIGetDevice( atapi_device_data[1], &cd );
19821974   cdda_set_cdrom(0, cd);
19831975}
19841976
src/mame/drivers/bnstars.c
r1215r1216
534534
535535INPUT_PORTS_START( bnstars )
536536   PORT_START
537   PORT_DIPNAME(     0x00000001, 0x00000001, "MAH0" )
538   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
539   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
540   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
541   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
542   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
543   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
544   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
545   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
546   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
547   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
548   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
549   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
550   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
551   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
552   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
553   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
554   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
537   PORT_BIT( 0x00000001, IP_ACTIVE_LOW, IPT_START1 )
538   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_MAHJONG_A )
539   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_MAHJONG_E )
540   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_MAHJONG_M )
541   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_I )
542   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
555543   PORT_DIPNAME(     0x00000040, 0x00000040, DEF_STR( Unknown ) )
556544   PORT_DIPSETTING(  0x00000040, DEF_STR( Off ) )
557545   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
r1215r1216
586574   PORT_DIPNAME(     0x00020000, 0x00020000, "MAH1" )
587575   PORT_DIPSETTING(  0x00020000, DEF_STR( Off ) )
588576   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
589   PORT_DIPNAME(     0x00040000, 0x00040000, DEF_STR( Unknown ) )
590   PORT_DIPSETTING(  0x00040000, DEF_STR( Off ) )
591   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
592   PORT_DIPNAME(     0x00080000, 0x00080000, DEF_STR( Unknown ) )
577   PORT_BIT( 0x00040000, IP_ACTIVE_LOW, IPT_SERVICE1 )
578   PORT_DIPNAME(     0x00080000, 0x00080000, "Service Mode ? 1" )
593579   PORT_DIPSETTING(  0x00080000, DEF_STR( Off ) )
594580   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
595581   PORT_DIPNAME(     0x00100000, 0x00100000, DEF_STR( Unknown ) )
r1215r1216
633619   PORT_DIPNAME(     0x00000001, 0x00000001, "MAH2" )
634620   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
635621   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
636   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
637   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
638   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
639   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
640   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
641   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
642   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
643   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
644   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
645   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
646   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
647   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
648   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
649   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
650   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
622   PORT_BIT( 0x00000002, IP_ACTIVE_LOW, IPT_MAHJONG_B )
623   PORT_BIT( 0x00000004, IP_ACTIVE_LOW, IPT_MAHJONG_F )
624   PORT_BIT( 0x00000008, IP_ACTIVE_LOW, IPT_MAHJONG_N )
625   PORT_BIT( 0x00000010, IP_ACTIVE_LOW, IPT_MAHJONG_J )
626   PORT_BIT( 0x00000020, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
651627   PORT_DIPNAME(     0x00000040, 0x00000040, DEF_STR( Unknown ) )
652628   PORT_DIPSETTING(  0x00000040, DEF_STR( Off ) )
653629   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
r1215r1216
731707   PORT_DIPNAME(     0x00000001, 0x00000001, "MAH4" )
732708   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
733709   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
734   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
735   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
736   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
737   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
738   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
739   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
740   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
741   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
742   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
743   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
744   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
745   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
746   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
747   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
748   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
710   PORT_BIT( 0x00000002, IP_ACTIVE_LOW, IPT_MAHJONG_C )
711   PORT_BIT( 0x00000004, IP_ACTIVE_LOW, IPT_MAHJONG_G )
712   PORT_BIT( 0x00000008, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
713   PORT_BIT( 0x00000010, IP_ACTIVE_LOW, IPT_MAHJONG_K )
714   PORT_BIT( 0x00000020, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
749715   PORT_DIPNAME(     0x00000040, 0x00000040, DEF_STR( Unknown ) )
750716   PORT_DIPSETTING(  0x00000040, DEF_STR( Off ) )
751717   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
r1215r1216
829795   PORT_DIPNAME(     0x00000001, 0x00000001, "MAH6" )
830796   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
831797   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
832   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
833   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
834   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
835   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
836   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
837   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
838   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
839   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
840   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
841   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
842   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
843   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
798   PORT_BIT( 0x00000002, IP_ACTIVE_LOW, IPT_MAHJONG_D )
799   PORT_BIT( 0x00000004, IP_ACTIVE_LOW, IPT_MAHJONG_H )
800   PORT_BIT( 0x00000008, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
801   PORT_BIT( 0x00000010, IP_ACTIVE_LOW, IPT_MAHJONG_L )
844802   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
845803   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
846804   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
r1215r1216
924882   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
925883
926884   PORT_START
927   PORT_DIPNAME(     0x00000001, 0x00000001, "0" )
928   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
929   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
930   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
885   PORT_BIT( 0x00000001, IP_ACTIVE_LOW, IPT_START2 )
886   /* The follow 4 bits active 4 button each one for the second player */
887   PORT_DIPNAME(     0x00000002, 0x00000002, "P2: A,B,C,D" )
931888   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
932889   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
933   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
890   PORT_DIPNAME(     0x00000004, 0x00000004, "P2: E,F,G,H" )
934891   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
935892   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
936   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
893   PORT_DIPNAME(     0x00000008, 0x00000008, "P2: M,N,Pon,Chie" )
937894   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
938895   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
939   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
896   PORT_DIPNAME(     0x00000010, 0x00000010, "P2: I,J,K,L" )
940897   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
941898   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
942   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
899   PORT_DIPNAME(     0x00000020, 0x00000020, "P2: Kan,Reach,Ron" )
943900   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
944901   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
945902   PORT_DIPNAME(     0x00000040, 0x00000040, DEF_STR( Unknown ) )
r1215r1216
972929   PORT_DIPNAME(     0x00008000, 0x00008000, DEF_STR( Unknown ) )
973930   PORT_DIPSETTING(  0x00008000, DEF_STR( Off ) )
974931   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
975   PORT_DIPNAME(     0x00010000, 0x00010000, "1" )
976   PORT_DIPSETTING(  0x00010000, DEF_STR( Off ) )
977   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
978   PORT_DIPNAME(     0x00020000, 0x00020000, DEF_STR( Unknown ) )
932   PORT_BIT( 0x00010000, IP_ACTIVE_LOW, IPT_COIN2 )
933   PORT_DIPNAME(     0x00020000, 0x00020000, "MAH9" )
979934   PORT_DIPSETTING(  0x00020000, DEF_STR( Off ) )
980935   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
981   PORT_DIPNAME(     0x00040000, 0x00040000, DEF_STR( Unknown ) )
982   PORT_DIPSETTING(  0x00040000, DEF_STR( Off ) )
983   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
984   PORT_DIPNAME(     0x00080000, 0x00080000, DEF_STR( Unknown ) )
936   PORT_BIT( 0x00040000, IP_ACTIVE_LOW, IPT_SERVICE2 )
937   PORT_DIPNAME(     0x00080000, 0x00080000, "Service Mode ? 2" )
985938   PORT_DIPSETTING(  0x00080000, DEF_STR( Off ) )
986939   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
987940   PORT_DIPNAME(     0x00100000, 0x00100000, DEF_STR( Unknown ) )
r1215r1216
1020973   PORT_DIPNAME(     0x80000000, 0x80000000, DEF_STR( Unknown ) )
1021974   PORT_DIPSETTING(  0x80000000, DEF_STR( Off ) )
1022975   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
976
1023977   PORT_START
1024   PORT_DIPNAME(     0x00000001, 0x00000001, "2" )
978   PORT_DIPNAME(     0x00000001, 0x00000001, "Test Mode" ) PORT_DIPLOCATION("SW1:8")
1025979   PORT_DIPSETTING(  0x00000001, DEF_STR( Off ) )
1026980   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1027   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Unknown ) )
981   PORT_DIPNAME(     0x00000002, 0x00000002, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW1:7")
1028982   PORT_DIPSETTING(  0x00000002, DEF_STR( Off ) )
1029983   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1030   PORT_DIPNAME(     0x00000004, 0x00000004, DEF_STR( Unknown ) )
1031   PORT_DIPSETTING(  0x00000004, DEF_STR( Off ) )
1032   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1033   PORT_DIPNAME(     0x00000008, 0x00000008, DEF_STR( Unknown ) )
1034   PORT_DIPSETTING(  0x00000008, DEF_STR( Off ) )
1035   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1036   PORT_DIPNAME(     0x00000010, 0x00000010, DEF_STR( Unknown ) )
1037   PORT_DIPSETTING(  0x00000010, DEF_STR( Off ) )
1038   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1039   PORT_DIPNAME(     0x00000020, 0x00000020, DEF_STR( Unknown ) )
1040   PORT_DIPSETTING(  0x00000020, DEF_STR( Off ) )
1041   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1042   PORT_DIPNAME(     0x00000040, 0x00000040, DEF_STR( Unknown ) )
1043   PORT_DIPSETTING(  0x00000040, DEF_STR( Off ) )
1044   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1045   PORT_DIPNAME(     0x00000080, 0x00000080, DEF_STR( Unknown ) )
1046   PORT_DIPSETTING(  0x00000080, DEF_STR( Off ) )
1047   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1048   PORT_DIPNAME(     0x00000100, 0x00000100, DEF_STR( Unknown ) )
984   PORT_DIPNAME(     0x0000001c, 0x0000001c, "First Point" ) PORT_DIPLOCATION("SW1:6,5,4")
985   PORT_DIPSETTING(  0x0000000c, "5000"  )
986   PORT_DIPSETTING(  0x00000014, "10000" )
987   PORT_DIPSETTING(  0x00000004, "15000" )
988   PORT_DIPSETTING(  0x0000001c, "20000" )
989   PORT_DIPSETTING(  0x00000018, "23000" )
990   PORT_DIPSETTING(  0x00000008, "25000" )
991   PORT_DIPSETTING(  0x00000010, "26000" )
992   PORT_DIPSETTING(  0x00000000, "30000" )
993   PORT_DIPNAME(     0x000000e0, 0x000000e0, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:3,2,1")
994   PORT_DIPSETTING(  0x00000000, DEF_STR( 5C_1C ) )
995   PORT_DIPSETTING(  0x00000080, DEF_STR( 4C_1C ) )
996   PORT_DIPSETTING(  0x00000040, DEF_STR( 3C_1C ) )
997   PORT_DIPSETTING(  0x000000c0, DEF_STR( 2C_1C ) )
998   PORT_DIPSETTING(  0x000000e0, DEF_STR( 1C_1C ) )
999   PORT_DIPSETTING(  0x00000060, DEF_STR( 1C_2C ) )
1000   PORT_DIPSETTING(  0x000000a0, DEF_STR( 1C_3C ) )
1001   PORT_DIPSETTING(  0x00000020, DEF_STR( 1C_4C ) )
1002   PORT_DIPNAME(     0x00000100, 0x00000100, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:8")
10491003   PORT_DIPSETTING(  0x00000100, DEF_STR( Off ) )
10501004   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1051   PORT_DIPNAME(     0x00000200, 0x00000200, DEF_STR( Unknown ) )
1005   PORT_DIPNAME(     0x00000200, 0x00000200, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW2:7")
10521006   PORT_DIPSETTING(  0x00000200, DEF_STR( Off ) )
10531007   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1054   PORT_DIPNAME(     0x00000400, 0x00000400, DEF_STR( Unknown ) )
1008   PORT_DIPNAME(     0x00000400, 0x00000400, "Taisen Only" ) PORT_DIPLOCATION("SW2:6")
10551009   PORT_DIPSETTING(  0x00000400, DEF_STR( Off ) )
10561010   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1057   PORT_DIPNAME(     0x00000800, 0x00000800, DEF_STR( Unknown ) )
1058   PORT_DIPSETTING(  0x00000800, DEF_STR( Off ) )
1059   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1060   PORT_DIPNAME(     0x00001000, 0x00001000, DEF_STR( Unknown ) )
1061   PORT_DIPSETTING(  0x00001000, DEF_STR( Off ) )
1062   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1063   PORT_DIPNAME(     0x00002000, 0x00002000, DEF_STR( Unknown ) )
1064   PORT_DIPSETTING(  0x00002000, DEF_STR( Off ) )
1065   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1066   PORT_DIPNAME(     0x00004000, 0x00004000, DEF_STR( Unknown ) )
1067   PORT_DIPSETTING(  0x00004000, DEF_STR( Off ) )
1068   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1069   PORT_DIPNAME(     0x00008000, 0x00008000, DEF_STR( Unknown ) )
1070   PORT_DIPSETTING(  0x00008000, DEF_STR( Off ) )
1071   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1072   PORT_DIPNAME(     0x00010000, 0x00010000, "3" )
1011   PORT_DIPNAME(     0x00000800, 0x00000800, "Tumo Pinfu" ) PORT_DIPLOCATION("SW2:5")
1012   PORT_DIPSETTING(  0x00000000, DEF_STR( Off ) )
1013   PORT_DIPSETTING(  0x00000800, DEF_STR( On ) )
1014   PORT_DIPNAME(     0x00001000, 0x00001000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:4")
1015   PORT_DIPSETTING(  0x00000000, DEF_STR( Off ) )
1016   PORT_DIPSETTING(  0x00001000, DEF_STR( On ) )
1017   PORT_DIPNAME(     0x0000e000, 0x0000e000, DEF_STR ( Difficulty ) ) PORT_DIPLOCATION("SW2:3,2,1")
1018   PORT_DIPSETTING(  0x00000000, DEF_STR( Easiest ) )
1019   PORT_DIPSETTING(  0x00008000, DEF_STR( Very_Easy) )
1020   PORT_DIPSETTING(  0x00004000, DEF_STR( Easier ) )
1021   PORT_DIPSETTING(  0x0000c000, DEF_STR( Easy ) )
1022   PORT_DIPSETTING(  0x0000e000, DEF_STR( Normal ) )
1023   PORT_DIPSETTING(  0x00006000, DEF_STR( Hard ) )
1024   PORT_DIPSETTING(  0x0000a000, DEF_STR( Harder ) )
1025   PORT_DIPSETTING(  0x00002000, DEF_STR( Hardest ) )
1026
1027   PORT_DIPNAME(     0x00010000, 0x00010000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:8")
10731028   PORT_DIPSETTING(  0x00010000, DEF_STR( Off ) )
10741029   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1075   PORT_DIPNAME(     0x00020000, 0x00020000, DEF_STR( Unknown ) )
1030   PORT_DIPNAME(     0x00020000, 0x00020000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:7")
10761031   PORT_DIPSETTING(  0x00020000, DEF_STR( Off ) )
10771032   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1078   PORT_DIPNAME(     0x00040000, 0x00040000, DEF_STR( Unknown ) )
1033   PORT_DIPNAME(     0x00040000, 0x00040000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:6")
10791034   PORT_DIPSETTING(  0x00040000, DEF_STR( Off ) )
10801035   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1081   PORT_DIPNAME(     0x00080000, 0x00080000, DEF_STR( Unknown ) )
1036   PORT_DIPNAME(     0x00080000, 0x00080000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:5")
10821037   PORT_DIPSETTING(  0x00080000, DEF_STR( Off ) )
10831038   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1084   PORT_DIPNAME(     0x00100000, 0x00100000, DEF_STR( Unknown ) )
1039   PORT_DIPNAME(     0x00100000, 0x00100000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:4")
10851040   PORT_DIPSETTING(  0x00100000, DEF_STR( Off ) )
10861041   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1087   PORT_DIPNAME(     0x00200000, 0x00200000, DEF_STR( Unknown ) )
1042   PORT_DIPNAME(     0x00200000, 0x00200000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:3")
10881043   PORT_DIPSETTING(  0x00200000, DEF_STR( Off ) )
10891044   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1090   PORT_DIPNAME(     0x00400000, 0x00400000, DEF_STR( Unknown ) )
1045   PORT_DIPNAME(     0x00400000, 0x00400000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:2")
10911046   PORT_DIPSETTING(  0x00400000, DEF_STR( Off ) )
10921047   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
1093   PORT_DIPNAME(     0x00800000, 0x00800000, DEF_STR( Unknown ) )
1048   PORT_DIPNAME(     0x00800000, 0x00800000, DEF_STR( Unused ) ) PORT_DIPLOCATION("SW3:1")
10941049   PORT_DIPSETTING(  0x00800000, DEF_STR( Off ) )
10951050   PORT_DIPSETTING(  0x00000000, DEF_STR( On ) )
10961051   PORT_DIPNAME(     0x01000000, 0x01000000, DEF_STR( Unknown ) )
r1215r1216
15311486   memory_set_bankptr(1, memory_region(REGION_CPU1));
15321487}
15331488
1534GAME( 1997, bnstars1, 0,        bnstars, bnstars, bnstars, ROT0,   "Jaleco", "Vs. Janshi Brandnew Stars", GAME_NOT_WORKING|GAME_NO_SOUND )
1489GAME( 1997, bnstars1, 0,        bnstars, bnstars, bnstars, ROT0,   "Jaleco", "Vs. Janshi Brandnew Stars", GAME_NO_SOUND )
src/mame/drivers/galaga.c
r1215r1216
16071607   0   /* end of array */
16081608};
16091609
1610struct Samplesinterface samples_interface_battles =
1610struct Samplesinterface battles_samples_interface =
16111611{
16121612   1,   /* one channel */
16131613   battles_sample_names
r1215r1216
18291829   MDRV_SOUND_REMOVE("Discrete")
18301830
18311831   MDRV_SOUND_ADD(SAMPLES, 0)
1832   MDRV_SOUND_CONFIG(samples_interface_battles)
1832   MDRV_SOUND_CONFIG(battles_samples_interface)
18331833   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
18341834MACHINE_DRIVER_END
18351835
src/mame/drivers/polyplay.c
r1215r1216
113113
114114
115115/* Polyplay Sound Interface */
116static struct Samplesinterface custom_interface =
116static struct Samplesinterface polyplay_samples_interface =
117117{
118118   2,
119119   NULL,
r1215r1216
318318   MDRV_SPEAKER_STANDARD_MONO("mono")
319319
320320   MDRV_SOUND_ADD(SAMPLES, 0)
321   MDRV_SOUND_CONFIG(custom_interface)
321   MDRV_SOUND_CONFIG(polyplay_samples_interface)
322322   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
323323MACHINE_DRIVER_END
324324
src/mame/drivers/dambustr.c
r1215r1216
212212
213213   /* sound hardware */
214214   MDRV_SOUND_ADD(SAMPLES, 0)
215   MDRV_SOUND_CONFIG(galaxian_custom_interface)
215   MDRV_SOUND_CONFIG(galaxian_samples_interface)
216216   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
217217MACHINE_DRIVER_END
218218
src/mame/drivers/meadows.c
r1215r1216
578578 *
579579 *************************************/
580580
581static struct Samplesinterface custom_interface =
581static struct Samplesinterface meadows_samples_interface =
582582{
583583   2,
584584   NULL,
r1215r1216
643643   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
644644
645645   MDRV_SOUND_ADD(SAMPLES, 0)
646   MDRV_SOUND_CONFIG(custom_interface)
646   MDRV_SOUND_CONFIG(meadows_samples_interface)
647647   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
648648MACHINE_DRIVER_END
649649
src/mame/drivers/madalien.c
r1215r1216
11/***************************************************************************
22
3Mad Alien
4(c) 1980 Data East Corporation
3    Mad Alien (c) 1980 Data East Corporation
54
6Driver by Norbert Kehrer (February 2004).
5    Original driver by Norbert Kehrer (February 2004)
76
8****************************************************************************
7***************************************************************************/
98
10Hardware:
11---------
9#include "driver.h"
10#include "video/crtc6845.h"
11#include "sound/ay8910.h"
1212
13Main CPU    6502
14Sound CPU   6502
15Sound chip  AY-3-8910
13#define MAIN_CLOCK 10595000
1614
15#define SOUND_CLOCK 4000000
1716
18Memory map of main board:
19-------------------------
17#define PIXEL_CLOCK (MAIN_CLOCK / 2)
2018
21$0000 - $03ff   Program RAM
22$6000 - $63ff   Video RAM
23$6800 - $7fff   Character generator RAM
24$8004       Flip screen in cocktail mode (?)
25$8006       Write: send command to sound board, read: input from sound board
26$8008       Write: set counter for shifter circuitry, read: low byte of shift reg. after shift operation
27$8009       Write: set data to be shifted, read: high byte of shift reg. after shift operation
28$8008       Video register (control of headlight, color, and landscape)
29$800d       Background horiz. scroll register left part
30$800e       Background horiz. scroll register right part
31$800f       Background vertical scroll register
32$9000       Input port 1: player 1 controls
33$9001       DIP switch port
34$9002       Input port 2: player 2 controls
35$c000 - $ffff   Program ROM
3619
37Main board interrupts: NMI triggered, when coin is inserted
20static UINT8* madalien_videoram;
21static UINT8* madalien_charram;
3822
23static UINT8 madalien_video_flags;
24static UINT8 madalien_screen_control;
25static UINT8 madalien_scroll;
26static UINT8 madalien_edge1_pos;
27static UINT8 madalien_edge2_pos;
28static UINT8 madalien_headlight_pos;
29static UINT8 madalien_shift_count;
30static UINT8 madalien_shift_data;
3931
40Memory map of sound board:
41--------------------------
32static tilemap* tilemap_fg;
4233
43$0000 - $03ff   Sound board program RAM
44$6500       Sound board register, just to write in someting (?)
45$6800       Sound board register, just to write in and read out (?)
46$8000       Write: AY-3-8910 control port, read: input from master CPU
47$8001       AY-3-8910 data port
48$8006       Output to master CPU
49$f800 - $ffff   Sound board program ROM
34static tilemap* tilemap_edge1[4];
35static tilemap* tilemap_edge2[4];
5036
51Sound board interrupts: NMI triggered by VBlank signal
37static mame_bitmap* tmp_bitmap;
38static mame_bitmap* headlight_bitmap;
5239
5340
54Input ports:
55------------
41static PALETTE_INIT( madalien )
42{
43   int i;
5644
57Input port 1, mapped to memory address $9000:
587654 3210
591          Unused
60 1         Start 2 players game
61  1        Start 1 player game
62   1       Player 1 fire button
63     1     Player 1 down (not used in Mad Alien)
64      1    Player 1 up (not used in Mad Alien)
65       1   Player 1 left
66        1  Player 1 right
45   for (i = 0; i < 32; i++)
46   {
47      int r = 0;
48      int g = 0;
49      int b = 0;
6750
68DIP switch port, mapped to memory address $9001:
697654 3210
701          VBlank (0 = off, 1 = on)
71 1         Game screen (0 = prevent turning, 1 = to turn) (?)
72  00       Bonus points (0 = 3000, 1 = 7000, 2 = 5000, 3 = nil)
73     00    Game charge (0 = 1 coin/1 play, 1 = 1 coin/2 plays, 2 and 3 = 2 coins 1 play)
74       00  Number of cars (0 = 3 cars, 1 = 4 cars, 2 = 5 cars, 3 = 6cars)
51      if (BIT(color_prom[i], 0))
52         r += 0x3f;
53      if (BIT(color_prom[i], 1))
54         r += 0xc0;
55      if (BIT(color_prom[i], 2))
56         g += 0x3f;
57      if (BIT(color_prom[i], 3))
58         g += 0xc0;
59      if (BIT(color_prom[i], 4))
60         b += 0x3f;
61      if (BIT(color_prom[i], 5))
62         b += 0xc0;
7563
76Input port 2, mapped to memory address $9002:
777654 3210
78111        Unused
79   1       Player 2 fire button
80     1     Player 2 down (not used in Mad Alien)
81      1    Player 2 up (not used in Mad Alien)
82       1   Player 2 left
83        1  Player 2 right
64      palette_set_color(machine, i, MAKE_RGB(r, g, b));
65   }
8466
85***************************************************************************/
67   for (i = 0; i < 16; i++)
68   {
69      colortable[0x00 + i] = i;
70      colortable[0x10 + i] = i;
71      colortable[0x20 + i] = i + 0x10;
8672
87#include "driver.h"
88#include "sound/ay8910.h"
73      /* PCB can swap address lines 1 and 2 when accessing color PROM */
8974
90static tilemap *fg_tilemap, *bg_tilemap_l, *bg_tilemap_r;
75      if (BIT(i, 1))
76      {
77         colortable[0x10 + i] ^= 6;
78      }
79      if (BIT(i, 2))
80      {
81         colortable[0x10 + i] ^= 6;
82      }
83   }
84}
9185
92static rectangle bg_tilemap_l_clip;
93static rectangle bg_tilemap_r_clip;
9486
95static mame_bitmap *headlight_bitmap, *flip_bitmap;
87static void update_edges(int area)
88{
89   UINT8* map = memory_region(REGION_GFX2) + 0x200 * area;
9690
97static UINT8 *madalien_videoram;
98static UINT8 *madalien_charram;
99static UINT8 *madalien_bgram;
100static UINT8 *madalien_shift_data;
91   // MADALIEN:
92   //
93   //   area 0 section A - casino
94   //          section B - tunnel
95   //   area 1 section A - city
96   //          section B - tunnel
97   //
98   // MADALINA:
99   //
100   //   area 0 section A - desert
101   //          section B - tunnel
102   //   area 1 section A - lake
103   //          section B - tunnel
101104
102static UINT8 madalien_scroll_v;
103static UINT8 madalien_scroll_l;
104static UINT8 madalien_scroll_r;
105static UINT8 madalien_scroll_light;
105   tilemap_set_user_data(tilemap_edge1[0], map); /* left edge */
106   tilemap_set_user_data(tilemap_edge1[1], map);
107   tilemap_set_user_data(tilemap_edge1[2], map);
108   tilemap_set_user_data(tilemap_edge1[3], map);
106109
107static UINT8 madalien_shift_counter;
108static UINT8 madalien_shift_reg_lo;
109static UINT8 madalien_shift_reg_hi;
110   map += 0x80;
110111
111static UINT8 madalien_video_register;
112   tilemap_set_user_data(tilemap_edge2[0], map); /* right edge */
113   tilemap_set_user_data(tilemap_edge2[1], map);
114   tilemap_set_user_data(tilemap_edge2[2], map);
115   tilemap_set_user_data(tilemap_edge2[3], map);
112116
113static UINT8 madalien_bg_map_selector;
117   tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
118}
114119
115static int madalien_select_color_1;
116static int madalien_select_color_2;
117static int madalien_swap_colors;
118120
119static int madalien_headlight_on;
121static int scan_helper(int col, int row, int section)
122{
123   return section * 0x100 + (~col & 15) * 8 + row;
124}
120125
121static int madalien_flip_screen;
122126
123static int madalien_headlight_source[128][128];
127static TILEMAP_MAPPER( scan_mode0 )
128{
129   return scan_helper(col, row, 0);
130}
131static TILEMAP_MAPPER( scan_mode1 )
132{
133   return scan_helper(col, row, 1);
134}
135static TILEMAP_MAPPER( scan_mode2 )
136{
137   return scan_helper(col, row, BIT(col, 4) ? 1 : 0);
138}
139static TILEMAP_MAPPER( scan_mode3 )
140{
141   return scan_helper(col, row, BIT(col, 4) ? 0 : 1);
142}
124143
125static UINT8 madalien_sound_reg;
126144
127
128PALETTE_INIT( madalien )
145static TILE_GET_INFO( get_tile_info_BG )
129146{
130   int i, j, n, bit0, bit1, r, g, b;
147   const UINT8* p = param;
131148
132   n = machine->drv->total_colors / 2;
149   SET_TILE_INFO(1, p[tile_index], BIT(madalien_video_flags, 2) ? 2 : 0, 0);
150}
133151
134   for (i = 0; i < n; i++)
135   {
136      /* red component */
137      bit0 = (color_prom[i] >> 0) & 0x01;
138      bit1 = (color_prom[i] >> 1) & 0x01;
139      r = 0x40 * bit0 + 0x80 * bit1;
140      /* green component */
141      bit0 = (color_prom[i] >> 2) & 0x01;
142      bit1 = (color_prom[i] >> 3) & 0x01;
143      g = 0x40 * bit0 + 0x80 * bit1;
144      /* blue component */
145      bit0 = (color_prom[i] >> 4) & 0x01;
146      bit1 = (color_prom[i] >> 5) & 0x01;
147      b = 0x40 * bit0 + 0x80 * bit1;
148152
149      palette_set_color(machine, i, MAKE_RGB(r, g, b));
150
151      /* Colors for bits 1 and 2 swapped */
152      j = i;
153      switch (j & 6) {
154         case 2:
155            j &= 0xf9;
156            j |= 0x04;
157            break;
158         case 4:
159            j &= 0xf9;
160            j |= 0x02;
161            break;
162      };
163      palette_set_color(machine, j+n, MAKE_RGB(r, g, b));
164   }
153static TILE_GET_INFO( get_tile_info_FG )
154{
155   SET_TILE_INFO(0, madalien_videoram[tile_index], 0, 0);
165156}
166157
167static TILE_GET_INFO( get_fg_tile_info )
168{
169   int code, color;
170158
171   code = madalien_videoram[tile_index];
172   color = 2 * madalien_select_color_1;
173
174   SET_TILE_INFO(0, code, color, 0);
175}
176
177static TILE_GET_INFO( get_bg_tile_info_l )
159static VIDEO_START( madalien )
178160{
179   int x, y, code, color, bg_base;
161   rectangle rect = { 0, 127, 0, 127 };
180162
181   UINT8 *bgrom = memory_region(REGION_GFX2);
163   static crtc6845_interface crtc6845_intf =
164   {
165      0,                /* screen we are acting on */
166      PIXEL_CLOCK / 8,  /* the clock of the chip  */
167      8,                /* number of pixels per video memory address */
168      NULL,             /* before pixel update callback */
169      NULL,             /* row update callback */
170      NULL,             /* after pixel update callback */
171      NULL              /* call back for display state changes */
172   };
182173
183   x = tile_index & 0x0f;
184   y = (tile_index / 16) & 0x0f;
174   crtc6845_config(0, &crtc6845_intf);
185175
186   bg_base = madalien_bg_map_selector * 0x0100;
176   tilemap_fg = tilemap_create(get_tile_info_FG,
177      tilemap_scan_cols_flip_x, TILEMAP_TYPE_PEN, 8, 8, 32, 32);
187178
188   if (x < 8)
189      code = bgrom[bg_base + 8*y + x];
190   else
191      code = 16;
179   tilemap_set_transparent_pen(tilemap_fg, 0);
192180
193   color = madalien_swap_colors * 4;
181   tilemap_edge1[0] = tilemap_create(get_tile_info_BG,
182      scan_mode0, TILEMAP_TYPE_PEN, 16, 16, 16, 8);
183   tilemap_edge1[1] = tilemap_create(get_tile_info_BG,
184      scan_mode1, TILEMAP_TYPE_PEN, 16, 16, 16, 8);
185   tilemap_edge1[2] = tilemap_create(get_tile_info_BG,
186      scan_mode2, TILEMAP_TYPE_PEN, 16, 16, 32, 8);
187   tilemap_edge1[3] = tilemap_create(get_tile_info_BG,
188      scan_mode3, TILEMAP_TYPE_PEN, 16, 16, 32, 8);
194189
195   SET_TILE_INFO(1, code, color, 0);
196}
190   tilemap_edge2[0] = tilemap_create(get_tile_info_BG,
191      scan_mode0, TILEMAP_TYPE_PEN, 16, 16, 16, 8);
192   tilemap_edge2[1] = tilemap_create(get_tile_info_BG,
193      scan_mode1, TILEMAP_TYPE_PEN, 16, 16, 16, 8);
194   tilemap_edge2[2] = tilemap_create(get_tile_info_BG,
195      scan_mode2, TILEMAP_TYPE_PEN, 16, 16, 32, 8);
196   tilemap_edge2[3] = tilemap_create(get_tile_info_BG,
197      scan_mode3, TILEMAP_TYPE_PEN, 16, 16, 32, 8);
197198
198static TILE_GET_INFO( get_bg_tile_info_r )
199{
200   int x, y, code, color, bg_base;
199   update_edges(0);
201200
202   UINT8 *bgrom = memory_region(REGION_GFX2);
201   tilemap_set_scrolldy(tilemap_edge2[0], 0, machine->screen[0].height - 256);
202   tilemap_set_scrolldy(tilemap_edge2[1], 0, machine->screen[0].height - 256);
203   tilemap_set_scrolldy(tilemap_edge2[2], 0, machine->screen[0].height - 256);
204   tilemap_set_scrolldy(tilemap_edge2[3], 0, machine->screen[0].height - 256);
203205
204   x = tile_index & 0x0f;
205   y = (tile_index / 16) & 0x0f;
206   tilemap_set_flip(tilemap_edge2[0], TILEMAP_FLIPY);
207   tilemap_set_flip(tilemap_edge2[1], TILEMAP_FLIPY);
208   tilemap_set_flip(tilemap_edge2[2], TILEMAP_FLIPY);
209   tilemap_set_flip(tilemap_edge2[3], TILEMAP_FLIPY);
206210
207   bg_base = madalien_bg_map_selector * 0x0100;
211   headlight_bitmap = auto_bitmap_alloc(128, 128, BITMAP_FORMAT_INDEXED16);
208212
209   if (x < 8)
210      code = bgrom[bg_base + 0x80 + 8*y + x];
211   else
212      code = 16;
213   drawgfx(headlight_bitmap, machine->gfx[2],
214      0, 0, 0, 0, 0x00, 0x00, &rect, TRANSPARENCY_NONE, 0);
215   drawgfx(headlight_bitmap, machine->gfx[2],
216      0, 0, 0, 1, 0x00, 0x40, &rect, TRANSPARENCY_NONE, 0);
213217
214   color = madalien_swap_colors * 4;
215
216   SET_TILE_INFO(1, code, color, 0);
218   tmp_bitmap = auto_bitmap_alloc(256, 256, BITMAP_FORMAT_INDEXED16);
217219}
218220
219221
222static VIDEO_UPDATE( madalien )
223{
224   int i;
220225
226   int flip_screen;
221227
222VIDEO_START( madalien )
223{
224   int x, y, data1, data2, bit;
225   const UINT8 *headlight_rom;
228   /* draw background */
226229
227   fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_cols_flip_x,
228      TILEMAP_TYPE_PEN, 8, 8, 32, 32);
230   rectangle rect = { 0, 255, 0, 255 };
229231
230   bg_tilemap_l = tilemap_create(get_bg_tile_info_l, tilemap_scan_cols_flip_x,
231      TILEMAP_TYPE_PEN, 16, 16, 16, 16);
232   rectangle clip_edge1 = rect;
233   rectangle clip_edge2 = rect;
232234
233   bg_tilemap_r = tilemap_create(get_bg_tile_info_r, tilemap_scan_cols_flip_x,
234      TILEMAP_TYPE_PEN, 16, 16, 16, 16);
235   int mode = madalien_scroll & 3;
235236
236   tilemap_set_transparent_pen( fg_tilemap, 0 );
237   clip_edge1.max_y = madalien_edge1_pos ^ 0x7f;
238   clip_edge2.min_y = madalien_edge2_pos | 0x80;
237239
238   bg_tilemap_l_clip = machine->screen[0].visarea;
239   bg_tilemap_l_clip.max_y = machine->screen[0].height / 2;
240   fillbitmap(tmp_bitmap, machine->pens[0], &rect);
240241
241   bg_tilemap_r_clip = machine->screen[0].visarea;
242   bg_tilemap_r_clip.min_y = machine->screen[0].height / 2;
242   tilemap_draw(
243      tmp_bitmap, &clip_edge1, tilemap_edge1[mode], 0, 0);
244   tilemap_draw(
245      tmp_bitmap, &clip_edge2, tilemap_edge2[mode], 0, 0);
243246
244   tilemap_set_flip(bg_tilemap_r, TILEMAP_FLIPY);
247   /* draw foreground */
245248
246   headlight_bitmap = auto_bitmap_alloc(128, 128, machine->screen[0].format);
249   for (i = 0; i < 256; i++)
250   {
251      decodechar(machine->gfx[0], i, madalien_charram,
252         machine->drv->gfxdecodeinfo[0].gfxlayout);
253   }
247254
248   flip_bitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format);
255   tilemap_mark_all_tiles_dirty(tilemap_fg);
249256
250   madalien_bgram = auto_malloc(0x1000);   /* ficticiuos background RAM for empty tile */
257   tilemap_draw(tmp_bitmap, &rect, tilemap_fg, 0, 0);
251258
252   memset(madalien_bgram, 0, 0x1000);
259   /* highlight section A (outside of tunnels) */
253260
254   madalien_scroll_v = madalien_scroll_l = madalien_scroll_r = 0;
261   if (mode != 1)
262   {
263      int x;
264      int y;
255265
256   madalien_shift_data = memory_region( REGION_GFX4 );
266      int _L = 0;
267      int _T = 0;
268      int _R = 256;
269      int _B = 256;
257270
258   /* Generate headlight shape data: */
259   headlight_rom = memory_region( REGION_GFX3 );
260   for( x=0; x<64; x++ )
261      for( y=0; y<64; y+=8 )
271      if (mode == 2)
262272      {
263         data1 = headlight_rom[x*16 + (y/8)];
264         data2 = headlight_rom[x*16 + (y/8) + 8];
265         for( bit=0; bit<8; bit++ )
273         if (_L < (madalien_scroll & 0xfc))
274            _L = (madalien_scroll & 0xfc);
275      }
276      if (mode == 3)
277      {
278         if (_R > (madalien_scroll & 0xfc))
279            _R = (madalien_scroll & 0xfc);
280      }
281
282      for (y = _T; y < _B; y++)
283      {
284         for (x = _L; x < _R; x++)
266285         {
267            madalien_headlight_source[127-(y+bit)][x] = (data1 & 0x01);
268            madalien_headlight_source[63-(y+bit)][x] = (data2 & 0x01);
269            data1 >>= 1;
270            data2 >>= 1;
286            *BITMAP_ADDR16(tmp_bitmap, y, x) |= 8;
271287         }
272288      }
273   for( x=0; x<64; x++ )
274      for( y=0; y<128; y++ )
275         madalien_headlight_source[y][64+x] = madalien_headlight_source[y][63-x];
276}
289   }
277290
291   /* draw car headlight */
278292
279
280VIDEO_UPDATE( madalien )
281{
282   rectangle clip;
283   int i, yh, x, y, xp, yp;
284
285   for (i=0; i<256; i++)
286      decodechar(machine->gfx[0], i, madalien_charram, machine->drv->gfxdecodeinfo[0].gfxlayout);
287
288   decodechar(machine->gfx[1], 16, madalien_bgram, machine->drv->gfxdecodeinfo[1].gfxlayout); /* empty tile */
289
290   tilemap_set_scrolly( bg_tilemap_l, 0, madalien_scroll_l );
291   tilemap_set_scrollx( bg_tilemap_l, 0, madalien_scroll_v );
292
293   tilemap_set_scrolly( bg_tilemap_r, 0, madalien_scroll_r );
294   tilemap_set_scrollx( bg_tilemap_r, 0, madalien_scroll_v );
295
296   clip = bg_tilemap_l_clip;
297   sect_rect(&clip, cliprect);
298   tilemap_draw(bitmap, &clip, bg_tilemap_l, 0, 0);
299
300   clip = bg_tilemap_r_clip;
301   sect_rect(&clip, cliprect);
302   tilemap_draw(bitmap, &clip, bg_tilemap_r, 0, 0);
303
304   tilemap_draw(bitmap, &machine->screen[0].visarea, fg_tilemap, 0, 0);
305
306   /* Draw headlight area using lighter colors: */
307   if (madalien_headlight_on && (madalien_bg_map_selector & 1))
293   if (BIT(madalien_video_flags, 0))
308294   {
309      yh = (256 - madalien_scroll_light) & 0xff;
310      if (yh >= 192)
311         yh = -(255-yh);
295      int x;
296      int y;
312297
313      copybitmap(
314         headlight_bitmap,   /* dest */
315         bitmap,         /* source */
316         0, 0,          /* flipx, flipy */
317         0, -yh,         /* scroll x, scroll y */
318         cliprect,       /* clip */
319         TRANSPARENCY_NONE, 0   );
298      for (y = 0; y < 128; y++)
299      {
300         int ypos = (y - madalien_headlight_pos) & 0xff;
320301
321      for( x=0; x<128; x++ )
322         for( y=0; y<128; y++ )
323            if (madalien_headlight_source[x][y])
302         for (x = 0; x < 128; x++)
303         {
304            if (*BITMAP_ADDR16(headlight_bitmap, y, x) != 0)
324305            {
325               xp = x;
326               yp = yh + y;
327               if( xp >= machine->screen[0].visarea.min_x &&
328                   yp >= machine->screen[0].visarea.min_y &&
329                   xp <= machine->screen[0].visarea.max_x &&
330                   yp <= machine->screen[0].visarea.max_y )
331               {
332                  int color = *BITMAP_ADDR16(headlight_bitmap, y, x);
333                  *BITMAP_ADDR16(bitmap, yp, xp) = machine->pens[color+8];
334               }
306               *BITMAP_ADDR16(tmp_bitmap, ypos, x) |= 8;
335307            }
308         }
309      }
336310   };
337311
338   /* Flip screen (cocktail mode): */
339   if (madalien_flip_screen) {
340      copybitmap(flip_bitmap, bitmap, 1, 1, 0, 0, &machine->screen[0].visarea, TRANSPARENCY_NONE, 0);
341      copybitmap(bitmap, flip_bitmap, 0, 0, 0, 0, &machine->screen[0].visarea, TRANSPARENCY_NONE, 0);
342   };
343   return 0;
344}
312   /* flip screen if necessary */
345313
314   flip_screen = 0;
346315
347
348INTERRUPT_GEN( madalien_interrupt )
349{
350   static int coin;
351
352   int port = readinputport(3) & 0x01;
353
354   if (port != 0x00)    /* Coin insertion triggers an NMI */
316   if (BIT(readinputportbytag("DIP"), 6)) /* cocktail DIP */
355317   {
356      if (coin == 0)
318      if (BIT(madalien_screen_control, 0))
357319      {
358         coin = 1;
359         cpunum_set_input_line(0, INPUT_LINE_NMI, PULSE_LINE);
320         flip_screen = 1;
360321      }
361322   }
362   else
363      coin = 0;
364}
365323
324   copybitmap(bitmap, tmp_bitmap, flip_screen, flip_screen,
325      0, 0, cliprect, TRANSPARENCY_NONE, 0);
366326
367READ8_HANDLER( madalien_shift_reg_lo_r )
368{
369   return madalien_shift_reg_lo;
327   return 0;
370328}
371329
372READ8_HANDLER( madalien_shift_reg_hi_r )
330
331static INTERRUPT_GEN( madalien_interrupt )
373332{
374   return madalien_shift_reg_hi;
333   cpunum_set_input_line(0, INPUT_LINE_NMI,
334      (readinputportbytag("PLAYER2") & 0x80) ? CLEAR_LINE : ASSERT_LINE);
375335}
376336
377READ8_HANDLER( madalien_videoram_r )
337
338static READ8_HANDLER( madalien_shift_lo_r )
378339{
379   return madalien_videoram[offset];
380}
340   const UINT8* table = memory_region(REGION_USER1);
381341
382READ8_HANDLER( madalien_charram_r )
383{
384   return madalien_charram[offset];
342   return table[256 * madalien_shift_count + madalien_shift_data];
385343}
386344
387WRITE8_HANDLER(madalien_video_register_w)
345
346static READ8_HANDLER( madalien_shift_hi_r )
388347{
389   int bit0, bit2, bit3;
348   UINT8 result = 0;
390349
391   if ( madalien_video_register != data )
392   {
393      madalien_video_register = data;
350   UINT8 flip = 0;
394351
395      bit0 = data & 0x01;
396      bit2 = ((data & 0x04) >> 2);
397      bit3 = ((data & 0x08) >> 3);
352   if (BIT(madalien_shift_data, 0)) flip |= 1 << 7;
353   if (BIT(madalien_shift_data, 1)) flip |= 1 << 6;
354   if (BIT(madalien_shift_data, 2)) flip |= 1 << 5;
355   if (BIT(madalien_shift_data, 3)) flip |= 1 << 4;
356   if (BIT(madalien_shift_data, 4)) flip |= 1 << 3;
357   if (BIT(madalien_shift_data, 5)) flip |= 1 << 2;
358   if (BIT(madalien_shift_data, 6)) flip |= 1 << 1;
359   if (BIT(madalien_shift_data, 7)) flip |= 1 << 0;
398360
399      /* Headlight on, if bit 0 is on */
400      madalien_headlight_on = bit0;
361   {
362      const UINT8* table = memory_region(REGION_USER1);
401363
402      /* Swap color bits 1 and 2 of background */
403      if (bit2 != madalien_swap_colors)
404      {
405         madalien_swap_colors = bit2;
406         tilemap_mark_all_tiles_dirty( fg_tilemap );
407      };
364      UINT8 lookup = table[256 * (madalien_shift_count ^ 7) + flip];
408365
409      /* Select map (0=landscape A, 1=tunnel, 2=landscape B, 3=tunnel) */
410      madalien_bg_map_selector &= 0x01;
411      madalien_bg_map_selector |= (bit3 << 1);
366      if (BIT(lookup, 0)) result |= 1 << 6;
367      if (BIT(lookup, 1)) result |= 1 << 5;
368      if (BIT(lookup, 2)) result |= 1 << 4;
369      if (BIT(lookup, 3)) result |= 1 << 3;
370      if (BIT(lookup, 4)) result |= 1 << 2;
371      if (BIT(lookup, 5)) result |= 1 << 1;
372      if (BIT(lookup, 6)) result |= 1 << 0;
373   }
412374
413      tilemap_mark_all_tiles_dirty( bg_tilemap_l );
414      tilemap_mark_all_tiles_dirty( bg_tilemap_r );
415   };
375   return result;
416376}
417377
418WRITE8_HANDLER( madalien_charram_w )
378
379static WRITE8_HANDLER(madalien_video_flags_w)
419380{
420   if (madalien_charram[offset] != data)
381   data &= 15;
382
383   if (madalien_video_flags != data)
421384   {
422      madalien_charram[offset] = data;
423      tilemap_mark_all_tiles_dirty(fg_tilemap);
385      update_edges(data >> 3);
424386   }
387
388   madalien_video_flags = data;
425389}
426390
427WRITE8_HANDLER( madalien_scroll_light_w )
391
392static WRITE8_HANDLER( madalien_headlight_pos_w )
428393{
429   madalien_scroll_light = data;
394   madalien_headlight_pos = data;
430395}
431396
432WRITE8_HANDLER( madalien_scroll_v_w )
397
398static WRITE8_HANDLER( madalien_scroll_w )
433399{
434   madalien_scroll_v = (255 - (data & 0xfc));
400   int i;
435401
436   madalien_bg_map_selector &= 0x02;
437   madalien_bg_map_selector |= (data & 0x01);
402   // bits #0 and #1 define scrolling mode
403   //
404   // mode 0 - cycle over map section A
405   // mode 1 - cycle over map section B
406   //
407   // mode 2 - transition from B to A
408   // mode 3 - transition from A to B
438409
439   madalien_select_color_1 = (data & 0x01);
410   for (i = 0; i < 4; i++)
411   {
412      tilemap_set_scrollx(
413         tilemap_edge1[i], 0, -(data & 0xfc));
414      tilemap_set_scrollx(
415         tilemap_edge2[i], 0, -(data & 0xfc));
416   }
440417
441   tilemap_mark_all_tiles_dirty( bg_tilemap_l );
442   tilemap_mark_all_tiles_dirty( bg_tilemap_r );
443   tilemap_mark_all_tiles_dirty( fg_tilemap );
418   madalien_scroll = data;
444419}
445420
446WRITE8_HANDLER( madalien_scroll_l_w )
421
422static WRITE8_HANDLER( madalien_edge1_pos_w )
447423{
448   madalien_scroll_l = data;
424   madalien_edge1_pos = data & 0x7f;
425
426   tilemap_set_scrolly(tilemap_edge1[0], 0, madalien_edge1_pos);
427   tilemap_set_scrolly(tilemap_edge1[1], 0, madalien_edge1_pos);
428   tilemap_set_scrolly(tilemap_edge1[2], 0, madalien_edge1_pos);
429   tilemap_set_scrolly(tilemap_edge1[3], 0, madalien_edge1_pos);
449430}
450431
451WRITE8_HANDLER( madalien_scroll_r_w )
432
433static WRITE8_HANDLER( madalien_edge2_pos_w )
452434{
453   madalien_scroll_r = data;
435   madalien_edge2_pos = data & 0x7f;
436
437   tilemap_set_scrolly(tilemap_edge2[0], 0, madalien_edge2_pos);
438   tilemap_set_scrolly(tilemap_edge2[1], 0, madalien_edge2_pos);
439   tilemap_set_scrolly(tilemap_edge2[2], 0, madalien_edge2_pos);
440   tilemap_set_scrolly(tilemap_edge2[3], 0, madalien_edge2_pos);
454441}
455442
456WRITE8_HANDLER( madalien_shift_counter_w )
443
444static WRITE8_HANDLER( madalien_shift_data_w )
457445{
458   madalien_shift_counter = data & 0x07;
446   madalien_shift_data = data;
459447}
460
461static UINT8 reverse_bits( int x )   /* bit reversal by wiring in Mad Alien hardware */
448static WRITE8_HANDLER( madalien_shift_count_w )
462449{
463   int bit, n;
464   n = 0;
465   for (bit=0; bit<8; bit++)
466      if (x & (1 << bit))
467         n |= (1 << (7-bit));
468   return n;
450   madalien_shift_count = data & 7;
469451}
470452
471static UINT8 swap_bits( int x )   /* special bit swap by wiring in Mad Alien hardware */
453
454static WRITE8_HANDLER( madalien_screen_control_w )
472455{
473   int n = 0;
474   if (x & 0x40) n |= 0x01;
475   if (x & 0x20) n |= 0x02;
476   if (x & 0x10) n |= 0x04;
477   if (x & 0x08) n |= 0x08;
478   if (x & 0x04) n |= 0x10;
479   if (x & 0x02) n |= 0x20;
480   if (x & 0x01) n |= 0x40;
481   return n;
482}
456   /* bit #0 is set during player 2's turn, bit #3 is set during CRTC initialization */
483457
484WRITE8_HANDLER( madalien_shift_reg_w )
485{
486   int rom_addr_0, rom_addr_1;
487   rom_addr_0 = madalien_shift_counter * 256 + data;
488   rom_addr_1 = ((madalien_shift_counter^0x07) & 0x07) * 256 + reverse_bits(data);
489   madalien_shift_reg_lo = madalien_shift_data[rom_addr_0];
490   madalien_shift_reg_hi = swap_bits( madalien_shift_data[rom_addr_1] );
458   madalien_screen_control = data & 15;
491459}
492460
493WRITE8_HANDLER( madalien_videoram_w )
461
462static WRITE8_HANDLER( madalien_output_w )
494463{
495   madalien_videoram[offset] = data;
496   tilemap_mark_tile_dirty(fg_tilemap, offset);
464   /* output latch, eight output bits, none connected */
497465}
498466
499WRITE8_HANDLER( madalien_flip_screen_w )
467
468static WRITE8_HANDLER( madalien_sound_command_w )
500469{
501   if (readinputport(1) & 0x40)   /* hack for screen flipping in cocktail mode - main board schematics needed */
502      madalien_flip_screen = (data & 1);
503   else
504      madalien_flip_screen = 0;
505}
470   cpunum_set_input_line(1, 0, ASSERT_LINE);
506471
507WRITE8_HANDLER( madalien_sound_command_w )
508{
509472   soundlatch_w(offset, data);
510   cpunum_set_input_line(1, 0, HOLD_LINE);
511473}
512474
513WRITE8_HANDLER( madalien_soundreg_w )
475
476static READ8_HANDLER(madalien_sound_command_r )
514477{
515   madalien_sound_reg = data;
516}
478   cpunum_set_input_line(1, 0, CLEAR_LINE);
517479
518READ8_HANDLER( madalien_soundreg_r )
519{
520   return madalien_sound_reg;
480   return soundlatch_r(offset);
521481}
522482
523483
524static const gfx_layout charlayout_memory =
484static WRITE8_HANDLER( madalien_portA_w )
525485{
526   8,8,    /* 8*8 characters */
527   256,   /* 256 characters */
528   3,      /* 3 bits per pixel */
529   { 2*256*8*8, 256*8*8, 0 },  /* the 3 bitplanes are separated */
530   { 0, 1, 2, 3, 4, 5, 6, 7 },
531   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
532   8*8     /* every char takes 8 consecutive bytes */
533};
534
535static const gfx_layout tilelayout =
486   /* not emulated - amplification? */
487}
488static WRITE8_HANDLER( madalien_portB_w )
536489{
537   16,16,  /* 16*16 tiles */
538   16+1,   /* 16 tiles + 1 empty tile */
539   3,      /* 3 bits per pixel */
540   { 4*16*16*16+4, 2*16*16*16+4, 4 },
541   { 3*16*8+0, 3*16*8+1, 3*16*8+2, 3*16*8+3, 2*16*8+0, 2*16*8+1, 2*16*8+2, 2*16*8+3,
542     16*8+0, 16*8+1, 16*8+2, 16*8+3, 0, 1, 2, 3 },
543   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
544     8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 },
545   64*8    /* every tile takes 64 consecutive bytes */
546};
490   /* not emulated - motor sound? */
491}
547492
548493
549static GFXDECODE_START( madalien )
550   GFXDECODE_ENTRY( 0, 0, charlayout_memory,   0, 8 ) /* characters (the game dynamically modifies them) */
551   GFXDECODE_ENTRY( REGION_GFX1, 0, tilelayout,   0, 8 )   /* background tiles */
552GFXDECODE_END
494static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
495   AM_RANGE(0x0000, 0x03ff) AM_RAM
553496
497   AM_RANGE(0x6000, 0x63ff) AM_RAM AM_BASE(&madalien_videoram)
498   AM_RANGE(0x6400, 0x67ff) AM_RAM
499   AM_RANGE(0x6800, 0x7fff) AM_RAM AM_BASE(&madalien_charram)
554500
555static ADDRESS_MAP_START( madalien_readmem, ADDRESS_SPACE_PROGRAM, 8 )
556   AM_RANGE(0x0000, 0x03ff) AM_READ(MRA8_RAM)         /* Program RAM */
557   AM_RANGE(0x6000, 0x63ff) AM_READ(madalien_videoram_r)      /* Video RAM   */
558   AM_RANGE(0x6800, 0x7fff) AM_READ(madalien_charram_r)      /* Character generator RAM */
559   AM_RANGE(0x8006, 0x8006) AM_READ(soundlatch2_r)         /* Input from sound board */
560   AM_RANGE(0x8008, 0x8008) AM_READ(madalien_shift_reg_lo_r)   /* Low byte of shift reg. after shift operation */
561   AM_RANGE(0x8009, 0x8009) AM_READ(madalien_shift_reg_hi_r)   /* Low byte of shift reg. after shift operation */
562   AM_RANGE(0x9000, 0x9000) AM_READ(input_port_0_r)          /* Input ports */
563   AM_RANGE(0x9001, 0x9001) AM_READ(input_port_1_r)
564   AM_RANGE(0x9002, 0x9002) AM_READ(input_port_2_r)
565   AM_RANGE(0xb000, 0xffff) AM_READ(MRA8_ROM)         /* Program ROM */
566ADDRESS_MAP_END
501   AM_RANGE(0x8000, 0x8000) AM_MIRROR(0x0ff0) AM_WRITE(crtc6845_address_w)
502   AM_RANGE(0x8001, 0x8001) AM_MIRROR(0x0ff0) AM_READWRITE(crtc6845_register_r, crtc6845_register_w)
503   AM_RANGE(0x8004, 0x8004) AM_MIRROR(0x0ff0) AM_WRITE(madalien_screen_control_w)
504   AM_RANGE(0x8005, 0x8005) AM_MIRROR(0x0ff0) AM_WRITE(madalien_output_w)
505   AM_RANGE(0x8006, 0x8006) AM_MIRROR(0x0ff0) AM_READWRITE(soundlatch2_r, madalien_sound_command_w)
506   AM_RANGE(0x8008, 0x8008) AM_MIRROR(0x07f0) AM_READWRITE(madalien_shift_lo_r, madalien_shift_count_w)
507   AM_RANGE(0x8009, 0x8009) AM_MIRROR(0x07f0) AM_READWRITE(madalien_shift_hi_r, madalien_shift_data_w)
508   AM_RANGE(0x800b, 0x800b) AM_MIRROR(0x07f0) AM_WRITE(madalien_video_flags_w)
509   AM_RANGE(0x800c, 0x800c) AM_MIRROR(0x07f0) AM_WRITE(madalien_headlight_pos_w)
510   AM_RANGE(0x800d, 0x800d) AM_MIRROR(0x07f0) AM_WRITE(madalien_edge1_pos_w)
511   AM_RANGE(0x800e, 0x800e) AM_MIRROR(0x07f0) AM_WRITE(madalien_edge2_pos_w)
512   AM_RANGE(0x800f, 0x800f) AM_MIRROR(0x07f0) AM_WRITE(madalien_scroll_w)
567513
514   AM_RANGE(0x9000, 0x9000) AM_MIRROR(0x0ff0) AM_READ(input_port_0_r)
515   AM_RANGE(0x9001, 0x9001) AM_MIRROR(0x0ff0) AM_READ(input_port_1_r)
516   AM_RANGE(0x9002, 0x9002) AM_MIRROR(0x0ff0) AM_READ(input_port_2_r)
568517
569
570static ADDRESS_MAP_START( madalien_writemem, ADDRESS_SPACE_PROGRAM, 8 )
571   AM_RANGE(0x0000, 0x03ff) AM_WRITE(MWA8_RAM)                  /* Normal RAM */
572   AM_RANGE(0x6000, 0x63ff) AM_WRITE(madalien_videoram_w) AM_BASE(&madalien_videoram)   /* Video RAM   */
573   AM_RANGE(0x6800, 0x7fff) AM_WRITE(madalien_charram_w)  AM_BASE(&madalien_charram)   /* Character generator RAM */
574   AM_RANGE(0x8004, 0x8004) AM_WRITE(madalien_flip_screen_w)      /* Flip screen in cocktail mode */
575   AM_RANGE(0x8006, 0x8006) AM_WRITE(madalien_sound_command_w)      /* Command to sound board */
576   AM_RANGE(0x8008, 0x8008) AM_WRITE(madalien_shift_counter_w)       /* Set counter for shifter circuitry */
577   AM_RANGE(0x8009, 0x8009) AM_WRITE(madalien_shift_reg_w)       /* Put data to be shifted */
578   AM_RANGE(0x800b, 0x800b) AM_WRITE(madalien_video_register_w)      /* Video register (light/color/landscape) */
579   AM_RANGE(0x800c, 0x800c) AM_WRITE(madalien_scroll_light_w)      /* Car headlight horiz. scroll register */
580   AM_RANGE(0x800d, 0x800d) AM_WRITE(madalien_scroll_l_w)      /* Background horiz. scroll register left part */
581   AM_RANGE(0x800e, 0x800e) AM_WRITE(madalien_scroll_r_w)      /* Background horiz. scroll register right part */
582   AM_RANGE(0x800f, 0x800f) AM_WRITE(madalien_scroll_v_w)       /* Background vertical scroll register */
583   AM_RANGE(0xb000, 0xffff) AM_WRITE(MWA8_ROM)         /* Program ROM */
518   AM_RANGE(0xa000, 0xffff) AM_ROM
584519ADDRESS_MAP_END
585520
586521
587static ADDRESS_MAP_START( sound_readmem, ADDRESS_SPACE_PROGRAM, 8 )
588   AM_RANGE(0x0000, 0x03ff) AM_READ(MRA8_RAM)      /* Sound board RAM */
589   AM_RANGE(0x6800, 0x6800) AM_READ(madalien_soundreg_r)   /* Sound board register, just to write in and read out */
590   AM_RANGE(0x8000, 0x8000) AM_READ(soundlatch_r)      /* Sound board input from master CPU */
591   AM_RANGE(0xf800, 0xffff) AM_READ(MRA8_ROM)      /* Sound board program ROM */
522static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 )
523   AM_RANGE(0x0000, 0x03ff) AM_MIRROR(0x1c00) AM_RAM
524   AM_RANGE(0x6000, 0x6003) AM_MIRROR(0x1ffc) AM_RAM /* unknown device in an epoxy block, might be tilt detection */
525   AM_RANGE(0x8000, 0x8000) AM_MIRROR(0x1ffc) AM_READ(madalien_sound_command_r)
526   AM_RANGE(0x8000, 0x8000) AM_MIRROR(0x1ffc) AM_WRITE(AY8910_control_port_0_w)
527   AM_RANGE(0x8001, 0x8001) AM_MIRROR(0x1ffc) AM_WRITE(AY8910_write_port_0_w)
528   AM_RANGE(0x8002, 0x8002) AM_MIRROR(0x1ffc) AM_WRITE(soundlatch2_w)
529   AM_RANGE(0xf800, 0xffff) AM_ROM
592530ADDRESS_MAP_END
593531
594static ADDRESS_MAP_START( sound_writemem, ADDRESS_SPACE_PROGRAM, 8 )
595   AM_RANGE(0x0000, 0x03ff) AM_WRITE(MWA8_RAM)         /* Sound board RAM */
596   AM_RANGE(0x6500, 0x6500) AM_WRITE(madalien_soundreg_w)      /* Sound board register */
597   AM_RANGE(0x8000, 0x8000) AM_WRITE(AY8910_control_port_0_w)   /* AY-3-8910 control port */
598   AM_RANGE(0x8001, 0x8001) AM_WRITE(AY8910_write_port_0_w)   /* AY-3-8910 data port */
599   AM_RANGE(0x8006, 0x8006) AM_WRITE(soundlatch2_w)      /* Sound board output to master CPU */
600   AM_RANGE(0xf800, 0xffff) AM_WRITE(MWA8_ROM)         /* Sound board program ROM */
601ADDRESS_MAP_END
602532
603
604
605533INPUT_PORTS_START( madalien )
606   PORT_START
534   PORT_START_TAG("PLAYER1")
607535   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
608536   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
609537   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
r1215r1216
611539   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
612540   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
613541   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
614   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED )
542   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
615543
616   PORT_START
617   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives ) )
544   PORT_START_TAG("DIP")
545   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives )) PORT_DIPLOCATION("SW:1,2")
618546   PORT_DIPSETTING(   0x00, "3" )
619547   PORT_DIPSETTING(   0x01, "4" )
620548   PORT_DIPSETTING(   0x02, "5" )
621549   PORT_DIPSETTING(   0x03, "6" )
622   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coinage ) )
550   PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage )) PORT_DIPLOCATION("SW:3,4")
623551   PORT_DIPSETTING(   0x0c, DEF_STR( 2C_1C ) )
624552   PORT_DIPSETTING(   0x00, DEF_STR( 1C_1C ) )
625553   PORT_DIPSETTING(   0x04, DEF_STR( 1C_2C ) )
626   PORT_DIPNAME( 0x30, 0x30, "Bonus_points" )
554   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life )) PORT_DIPLOCATION("SW:5,6")
627555   PORT_DIPSETTING(    0x00, "3000" )
628   PORT_DIPSETTING(    0x20, "5000" )
629   PORT_DIPSETTING(    0x10, "7000"  )
630   PORT_DIPSETTING(    0x30, "nil"  )
631   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Cabinet ) )
632   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
633   PORT_DIPSETTING(    0x40, DEF_STR( Cocktail ) )
634   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_VBLANK  )
556   PORT_DIPSETTING(    0x10, "5000" )
557   PORT_DIPSETTING(    0x20, "7000" )
558   PORT_DIPSETTING(    0x30, "never" )
559   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Cabinet )) PORT_DIPLOCATION("SW:8")
560   PORT_DIPSETTING(    0x00, DEF_STR( Upright ))
561   PORT_DIPSETTING(    0x40, DEF_STR( Cocktail ))
562   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_VBLANK )
635563
636   PORT_START
564   PORT_START_TAG("PLAYER2")
637565   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
638566   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
639567   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
640568   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
641569   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
642   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNUSED )
643   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNUSED )
644   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED )
645
646   PORT_START   /* Fake port or coin: coin insertion triggers an NMI */
647   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
648   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
570   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
571   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
572   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 ) /* or service coin */
649573INPUT_PORTS_END
650574
651575
652576
577static const UINT32 headlight_xoffset[] =
578{
579   STEP8(0x78, 1),
580   STEP8(0x70, 1),
581   STEP8(0x68, 1),
582   STEP8(0x60, 1),
583   STEP8(0x58, 1),
584   STEP8(0x50, 1),
585   STEP8(0x48, 1),
586   STEP8(0x40, 1),
587   STEP8(0x38, 1),
588   STEP8(0x30, 1),
589   STEP8(0x28, 1),
590   STEP8(0x20, 1),
591   STEP8(0x18, 1),
592   STEP8(0x10, 1),
593   STEP8(0x08, 1),
594   STEP8(0x00, 1),
595};
596
597static const UINT32 headlight_yoffset[] =
598{
599   STEP32(0x0000, 0x80), STEP32(0x1000, 0x80)
600};
601
602static const gfx_layout headlightlayout =
603{
604   128, 64,
605   1,
606   1,
607   { 0 },
608   EXTENDED_XOFFS,
609   EXTENDED_YOFFS,
610   0x2000,
611   headlight_xoffset,
612   headlight_yoffset
613};
614
615static const gfx_layout charlayout =
616{
617   8, 8,
618   256,
619   3,
620   { 2*0x4000, 1*0x4000, 0*0x4000 },
621   { STEP8(0, 1) },
622   { STEP8(0, 8) },
623   64
624};
625
626static const gfx_layout tilelayout =
627{
628   16, 16,
629   RGN_FRAC(1,3),
630   3,
631   { RGN_FRAC(2,3), RGN_FRAC(1,3), RGN_FRAC(0,3) },
632   {
633      0x30*8+4, 0x30*8+5, 0x30*8+6, 0x30*8+7,
634      0x20*8+4, 0x20*8+5, 0x20*8+6, 0x20*8+7,
635      0x10*8+4, 0x10*8+5, 0x10*8+6, 0x10*8+7,
636      0x00*8+4, 0x00*8+5, 0x00*8+6, 0x00*8+7
637   },
638   { STEP16(0, 8) },
639   0x200
640};
641
642
643static GFXDECODE_START( madalien )
644   GFXDECODE_ENTRY( 0, 0, charlayout, 32, 2 ) /* foreground characters, stored in RAM */
645   GFXDECODE_ENTRY( REGION_GFX1, 0, tilelayout, 0, 4 )
646   GFXDECODE_ENTRY( REGION_GFX3, 0, headlightlayout, 0, 1 )
647GFXDECODE_END
648
649
650static struct AY8910interface ay8910_interface =
651{
652   NULL,
653   NULL,
654   madalien_portA_w,
655   madalien_portB_w
656};
657
658
653659static MACHINE_DRIVER_START( madalien )
654660
655   /* basic machine hardware */
656   MDRV_CPU_ADD_TAG("main", M6502, 750000)    /* 750 kHz ? */
657   MDRV_CPU_PROGRAM_MAP(madalien_readmem, madalien_writemem)
661   /* main CPU */
662   MDRV_CPU_ADD_TAG("main", M6502, MAIN_CLOCK / 8)    /* 1324kHz */
663   MDRV_CPU_PROGRAM_MAP(main_map, 0)
658664   MDRV_CPU_VBLANK_INT(madalien_interrupt, 1)
659665
660   MDRV_CPU_ADD_TAG("sound", M6502, 500000)   /* 500 kHz ? */
661666   /* audio CPU */
662   MDRV_CPU_PROGRAM_MAP(sound_readmem, sound_writemem)
663   MDRV_CPU_VBLANK_INT(nmi_line_pulse, 16)
667   MDRV_CPU_ADD_TAG("sound", M6502, SOUND_CLOCK / 8)   /* 512kHz */
668   MDRV_CPU_PROGRAM_MAP(sound_map, 0)
669   MDRV_CPU_PERIODIC_INT(nmi_line_pulse, 800)    /* unknown due to incomplete schematics */
664670
665   MDRV_SCREEN_REFRESH_RATE(60)
666   MDRV_SCREEN_VBLANK_TIME(USEC_TO_SUBSECONDS(3072))
667
668671   /* video hardware */
669672   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
673   MDRV_SCREEN_RAW_PARAMS(PIXEL_CLOCK, 336, 0, 256, 288, 0, 256)
670674   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
671   MDRV_SCREEN_SIZE(32*8, 32*8)
672   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 0*8, 32*8-1)
673675   MDRV_GFXDECODE(madalien)
674   MDRV_PALETTE_LENGTH(2*32)
676   MDRV_PALETTE_LENGTH(32)
677   MDRV_COLORTABLE_LENGTH(48)
675678   MDRV_PALETTE_INIT(madalien)
676679   MDRV_VIDEO_START(madalien)
677680   MDRV_VIDEO_UPDATE(madalien)
r1215r1216
679682   /* sound hardware */
680683   MDRV_SPEAKER_STANDARD_MONO("mono")
681684
682   MDRV_SOUND_ADD(AY8910, 500000)
685   MDRV_SOUND_ADD(AY8910, SOUND_CLOCK / 4)
686   MDRV_SOUND_CONFIG(ay8910_interface)
683687   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.23)
684688MACHINE_DRIVER_END
685689
686690
687691ROM_START( madalien )
688   ROM_REGION( 0x10000, REGION_CPU1, 0 )           /* 64k for 6502 code of main CPU */
689   ROM_LOAD( "m7",   0xc000, 0x0800, CRC(4d12f89d) SHA1(e155f9135bc2bea56e211052f2b74d25e76308c8) )
690   ROM_LOAD( "m6",   0xc800, 0x0800, CRC(1bc4a57b) SHA1(02252b868d0c07c0a18240e9d831c303cdcfa9a6) )
691   ROM_LOAD( "m5",   0xd000, 0x0800, CRC(8db99572) SHA1(f8cf22f8c134b47756b7f02c5ca0217100466744) )
692   ROM_LOAD( "m4",   0xd800, 0x0800, CRC(fba671af) SHA1(dd74bd357c82d525948d836a7f860bbb3182c825) )
693   ROM_LOAD( "m3",   0xe000, 0x0800, CRC(1aad640d) SHA1(9ace7d2c5ef9e789c2b8cc65420b19ce72cd95fa) )
694   ROM_LOAD( "m2",   0xe800, 0x0800, CRC(cbd533a0) SHA1(d3be81fb9ba40e30e5ff0171efd656b11dd20f2b) )
695   ROM_LOAD( "m1",   0xf000, 0x0800, CRC(ad654b1d) SHA1(f8b365dae3801e97e04a10018a790d3bdb5d9439) )
696   ROM_LOAD( "m0",   0xf800, 0x0800, CRC(cf7aa787) SHA1(f852cc806ecc582661582326747974a14f50174a) )
692   ROM_REGION( 0x10000, REGION_CPU1, 0 )                   /* main CPU */
693   ROM_LOAD( "m7.3f",   0xc000, 0x0800, CRC(4d12f89d) SHA1(e155f9135bc2bea56e211052f2b74d25e76308c8) )
694   ROM_LOAD( "m6.3h",   0xc800, 0x0800, CRC(1bc4a57b) SHA1(02252b868d0c07c0a18240e9d831c303cdcfa9a6) )
695   ROM_LOAD( "m5.3k",   0xd000, 0x0800, CRC(8db99572) SHA1(f8cf22f8c134b47756b7f02c5ca0217100466744) )
696   ROM_LOAD( "m4.3l",   0xd800, 0x0800, CRC(fba671af) SHA1(dd74bd357c82d525948d836a7f860bbb3182c825) )
697   ROM_LOAD( "m3.4f",   0xe000, 0x0800, CRC(1aad640d) SHA1(9ace7d2c5ef9e789c2b8cc65420b19ce72cd95fa) )
698   ROM_LOAD( "m2.4h",   0xe800, 0x0800, CRC(cbd533a0) SHA1(d3be81fb9ba40e30e5ff0171efd656b11dd20f2b) )
699   ROM_LOAD( "m1.4k",   0xf000, 0x0800, CRC(ad654b1d) SHA1(f8b365dae3801e97e04a10018a790d3bdb5d9439) )
700   ROM_LOAD( "m0.4l",   0xf800, 0x0800, CRC(cf7aa787) SHA1(f852cc806ecc582661582326747974a14f50174a) )
697701
698   ROM_REGION( 0x10000, REGION_CPU2, 0 )           /* 64k for 6502 code of audio CPU */
702   ROM_REGION( 0x10000, REGION_CPU2, 0 )               /* audio CPU */
699703   ROM_LOAD( "m8", 0xf800, 0x0400, CRC(cfd19dab) SHA1(566dc84ffe9bcaeb112250a9e1882bf62f47b579) )
700704   ROM_LOAD( "m9", 0xfc00, 0x0400, CRC(48f30f24) SHA1(9c0bf6e43b143d6af1ebb9dad2bdc2b53eb2e48e) )
701705
702   ROM_REGION( 0x1000, REGION_GFX1, ROMREGION_DISPOSE )   /* Background tiles */
703   ROM_LOAD( "mc", 0x0000, 0x0400, CRC(2daadfb7) SHA1(8be084a39b256e538fd57111e92d47115cb142cd) )
704   ROM_LOAD( "md", 0x0400, 0x0400, CRC(3ee1287a) SHA1(33bc59a8d09d22f3db80f881c2f37aa788718138) )
705   ROM_LOAD( "me", 0x0800, 0x0400, CRC(45a5c201) SHA1(ac600afeabf494634c3189d8e96644bd0deb45f3) )
706   ROM_REGION( 0x0c00, REGION_GFX1, ROMREGION_DISPOSE )    /* background tiles */
707   ROM_LOAD( "mc.3k", 0x0000, 0x0400, CRC(2daadfb7) SHA1(8be084a39b256e538fd57111e92d47115cb142cd) )
708   ROM_LOAD( "md.3l", 0x0400, 0x0400, CRC(3ee1287a) SHA1(33bc59a8d09d22f3db80f881c2f37aa788718138) )
709   ROM_LOAD( "me.3m", 0x0800, 0x0400, CRC(45a5c201) SHA1(ac600afeabf494634c3189d8e96644bd0deb45f3) )
706710
707   ROM_REGION( 0x0400, REGION_GFX2, 0 )           /* Background tile maps */
708   ROM_LOAD( "mf", 0x0000, 0x0400, CRC(e9cba773) SHA1(356c7edb1b412a9e04f0747e780c945af8791c55) )
711   ROM_REGION( 0x0400, REGION_GFX2, 0 )                    /* background tile map */
712   ROM_LOAD( "mf.4h", 0x0000, 0x0400, CRC(e9cba773) SHA1(356c7edb1b412a9e04f0747e780c945af8791c55) )
709713
710   ROM_REGION( 0x0400, REGION_GFX3, 0 )         /* Car headlight */
711   ROM_LOAD( "ma", 0x0000, 0x0400, CRC(aab16446) SHA1(d2342627cc2766004343f27515d8a7989d5fe932) )
714   ROM_REGION( 0x0400, REGION_GFX3, ROMREGION_DISPOSE )    /* headlight */
715   ROM_LOAD( "ma.2b", 0x0000, 0x0400, CRC(aab16446) SHA1(d2342627cc2766004343f27515d8a7989d5fe932) )
712716
713   ROM_REGION( 0x0800, REGION_GFX4, 0 )         /* Shifting data */
714   ROM_LOAD( "mb", 0x0000, 0x0800, CRC(cb801e49) SHA1(7444c4af7cf07e5fdc54044d62ea4fcb201b2b8b) )
717   ROM_REGION( 0x0800, REGION_USER1, 0 )                   /* shifting table */
718   ROM_LOAD( "mb.5c", 0x0000, 0x0800, CRC(cb801e49) SHA1(7444c4af7cf07e5fdc54044d62ea4fcb201b2b8b) )
715719
716   ROM_REGION( 0x0020, REGION_PROMS, 0 )          /* Color PROM */
717   ROM_LOAD( "mg",   0x0000, 0x0020, CRC(3395b31f) SHA1(26235fb448a4180c58f0887e53a29c17857b3b34) )
720   ROM_REGION( 0x0020, REGION_PROMS, 0 )                   /* color PROM */
721   ROM_LOAD( "mg.7f",   0x0000, 0x0020, CRC(3395b31f) SHA1(26235fb448a4180c58f0887e53a29c17857b3b34) )
718722ROM_END
719723
720724
721725ROM_START( madalina )
722   ROM_REGION( 0x10000, REGION_CPU1, 0 )          /* 64k for 6502 code of main CPU */
723   ROM_LOAD( "2716.4c",        0xb000, 0x0800, CRC(90be68af) SHA1(472ccfd2e04d6d49be47d919cba0c55d850b2887) )
724   ROM_LOAD( "2716.4e",        0xb800, 0x0800, CRC(aba10cbb) SHA1(6ca213ded8ed7f4f310ab5ae25220cf867dd1d00) )
725   ROM_LOAD( "2716.3f",        0xc000, 0x0800, CRC(c3af484c) SHA1(c3667526d3b5aeee68823f92826053e657512851) )
726   ROM_LOAD( "2716.3j",        0xc800, 0x0800, CRC(78ca5a87) SHA1(729d69ee63c710241a098471e9769063dfe8ef1e) )
727   ROM_LOAD( "2716.3k",        0xd000, 0x0800, CRC(070e81ea) SHA1(006831f4bf289812e4e87a3ece7885e8b901f2f5) )
728   ROM_LOAD( "2716.3l",        0xd800, 0x0800, CRC(98225cb0) SHA1(ca74f5e33fa9116215b03abadd5d09840c04fb0b) )
729   ROM_LOAD( "2716.4f",        0xe000, 0x0800, CRC(52fea0fc) SHA1(443fd859daf4279d5976256a4b1c970b520661a2) )
730   ROM_LOAD( "2716.4j",        0xe800, 0x0800, CRC(dba6c4f6) SHA1(51f815fc7eb99a05eee6204de2d4cad1734adc52) )
731   ROM_LOAD( "2716.4k",        0xf000, 0x0800, CRC(06991af6) SHA1(19112306529721222b6e1c07920348c263d8b8aa) )
732   ROM_LOAD( "2716.4l",        0xf800, 0x0800, CRC(57752b47) SHA1(a34d3150ea9082889154042dbea3386f71322a78) )
726   ROM_REGION( 0x10000, REGION_CPU1, 0 )                   /* main CPU */
727   ROM_LOAD( "2716.4c", 0xb000, 0x0800, CRC(90be68af) SHA1(472ccfd2e04d6d49be47d919cba0c55d850b2887) )
728   ROM_LOAD( "2716.4e", 0xb800, 0x0800, CRC(aba10cbb) SHA1(6ca213ded8ed7f4f310ab5ae25220cf867dd1d00) )
729   ROM_LOAD( "2716.3f", 0xc000, 0x0800, CRC(c3af484c) SHA1(c3667526d3b5aeee68823f92826053e657512851) )
730   ROM_LOAD( "2716.3h", 0xc800, 0x0800, CRC(78ca5a87) SHA1(729d69ee63c710241a098471e9769063dfe8ef1e) )
731   ROM_LOAD( "2716.3k", 0xd000, 0x0800, CRC(070e81ea) SHA1(006831f4bf289812e4e87a3ece7885e8b901f2f5) )
732   ROM_LOAD( "2716.3l", 0xd800, 0x0800, CRC(98225cb0) SHA1(ca74f5e33fa9116215b03abadd5d09840c04fb0b) )
733   ROM_LOAD( "2716.4f", 0xe000, 0x0800, CRC(52fea0fc) SHA1(443fd859daf4279d5976256a4b1c970b520661a2) )
734   ROM_LOAD( "2716.4h", 0xe800, 0x0800, CRC(dba6c4f6) SHA1(51f815fc7eb99a05eee6204de2d4cad1734adc52) )
735   ROM_LOAD( "2716.4k", 0xf000, 0x0800, CRC(06991af6) SHA1(19112306529721222b6e1c07920348c263d8b8aa) )
736   ROM_LOAD( "2716.4l", 0xf800, 0x0800, CRC(57752b47) SHA1(a34d3150ea9082889154042dbea3386f71322a78) )
733737
734   ROM_REGION( 0x10000, REGION_CPU2, 0 )           /* 64k for 6502 code of audio CPU */
735   ROM_LOAD( "8_2708.4d",      0xf800, 0x0400, CRC(46162e7e) SHA1(7ed85f4a9ac58d6d9bafba0c843a16c269656563) )
736   ROM_LOAD( "9_2708.3d",      0xfc00, 0x0400, CRC(4175f5c4) SHA1(45cae8a1fcfd34b91c63cc7e544a32922da14f16) )
738   ROM_REGION( 0x10000, REGION_CPU2, 0 )                   /* audio CPU */
739   ROM_LOAD( "8_2708.4d", 0xf800, 0x0400, CRC(46162e7e) SHA1(7ed85f4a9ac58d6d9bafba0c843a16c269656563) )
740   ROM_LOAD( "9_2708.3d", 0xfc00, 0x0400, CRC(4175f5c4) SHA1(45cae8a1fcfd34b91c63cc7e544a32922da14f16) )
737741
738   ROM_REGION( 0x1000, REGION_GFX1, ROMREGION_DISPOSE )    /* Background tiles */
739   ROM_LOAD( "mc-1_82s137.3k", 0x0000, 0x0400, NO_DUMP )
740   ROM_LOAD( "me-1_82s137.3l", 0x0400, 0x0400, CRC(7328a425) SHA1(327adc8b0e25d93f1ae98a44c26d0aaaac1b1a9c) )
741   ROM_LOAD( "md-1_82s137.3m", 0x0800, 0x0400, CRC(b5329929) SHA1(86890e1b7cc8cb31fc0dcbc2d3cff02e4cf95619) )
742   ROM_REGION( 0x0c00, REGION_GFX1, ROMREGION_DISPOSE )    /* background tiles */
743   ROM_LOAD( "mc-1.3k", 0x0000, 0x0400, NO_DUMP )
744   ROM_LOAD( "me-1.3l", 0x0400, 0x0400, CRC(7328a425) SHA1(327adc8b0e25d93f1ae98a44c26d0aaaac1b1a9c) )
745   ROM_LOAD( "md-1.3m", 0x0800, 0x0400, CRC(b5329929) SHA1(86890e1b7cc8cb31fc0dcbc2d3cff02e4cf95619) )
742746
743   ROM_REGION( 0x0400, REGION_GFX2, 0 )           /* Background tile maps */
744   ROM_LOAD( "mf-1_82s137.4h", 0x0000, 0x0400, CRC(9b04c446) SHA1(918013f3c0244ab6a670b9d1b6b642298e2c5ab8) )
747   ROM_REGION( 0x0400, REGION_GFX2, 0 )                    /* background tile map */
748   ROM_LOAD( "mf-1.4h", 0x0000, 0x0400, CRC(9b04c446) SHA1(918013f3c0244ab6a670b9d1b6b642298e2c5ab8) )
745749
746   ROM_REGION( 0x0400, REGION_GFX3, 0 )         /* Car headlight */
747   ROM_LOAD( "ma-_2708.2b",    0x0000, 0x0400, CRC(aab16446) SHA1(d2342627cc2766004343f27515d8a7989d5fe932) )
750   ROM_REGION( 0x0400, REGION_GFX3, ROMREGION_DISPOSE )    /* headlight */
751   ROM_LOAD( "ma.2b", 0x0000, 0x0400, CRC(aab16446) SHA1(d2342627cc2766004343f27515d8a7989d5fe932) )
748752
749   ROM_REGION( 0x0800, REGION_GFX4, 0 )         /* Shifting data */
750   ROM_LOAD( "mb-_2716.5c",    0x0000, 0x0800, CRC(cb801e49) SHA1(7444c4af7cf07e5fdc54044d62ea4fcb201b2b8b) )
753   ROM_REGION( 0x0800, REGION_USER1, 0 )                   /* shifting table */
754   ROM_LOAD( "mb.5c", 0x0000, 0x0800, CRC(cb801e49) SHA1(7444c4af7cf07e5fdc54044d62ea4fcb201b2b8b) )
751755
752   ROM_REGION( 0x0020, REGION_PROMS, 0 )          /* Color PROM */
753   ROM_LOAD( "mg-1_82s123.7e", 0x0000, 0x0020, CRC(e622396a) SHA1(8972704bd25fed462e25c453771cc5ca4fc74034) )
756   ROM_REGION( 0x0020, REGION_PROMS, 0 )                   /* color PROM */
757   ROM_LOAD( "mg-1.7f", 0x0000, 0x0020, CRC(e622396a) SHA1(8972704bd25fed462e25c453771cc5ca4fc74034) )
754758ROM_END
755759
756760
757DRIVER_INIT( madalien )
761static DRIVER_INIT( madalien )
758762{
759   madalien_shift_counter = 0;
760   madalien_shift_reg_lo  = 0;
761   madalien_shift_reg_hi  = 0;
762   madalien_bg_map_selector = 0;
763   madalien_scroll_light = 0;
764   madalien_select_color_1 = 0;
765   madalien_select_color_2 = 0;
766   madalien_headlight_on = 0;
767   madalien_swap_colors = 0;
768   madalien_video_register = 0;
769   madalien_flip_screen = 0;
763   state_save_register_global(madalien_video_flags);
764   state_save_register_global(madalien_screen_control);
765   state_save_register_global(madalien_scroll);
766   state_save_register_global(madalien_edge1_pos);
767   state_save_register_global(madalien_edge2_pos);
768   state_save_register_global(madalien_headlight_pos);
769   state_save_register_global(madalien_shift_count);
770   state_save_register_global(madalien_shift_data);
770771}
771772
772773
773774/*          rom       parent     machine   inp       init */
774GAME( 1980, madalien, 0,         madalien, madalien, madalien, ROT270, "Data East Corporation", "Mad Alien", 0 )
775GAME( 1980, madalina, madalien,  madalien, madalien, madalien, ROT270, "Data East Corporation", "Mad Alien (Highway Chase)", 0 )
775GAME( 1980, madalien, 0,         madalien, madalien, madalien, ROT270, "Data East Corporation", "Mad Alien", GAME_IMPERFECT_SOUND )
776GAME( 1980, madalina, madalien,  madalien, madalien, madalien, ROT270, "Data East Corporation", "Mad Alien (Highway Chase)", GAME_IMPERFECT_SOUND )
src/mame/drivers/zr107.c
r1215r1216
11/*  Konami ZR107 System
22
33    Driver by Ville Linde
4
5
6
7    Hardware overview:
8
9    ZR107 CPU board:
10    ----------------
11        IBM PowerPC 403GA at 32MHz (main CPU)
12        Motorola MC68EC000 at 16MHz (sound CPU)
13        Konami K056800 (MIRAC), sound system interface
14        Konami K056230 (LANC), LAN interface
15        Konami K058141 sound chip (same as 2x K054539)
16
17    ZR107 GFX board:
18    ----------------
19        Analog Devices ADSP-21062 SHARC DSP at 36MHz
20        Konami K056832 tilemap chip
21        KS10071 (custom 3D pixel unit)
22        KS10081 (custom 3D texel unit)
23
24    GN678 GFX board (same as in gticlub.c):
25    ----------------
26        Analog Devices ADSP-21062 SHARC DSP at 36MHz
27        Konami K001604 (2D tilemaps + 2x ROZ)
28        2x KS10071 (custom 3D pixel unit)
29        2x KS10081 (custom 3D texel unit)
30
31
32    Hardware configurations:
33
34    Game                           | ID        | CPU PCB      | CG Board(s)
35    --------------------------------------------------------------------------
36    Midnight Run                   | GX???     | ZR107        | ZR107
37    Winding Heat                   | GX677     | ZR107        | ZR107
38    Jetwave / Waveshark            | GX678     | ZR107        | GN678
39
440*/
541
642#include "driver.h"
r1215r1216
1551#include "video/gticlub.h"
1652
1753
54static UINT8 led_reg0 = 0x7f, led_reg1 = 0x7f;
1855
56
1957// defined in drivers/gticlub.c
2058extern READ32_HANDLER(lanc_r);
2159extern WRITE32_HANDLER(lanc_w);
r1215r1216
2361extern WRITE32_HANDLER(lanc_ram_w);
2462
2563
64// defined in video/gticlub.c
65VIDEO_START( gticlub );
66VIDEO_UPDATE( gticlub );
2667
27static UINT8 led_reg0 = 0x7f, led_reg1 = 0x7f;
2868
69// defined in drivers/nwk-tr.c
70int K001604_vh_start(running_machine *machine, int chip);
71void K001604_tile_update(running_machine *machine, int chip);
72void K001604_draw_front_layer(int chip, mame_bitmap *bitmap, const rectangle *cliprect);
73void K001604_draw_back_layer(int chip, mame_bitmap *bitmap, const rectangle *cliprect);
74READ32_HANDLER(K001604_tile_r);
75READ32_HANDLER(K001604_char_r);
76WRITE32_HANDLER(K001604_tile_w);
77WRITE32_HANDLER(K001604_char_w);
78WRITE32_HANDLER(K001604_reg_w);
79READ32_HANDLER(K001604_reg_r);
80
81
82
83
84VIDEO_START( jetwave )
85{
86   K001005_init();
87   K001604_vh_start(machine, 0);
88}
89
90
91VIDEO_UPDATE( jetwave )
92{
93   fillbitmap(bitmap, machine->remapped_colortable[0], cliprect);
94
95   K001604_tile_update(machine, 0);
96   K001005_draw(bitmap, cliprect);
97
98   K001604_draw_front_layer(0, bitmap, cliprect);
99
100   draw_7segment_led(bitmap, 3, 3, led_reg0);
101   draw_7segment_led(bitmap, 9, 3, led_reg1);
102
103   cpuintrf_push_context(2);
104   sharc_set_flag_input(1, ASSERT_LINE);
105   cpuintrf_pop_context();
106   return 0;
107}
108
109
110/*****************************************************************************/
111
29112static WRITE32_HANDLER( paletteram32_w )
30113{
31114   COMBINE_DATA(&paletteram32[offset]);
r1215r1216
244327ADDRESS_MAP_END
245328
246329
330static WRITE32_HANDLER( jetwave_palette_w )
331{
332   COMBINE_DATA(&paletteram32[offset]);
333   data = paletteram32[offset];
334   palette_set_color_rgb(Machine, offset, pal5bit(data >> 10), pal5bit(data >> 5), pal5bit(data >> 0));
335}
247336
337static ADDRESS_MAP_START( jetwave_map, ADDRESS_SPACE_PROGRAM, 32 )
338   AM_RANGE(0x00000000, 0x000fffff) AM_MIRROR(0x80000000) AM_RAM      /* Work RAM */
339   AM_RANGE(0x74000000, 0x740000ff) AM_MIRROR(0x80000000) AM_READWRITE(K001604_reg_r, K001604_reg_w)
340   AM_RANGE(0x74010000, 0x7401ffff) AM_MIRROR(0x80000000) AM_READWRITE(paletteram32_r, jetwave_palette_w) AM_BASE(&paletteram32)
341   AM_RANGE(0x74020000, 0x7403ffff) AM_MIRROR(0x80000000) AM_READWRITE(K001604_tile_r, K001604_tile_w)
342   AM_RANGE(0x74040000, 0x7407ffff) AM_MIRROR(0x80000000) AM_READWRITE(K001604_char_r, K001604_char_w)
343   AM_RANGE(0x78000000, 0x7800ffff) AM_MIRROR(0x80000000) AM_READWRITE(cgboard_dsp_shared_r_ppc, cgboard_dsp_shared_w_ppc)      /* 21N 21K 23N 23K */
344   AM_RANGE(0x78010000, 0x7801ffff) AM_MIRROR(0x80000000) AM_WRITE(cgboard_dsp_shared_w_ppc)
345   AM_RANGE(0x78040000, 0x7804000f) AM_MIRROR(0x80000000) AM_READWRITE(K001006_0_r, K001006_0_w)
346   AM_RANGE(0x78080000, 0x7808000f) AM_MIRROR(0x80000000) AM_READWRITE(K001006_1_r, K001006_1_w)
347   AM_RANGE(0x780c0000, 0x780c0007) AM_MIRROR(0x80000000) AM_READWRITE(cgboard_dsp_comm_r_ppc, cgboard_dsp_comm_w_ppc)
348   AM_RANGE(0x7e000000, 0x7e003fff) AM_MIRROR(0x80000000) AM_READWRITE(sysreg_r, sysreg_w)
349   AM_RANGE(0x7e008000, 0x7e009fff) AM_MIRROR(0x80000000) AM_READWRITE(lanc_r, lanc_w)            /* LANC registers */
350   AM_RANGE(0x7e00a000, 0x7e00bfff) AM_MIRROR(0x80000000) AM_READWRITE(lanc_ram_r, lanc_ram_w)      /* LANC Buffer RAM (27E) */
351   AM_RANGE(0x7e00c000, 0x7e00c007) AM_MIRROR(0x80000000) AM_WRITE(K056800_host_w)
352   AM_RANGE(0x7e00c008, 0x7e00c00f) AM_MIRROR(0x80000000) AM_READ(K056800_host_r)
353   AM_RANGE(0x7f000000, 0x7f3fffff) AM_MIRROR(0x80000000) AM_ROM AM_REGION(REGION_USER2, 0)
354   AM_RANGE(0x7f800000, 0x7f9fffff) AM_MIRROR(0x80000000) AM_ROM AM_SHARE(2)
355   AM_RANGE(0x7fe00000, 0x7fffffff) AM_MIRROR(0x80000000) AM_ROM AM_REGION(REGION_USER1, 0) AM_SHARE(2)   /* Program ROM */
356ADDRESS_MAP_END
357
358
359
248360/**********************************************************************/
249361
250362static READ16_HANDLER( dual539_r )
r1215r1216
391503
392504INPUT_PORTS_END
393505
506INPUT_PORTS_START( jetwave )
507   PORT_START
508   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )
509   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 )
510   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON3 )
511   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 )
512   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Service Button") PORT_CODE(KEYCODE_8)
513   PORT_BIT( 0x0b, IP_ACTIVE_LOW, IPT_UNKNOWN )
514
515   PORT_START
516   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )
517
518   PORT_START
519   PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNKNOWN )
520
521   PORT_START
522   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME( DEF_STR( Service_Mode )) PORT_CODE(KEYCODE_F2)
523   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Service Button") PORT_CODE(KEYCODE_8)
524   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
525   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN2 )
526   PORT_DIPNAME( 0x08, 0x00, "DIP 1" )
527   PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
528   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
529   PORT_DIPNAME( 0x04, 0x04, "DIP 2" )
530   PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
531   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
532   PORT_DIPNAME( 0x02, 0x02, "DIP 3" )
533   PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
534   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
535   PORT_DIPNAME( 0x01, 0x00, "DIP 4" )
536   PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
537   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
538
539   PORT_START_TAG("ANALOG1")      // Steering wheel
540   PORT_BIT( 0xff, 0x80, IPT_PADDLE ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(35) PORT_KEYDELTA(5) PORT_REVERSE
541
542   PORT_START_TAG("ANALOG2")      // Acceleration pedal
543   PORT_BIT( 0xff, 0x00, IPT_PEDAL ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(35) PORT_KEYDELTA(5)
544
545   PORT_START_TAG("ANALOG3")      // Brake pedal
546   PORT_BIT( 0xff, 0x00, IPT_PEDAL2 ) PORT_MINMAX(0x00,0xff) PORT_SENSITIVITY(35) PORT_KEYDELTA(5)
547
548INPUT_PORTS_END
549
394550static ppc_config zr107_ppc_cfg =
395551{
396552   PPC_MODEL_403GA
r1215r1216
461617   MDRV_SOUND_ROUTE(1, "right", 0.75)
462618MACHINE_DRIVER_END
463619
620static MACHINE_DRIVER_START( jetwave )
621
622   /* basic machine hardware */
623   MDRV_CPU_ADD(PPC403, 64000000/2)   /* PowerPC 403GA 32MHz */
624   MDRV_CPU_CONFIG(zr107_ppc_cfg)
625   MDRV_CPU_PROGRAM_MAP(jetwave_map, 0)
626   MDRV_CPU_VBLANK_INT(zr107_vblank, 1)
627
628   MDRV_CPU_ADD(M68000, 64000000/8)   /* 8MHz */
629   MDRV_CPU_PROGRAM_MAP(sound_memmap, 0)
630
631   MDRV_CPU_ADD(ADSP21062, 36000000)
632   MDRV_CPU_CONFIG(sharc_cfg)
633   MDRV_CPU_DATA_MAP(sharc_map, 0)
634
635   MDRV_SCREEN_REFRESH_RATE(60)
636   MDRV_INTERLEAVE(500)
637
638   MDRV_NVRAM_HANDLER(93C46)
639   MDRV_MACHINE_RESET(zr107)
640
641    /* video hardware */
642   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
643   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
644   MDRV_SCREEN_SIZE(64*8, 48*8)
645   MDRV_SCREEN_VISIBLE_AREA(0*8, 64*8-1, 0*8, 48*8-1)
646   MDRV_PALETTE_LENGTH(65536)
647
648   MDRV_VIDEO_START(jetwave)
649   MDRV_VIDEO_UPDATE(jetwave)
650
651   MDRV_SPEAKER_STANDARD_STEREO("left", "right")
652
653   MDRV_SOUND_ADD(K054539, 48000)
654   MDRV_SOUND_CONFIG(k054539_interface)
655   MDRV_SOUND_ROUTE(0, "left", 0.75)
656   MDRV_SOUND_ROUTE(1, "right", 0.75)
657
658   MDRV_SOUND_ADD(K054539, 48000)
659   MDRV_SOUND_CONFIG(k054539_interface)
660   MDRV_SOUND_ROUTE(0, "left", 0.75)
661   MDRV_SOUND_ROUTE(1, "right", 0.75)
662MACHINE_DRIVER_END
663
464664/*****************************************************************************/
465665
466666static void sound_irq_callback(int irq)
r1215r1216
487687   adc083x_init(0, ADC0838, adc0838_callback);
488688}
489689
690static DRIVER_INIT(jetwave)
691{
692   init_konami_cgboard(1, CGBOARD_TYPE_GTICLUB);
693   sharc_dataram = auto_malloc(0x100000);
694
695   K001005_preprocess_texture_data(memory_region(REGION_GFX1), memory_region_length(REGION_GFX1), 0);
696
697   K056800_init(sound_irq_callback);
698
699   adc083x_init(0, ADC0838, adc0838_callback);
700}
701
490702/*****************************************************************************/
491703
704#define ROM_LOAD64_WORD(name,offset,length,hash)      ROMX_LOAD(name, offset, length, hash, ROM_GROUPWORD | ROM_SKIP(6))
705
492706ROM_START(midnrun)
493707   ROM_REGION(0x200000, REGION_USER1, 0)   /* PowerPC program roms */
494708   ROM_LOAD32_BYTE("midnight.20u", 0x000003, 0x80000, CRC(ea70edf2) SHA1(51c882383a150ba118ccd39eb869525fcf5eee3c))
r1215r1216
541755        ROM_LOAD( "677a08.5r",    0x400000, 0x200000, CRC(bde38850) SHA1(aaf1bdfc25ecdffc1f6076c9c1b2edbe263171d2) )
542756ROM_END
543757
758ROM_START(jetwave)
759   ROM_REGION(0x200000, REGION_USER1, 0)   /* PowerPC program roms */
760        ROM_LOAD32_BYTE( "678uab01.20u", 0x000003, 0x080000, CRC(a9b9ceed) SHA1(36f0d18481d7c3e7358e02473e54bc6b52d5c26b) )
761        ROM_LOAD32_BYTE( "678uab02.17u", 0x000002, 0x080000, CRC(5ed24ac8) SHA1(d659c751558d4f8d89314466a37c04ac2df46879) )
762        ROM_LOAD32_BYTE( "678uab03.15u", 0x000001, 0x080000, CRC(f4a595e7) SHA1(e05e7ea6613ecf70d8470af5fe0c6a7274c6e45b) )
763        ROM_LOAD32_BYTE( "678uab04.13u", 0x000000, 0x080000, CRC(fd3320a7) SHA1(03a50a7bba9eb7cdb9f84953d6fb5c09f2d4b2db) )
764
765   ROM_REGION(0x20000, REGION_CPU2, 0)      /* M68K program */
766        ROM_LOAD16_WORD_SWAP( "678a07.19l",   0x000000, 0x020000, CRC(bb3f5875) SHA1(97f80d9b55d4177217b7cd1ba14e8ed2d64376bb) )
767
768   ROM_REGION32_BE(0x400000, REGION_USER2, 0)   /* data roms */
769        ROM_LOAD32_WORD_SWAP( "685a05.10u",   0x000000, 0x200000, CRC(00e59741) SHA1(d799910d4e85482b0e92a3cc9043f81d97b2fb02) )
770        ROM_LOAD32_WORD_SWAP( "685a06.8u",   0x000002, 0x200000, CRC(fc98c6a5) SHA1(a84583bb7296fa9e0c284b2ac59e2dc7b2689eee) )
771
772   ROM_REGION(0x800000, REGION_GFX1, 0)   /* Texture data */
773        ROM_LOAD64_WORD( "678a13.18d",   0x000000, 0x200000, CRC(ccf75722) SHA1(f48d21dfc4f82adbb4c9c841a809267cfd028a3d) )
774        ROM_LOAD64_WORD( "678a14.13d",   0x000002, 0x200000, CRC(333a1ab4) SHA1(79df4a98b7871eba4157307a7709da8f8b5da39b) )
775        ROM_LOAD64_WORD( "678a15.9d",    0x000004, 0x200000, CRC(58b670f8) SHA1(5d4facb00e34de3ad11ed60c19835918a9cf6cb9) )
776        ROM_LOAD64_WORD( "678a16.4d",    0x000006, 0x200000, CRC(137b9bff) SHA1(5052c1fa30cc1d6affd78f48d483415dca89d10b) )
777
778   ROM_REGION(0x600000, REGION_SOUND1, 0)   /* Sound data */
779       ROM_LOAD( "678a09.3r",    0x000000, 0x200000, CRC(39baef23) SHA1(9f7bda0f9c06eee94703f9ceb06975c8e28338cc) )
780        ROM_LOAD( "678a10.5n",    0x200000, 0x200000, CRC(0508280e) SHA1(a36c5dc377b0ba597f131bd9dfc6019e7fc2d243) )
781        ROM_LOAD( "678a08.5r",    0x400000, 0x200000, CRC(4aeb61ad) SHA1(ec6872cb2e4776849963f48c1c245ca7697849e0) )
782ROM_END
783
544784/*****************************************************************************/
545785
546786GAME( 1995, midnrun,  0, zr107, midnrun,   zr107,    ROT0, "Konami", "Midnight Run", GAME_IMPERFECT_GRAPHICS|GAME_IMPERFECT_SOUND )
547787GAME( 1996, windheat, 0, zr107, windheat,  zr107,    ROT0, "Konami", "Winding Heat", GAME_IMPERFECT_GRAPHICS|GAME_IMPERFECT_SOUND )
788GAME( 1996, jetwave,  0, jetwave, jetwave, jetwave,  ROT0, "Konami", "Jet Wave", GAME_IMPERFECT_GRAPHICS|GAME_IMPERFECT_SOUND|GAME_NOT_WORKING )
src/mame/drivers/ksys573.c
r1215r1216
209209#include "cpu/mips/psx.h"
210210#include "includes/psx.h"
211211#include "machine/intelfsh.h"
212#include "machine/scsidev.h"
212#include "machine/cr589.h"
213213#include "machine/timekpr.h"
214214#include "machine/adc083x.h"
215215#include "machine/ds2401.h"
r1215r1216
451451
452452static UINT8 *atapi_regs;
453453static mame_timer *atapi_timer;
454static pSCSIDispatch cdrom_drive;
455static void *inserted_cdrom;
456static void *available_cdroms[ 2 ];
457static UINT16 *atapi_data;
454static SCSIInstance *inserted_cdrom;
455static SCSIInstance *available_cdroms[ 2 ];
456static UINT8 *atapi_data;
458457static int atapi_data_ptr, atapi_data_len, atapi_xferlen, atapi_xferbase, atapi_cdata_wait, atapi_xfermod;
459458
460459#define MAX_TRANSFER_SIZE ( 63488 )
r1215r1216
473472   while (atapi_xferlen > 0 )
474473   {
475474      // get a sector from the SCSI device
476      cdrom_drive(SCSIOP_READ_DATA, inserted_cdrom, 2048, sector_buffer);
475      SCSIReadData( inserted_cdrom, sector_buffer, 2048 );
477476
478477      atapi_xferlen -= 2048;
479478
r1215r1216
526525static READ32_HANDLER( atapi_r )
527526{
528527   int reg, data;
529   int i;
530   UINT8 sector_buffer[ 4096 ];
531528
532529   if (mem_mask == 0xffff0000)   // word-wide command read
533530   {
r1215r1216
536533      // assert IRQ and drop DRQ
537534      if (atapi_data_ptr == 0 && atapi_data_len == 0)
538535      {
539         while( atapi_xferlen > 0 )
536         // get the data from the device
537         if( atapi_xferlen > 0 )
540538         {
541            int transfer = atapi_xferlen;
542            if( transfer > 2048 )
543            {
544               transfer = 2048;
545            }
546
547            // get the data from the device
548            cdrom_drive(SCSIOP_READ_DATA, inserted_cdrom, transfer, sector_buffer);
549
550            // fix it up in an endian-safe way
551            for (i = 0; i < transfer; i += 2)
552            {
553               atapi_data[ atapi_data_len++ ] = sector_buffer[i] | sector_buffer[i+1]<<8;
554            }
555
556            atapi_xferlen -= transfer;
539            SCSIReadData( inserted_cdrom, atapi_data, atapi_xferlen );
540            atapi_data_len = atapi_xferlen;
557541         }
558542
559543         if (atapi_xfermod > MAX_TRANSFER_SIZE)
r1215r1216
589573      if( atapi_data_ptr < atapi_data_len )
590574      {
591575         data = atapi_data[atapi_data_ptr++];
576         data |= ( atapi_data[atapi_data_ptr++] << 8 );
592577         if( atapi_data_ptr >= atapi_data_len )
593578         {
594579//              verboselog( 2, "atapi_r: read all bytes\n" );
r1215r1216
661646static WRITE32_HANDLER( atapi_w )
662647{
663648   int reg;
664   int i;
665   UINT8 atapi_scsi_packet[ 32*1024 ];
666649
667650   verboselog( 2, "atapi_w( %08x, %08x, %08x )\n", offset, mem_mask, data );
668651
r1215r1216
671654      verboselog( 2, "atapi_w: data=%04x\n", data );
672655
673656//      mame_printf_debug("ATAPI: packet write %04x\n", data);
674      atapi_data[atapi_data_ptr++] = data;
657      atapi_data[atapi_data_ptr++] = data & 0xff;
658      atapi_data[atapi_data_ptr++] = data >> 8;
675659
676660      if (atapi_cdata_wait)
677661      {
678662//          mame_printf_debug("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait);
679663         if (atapi_data_ptr == atapi_cdata_wait)
680664         {
681            // decompose SCSI packet into proper byte order
682            for (i = 0; i < atapi_cdata_wait; i += 2)
683            {
684               atapi_scsi_packet[i] = atapi_data[i/2]&0xff;
685               atapi_scsi_packet[i+1] = atapi_data[i/2]>>8;
686            }
687
688665            // send it to the device
689            cdrom_drive(SCSIOP_WRITE_DATA, inserted_cdrom, atapi_cdata_wait, atapi_scsi_packet);
666            SCSIWriteData( inserted_cdrom, atapi_data, atapi_cdata_wait );
690667
691668            // assert IRQ
692669            psx_irq_set(0x400);
r1215r1216
696673         }
697674      }
698675
699      if ((!atapi_cdata_wait) && (atapi_data_ptr == 6))
676      else if ( atapi_data_ptr == 12 )
700677      {
678         int phase;
679
701680         verboselog( 2, "atapi_w: command %02x\n", atapi_data[0]&0xff );
702681
703682         // reset data pointer for reading SCSI results
704683         atapi_data_ptr = 0;
705684         atapi_data_len = 0;
706685
707         // decompose SCSI packet into proper byte order
708         for (i = 0; i < 16; i += 2)
709         {
710            atapi_scsi_packet[i] = atapi_data[i/2]&0xff;
711            atapi_scsi_packet[i+1] = atapi_data[i/2]>>8;
712         }
713
714686         // send it to the SCSI device
715         atapi_xferlen = cdrom_drive(SCSIOP_EXEC_COMMAND, inserted_cdrom, 0, atapi_scsi_packet);
687         SCSISetCommand( inserted_cdrom, atapi_data, 12 );
688         SCSIExecCommand( inserted_cdrom, &atapi_xferlen );
689         SCSIGetPhase( inserted_cdrom, &phase );
716690
717691         if (atapi_xferlen != -1)
718692         {
r1215r1216
743717               atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
744718            }
745719
720            switch( phase )
721            {
722            case SCSI_PHASE_DATAOUT:
723               atapi_cdata_wait = atapi_xferlen;
724               break;
725            }
726
746727            // perform special ATAPI processing of certain commands
747728            switch (atapi_data[0]&0xff)
748729            {
749               case 0x55:   // MODE SELECT
750                  atapi_cdata_wait = atapi_data[4]/2;
751                  break;
752
753               case 0x00:   // BUS RESET / TEST UNIT READY
730               case 0x00: // BUS RESET / TEST UNIT READY
731               case 0xbb: // SET CDROM SPEED
754732                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
755733                  break;
756734
r1215r1216
758736                  atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY;
759737                  mame_timer_adjust( atapi_timer, MAME_TIME_IN_CYCLES( ATAPI_CYCLES_PER_SECTOR, 0 ), 0, time_zero );
760738                  break;
761
762               case 0xbb: // SET CDROM SPEED
763                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
764                  break;
765739            }
766740
767741            // assert IRQ
r1215r1216
850824
851825               memset( atapi_data, 0, atapi_data_len );
852826
853               atapi_data[0] = 0x8500;   // ATAPI device, cmd set 5 compliant, DRQ within 3 ms of PACKET command
854               atapi_data[49] = 0x0400; // IORDY may be disabled
827               atapi_data[ 0 ^ 1 ] = 0x85;   // ATAPI device, cmd set 5 compliant, DRQ within 3 ms of PACKET command
828               atapi_data[ 1 ^ 1 ] = 0x00;
855829
830               memset( &atapi_data[ 46 ], ' ', 8 );
831               atapi_data[ 46 ^ 1 ] = '1';
832               atapi_data[ 47 ^ 1 ] = '.';
833               atapi_data[ 48 ^ 1 ] = '0';
834
835               memset( &atapi_data[ 54 ], ' ', 40 );
836               atapi_data[ 54 ^ 1 ] = 'M';
837               atapi_data[ 55 ^ 1 ] = 'A';
838               atapi_data[ 56 ^ 1 ] = 'T';
839               atapi_data[ 57 ^ 1 ] = 'S';
840               atapi_data[ 58 ^ 1 ] = 'H';
841               atapi_data[ 59 ^ 1 ] = 'I';
842               atapi_data[ 60 ^ 1 ] = 'T';
843               atapi_data[ 61 ^ 1 ] = 'A';
844               atapi_data[ 62 ^ 1 ] = ' ';
845               atapi_data[ 63 ^ 1 ] = 'C';
846               atapi_data[ 64 ^ 1 ] = 'R';
847               atapi_data[ 65 ^ 1 ] = '-';
848               atapi_data[ 66 ^ 1 ] = '5';
849               atapi_data[ 67 ^ 1 ] = '8';
850               atapi_data[ 68 ^ 1 ] = '9';
851               atapi_data[ 69 ^ 1 ] = ' ';
852
853               atapi_data[ 98 ^ 1 ] = 0x04; // IORDY may be disabled
854               atapi_data[ 99 ^ 1 ] = 0x00;
855
856856               atapi_regs[ATAPI_REG_COUNTLOW] = 0;
857857               atapi_regs[ATAPI_REG_COUNTHIGH] = 2;
858858
r1215r1216
895895   atapi_timer = mame_timer_alloc( atapi_xfer_end );
896896   mame_timer_adjust(atapi_timer, time_never, 0, time_never);
897897
898   // allocate a SCSI CD-ROM device
899   cdrom_drive = SCSI_DEVICE_CDROM;
900
901898   for( i = 0; i < 2; i++ )
902899   {
903900      if( get_disk_handle( i ) != NULL )
904901      {
905         cdrom_drive(SCSIOP_ALLOC_INSTANCE, &available_cdroms[ i ], i, (UINT8 *)NULL);
902         SCSIAllocInstance( &SCSIClassCr589, &available_cdroms[ i ], i );
906903      }
907904      else
908905      {
r1215r1216
13921389static void *atapi_get_device(void)
13931390{
13941391   void *ret;
1395   cdrom_drive(SCSIOP_GET_DEVICE, inserted_cdrom, 0, (UINT8 *)&ret);
1392   SCSIGetDevice( inserted_cdrom, &ret );
13961393   return ret;
13971394}
13981395
r1215r1216
15291526static void update_mode( void )
15301527{
15311528   int mode = readinputportbytag( "MODE" );
1532   static void *new_cdrom;
1529   static SCSIInstance *new_cdrom;
15331530
15341531   if( chiptype[ 1 ] != 0 )
15351532   {
r1215r1216
30183015   DISK_IMAGE_READONLY( "765jaa02", 0, MD5(11693b1234458c238ed613ef37f71245) SHA1(d820f8166b7d5ffcf41e7a70c8c4c4d1c207c1bd) )
30193016ROM_END
30203017
3018ROM_START( cr589fw )
3019   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3020   SYS573_BIOS_A
3021
3022   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3023   ROM_FILL( 0x0000000, 0x1000000, 0xff )
3024
3025   DISK_REGION( REGION_DISKS )
3026   DISK_IMAGE_READONLY( "700b04", 0, MD5(4847e008189b7c700f2129ecb362b924) SHA1(13ac92eb242de48317924b9c725f9f693a263cf5) )
3027ROM_END
3028
3029ROM_START( cr589fwa )
3030   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
3031   SYS573_BIOS_A
3032
3033   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
3034   ROM_FILL( 0x0000000, 0x1000000, 0xff )
3035
3036   DISK_REGION( REGION_DISKS )
3037   DISK_IMAGE_READONLY( "700a04", 0, MD5(211850ed73d05ccbf5951f1fe19a6767) SHA1(bf7865629775a34a8f8b628053e97f25b51ade2e) )
3038ROM_END
3039
30213040ROM_START( darkhleg )
30223041   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
30233042   SYS573_BIOS_A
r1215r1216
41624181   DISK_IMAGE_READONLY( "b06jaa02", 0, MD5(8191da2660bb645fcfee9fb60baef242) SHA1(e8be8bdc0cbfb95a0a56ab89f39de3089d31f305) )
41634182ROM_END
41644183
4184ROM_START( gtrfrk7m )
4185   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
4186   SYS573_BIOS_A
4187
4188   ROM_REGION( 0x0001014, REGION_USER2, 0 ) /* install security cart eeprom */
4189   ROM_LOAD( "gcb17jaa.u1",   0x000000, 0x001014, BAD_DUMP CRC(5a338c31) SHA1(0fd9ee306335858dd6bef680a62557a8bf055cc3) )
4190
4191   ROM_REGION( 0x1000000, REGION_USER3, 0 ) /* onboard flash */
4192   ROM_LOAD( "gcb17jaa.31m", 0x000000, 0x200000, CRC(1e1cbfe3) SHA1(6c942820f915ea0e01f0e736d70780ad8408aa69) )
4193   ROM_LOAD( "gcb17jaa.27m", 0x200000, 0x200000, CRC(7e7da9a9) SHA1(1882418779a48b5aefd113895756116379a6a4f7) )
4194   ROM_FILL( 0x400000, 0x0c00000, 0xff )
4195
4196   ROM_REGION( 0x2000000, REGION_USER4, 0 ) /* PCCARD1 */
4197   ROM_FILL( 0x0000000, 0x2000000, 0xff )
4198
4199   ROM_REGION( 0x000008, REGION_USER9, 0 ) /* install security cart id */
4200   ROM_LOAD( "gcb17jaa.u6",   0x000000, 0x000008, BAD_DUMP CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
4201
4202   DISK_REGION( REGION_DISKS )
4203   DISK_IMAGE_READONLY( "b17jaa02", 0, MD5(65b47fbf7d682e8dc8b2a3137aaab9b7) SHA1(bf8eb8f857c08595bb1c19f470ac689400ee0cab) )
4204ROM_END
4205
41654206ROM_START( gtfrk11m )
41664207   ROM_REGION32_LE( 0x080000, REGION_USER1, 0 )
41674208   SYS573_BIOS_A
r1215r1216
43414382GAME( 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 )
43424383GAME( 1999, gtrfrk2m, sys573,   konami573, gtrfrks,   gtrfrks,    ROT0, "Konami", "Guitar Freaks 2nd Mix Ver 1.01 (GQ883 VER. JAD)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
43434384GAME( 1999, dsftkd,   sys573,   konami573, ddr,       ddr,        ROT0, "Konami", "Dancing Stage featuring TRUE KiSS DESTiNATiON (G*884 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4385GAME( 1999, cr589fw,  sys573,   konami573, konami573, konami573,  ROT0, "Konami", "CD-ROM Drive Updater 2.0 (700B04)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4386GAME( 1999, cr589fwa, sys573,   konami573, konami573, konami573,  ROT0, "Konami", "CD-ROM Drive Updater (700A04)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
43444387GAME( 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 */
43454388GAME( 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 */
43464389GAME( 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 */
r1215r1216
43724415GAME( 2001, ddr5m,    sys573,   konami573, ddr,       ddrdigital, ROT0, "Konami", "Dance Dance Revolution 5th Mix (G*A27 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.9 */
43734416GAME( 2001, dmx2majp, sys573,   konami573, dmx,       dmx,        ROT0, "Konami", "Dance Maniax 2nd Mix Append J-Paradise (G*A38 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.9 */
43744417GAME( 2001, gtrfrk6m, sys573,   konami573, gtrfrks,   gtrfrkdigital,ROT0, "Konami", "Guitar Freaks 6th Mix (G*B06 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.9 */
4418GAME( 2001, gtrfrk7m, sys573,   konami573, gtrfrks,   gtrfrkdigital,ROT0, "Konami", "Guitar Freaks 7th Mix (G*B17 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) /* BOOT VER 1.95 */
43754419GAME( 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 */
43764420GAME( 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 */
43774421GAME( 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 */
src/mame/drivers/superqix.c
r1215r1216
862862
863863
864864
865static struct Samplesinterface custom_interface =
865static struct Samplesinterface pbillian_samples_interface =
866866{
867867   1,
868868   NULL,
r1215r1216
952952   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
953953
954954   MDRV_SOUND_ADD(SAMPLES, 0)
955   MDRV_SOUND_CONFIG(custom_interface)
955   MDRV_SOUND_CONFIG(pbillian_samples_interface)
956956   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
957957MACHINE_DRIVER_END
958958
r1215r1216
986986   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
987987
988988   MDRV_SOUND_ADD(SAMPLES, 0)
989   MDRV_SOUND_CONFIG(custom_interface)
989   MDRV_SOUND_CONFIG(pbillian_samples_interface)
990990   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
991991MACHINE_DRIVER_END
992992
src/mame/drivers/wilytowr.c
r1215r1216
501501GFXDECODE_END
502502
503503
504static struct Samplesinterface custom_interface =
504static struct Samplesinterface fghtbskt_samples_interface =
505505{
506506   1,
507507   NULL,
r1215r1216
580580   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
581581
582582   MDRV_SOUND_ADD(SAMPLES, 0)
583   MDRV_SOUND_CONFIG(custom_interface)
583   MDRV_SOUND_CONFIG(fghtbskt_samples_interface)
584584   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
585585MACHINE_DRIVER_END
586586
src/mame/drivers/skykid.c
r1215r1216
3333PALETTE_INIT( skykid );
3434
3535
36static int inputport_selected;
36static UINT8 inputport_selected;
3737
3838static WRITE8_HANDLER( inputport_select_w )
3939{
r1215r1216
8484
8585static WRITE8_HANDLER( skykid_bankswitch_w )
8686{
87   int bit = !BIT(offset,11);
88   UINT8 *rom = memory_region(REGION_CPU1) + 0x10000;
89
90   memory_set_bankptr(1,rom + 0x2000 * bit);
87   memory_set_bank(1, !BIT(offset,11));
9188}
9289
9390static WRITE8_HANDLER( skykid_irq_1_ctrl_w )
r1215r1216
106103      cpunum_set_input_line(1, 0, CLEAR_LINE);
107104}
108105
106static MACHINE_START( skykid )
107{
108   /* configure the banks */
109   memory_configure_bank(1, 0, 2, memory_region(REGION_CPU1) + 0x10000, 0x2000);
109110
111   state_save_register_global(inputport_selected);
112}
110113
114
115
111116static ADDRESS_MAP_START( skykid_map, ADDRESS_SPACE_PROGRAM, 8 )
112117   AM_RANGE(0x0000, 0x1fff) AM_READ(MRA8_BANK1)            /* banked ROM */
113118   AM_RANGE(0x2000, 0x2fff) AM_READWRITE(skykid_videoram_r,skykid_videoram_w) AM_BASE(&skykid_videoram)/* Video RAM (background) */
r1215r1216
380385   MDRV_SCREEN_VBLANK_TIME(DEFAULT_60HZ_VBLANK_DURATION)
381386   MDRV_INTERLEAVE(100)   /* we need heavy synch */
382387
388   MDRV_MACHINE_START(skykid)
389
383390   /* video hardware */
384391   MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
385392   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
r1215r1216
540547   }
541548}
542549
543GAME( 1984, drgnbstr, 0,      skykid, drgnbstr, skykid,  ROT0,   "Namco", "Dragon Buster", 0 )
544GAME( 1985, skykid,   0,      skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (New Ver.)", 0 ) /* Uses CUS63 aka 63a1 */
545GAME( 1985, skykido,  skykid, skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (Old Ver.)", 0 ) /* Uses CUS63 aka 63a1 */
546GAME( 1985, skykidd,  skykid, skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (CUS60 Ver.)", 0 ) /* Uses CUS60 aka 60a1 */
550GAME( 1984, drgnbstr, 0,      skykid, drgnbstr, skykid,  ROT0,   "Namco", "Dragon Buster", GAME_SUPPORTS_SAVE )
551GAME( 1985, skykid,   0,      skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (New Ver.)", GAME_SUPPORTS_SAVE ) /* Uses CUS63 aka 63a1 */
552GAME( 1985, skykido,  skykid, skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (Old Ver.)", GAME_SUPPORTS_SAVE ) /* Uses CUS63 aka 63a1 */
553GAME( 1985, skykidd,  skykid, skykid, skykid,   skykid,  ROT180, "Namco", "Sky Kid (CUS60 Ver.)", GAME_SUPPORTS_SAVE ) /* Uses CUS60 aka 60a1 */
src/mame/drivers/yamato.c
r1215r1216
601601   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.60)
602602
603603   MDRV_SOUND_ADD(SAMPLES, 0)
604   MDRV_SOUND_CONFIG(cclimber_custom_interface)
604   MDRV_SOUND_CONFIG(cclimber_samples_interface)
605605   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.40)
606606MACHINE_DRIVER_END
607607
src/mame/drivers/nwk-tr.c
r1215r1216
195195
196196   /* HACK !!! To be removed */
197197   if (mame_stricmp(gamename, "racingj") == 0 || mame_stricmp(gamename, "racingj2") == 0
198      || mame_stricmp(gamename, "hangplt") == 0 || mame_stricmp(gamename, "slrasslt") == 0)
198      || mame_stricmp(gamename, "hangplt") == 0 || mame_stricmp(gamename, "slrasslt") == 0
199      || mame_stricmp(gamename, "jetwave") == 0)
199200   {
200201      K001604_layer_size = 0;      // width = 128 tiles
201202   }
src/mame/drivers/srmp6.c
r1215r1216
787787***************************************************************************/
788788
789789/*GAME( YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME,FLAGS)*/
790GAME( 1995, srmp6, 0, srmp6, srmp6, srmp6, ROT0, "Seta", "Super Real Mahjong P6 (Japan)", GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND)
790GAME( 1995, srmp6, 0, srmp6, srmp6, srmp6, ROT0, "Seta", "Super Real Mahjong P6 (Japan)", GAME_IMPERFECT_GRAPHICS | GAME_NO_SOUND)
791791
src/osd/osdcore.h
r1215r1216
2222
2323#include "osdcomm.h"
2424
25#include "osinline.h"
2625
2726
28
2927/***************************************************************************
3028    FILE I/O INTERFACES
3129***************************************************************************/
r1215r1216
507505void osd_lock_free(osd_lock *lock);
508506
509507
510/*-----------------------------------------------------------------------------
511    osd_compare_exchange32: compare an INT32 against a value in memory; if they
512        are equal, swap in a new value; return the value from memory
513508
514    Parameters:
515
516        ptr - a pointer to the memory to compare and exchange to.
517
518        compare - the value to compare the memory against.
519
520        exchange - the value to swap in if the compare succeeds.
521
522    Return value:
523
524        The original value from memory.
525-----------------------------------------------------------------------------*/
526#ifndef osd_compare_exchange32
527INT32 osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange);
528#endif
529
530
531/*-----------------------------------------------------------------------------
532    osd_compare_exchange64: compare an INT64 against a value in memory; if they
533        are equal, swap in a new value; return the value from memory
534
535    Parameters:
536
537        ptr - a pointer to the memory to compare and exchange to.
538
539        compare - the value to compare the memory against.
540
541        exchange - the value to swap in if the compare succeeds.
542
543    Return value:
544
545        The original value from memory.
546-----------------------------------------------------------------------------*/
547#ifdef PTR64
548#ifndef osd_compare_exchange64
549INT64 osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange);
550#endif
551#endif
552
553
554/*-----------------------------------------------------------------------------
555    osd_sync_add: INLINE wrapper to safely add a delta value to a
556        32-bit integer, returning the final result
557-----------------------------------------------------------------------------*/
558#ifndef osd_sync_add
559INLINE INT32 osd_sync_add(INT32 volatile *ptr, INT32 delta)
560{
561   INT32 origvalue;
562
563   /* loop until we succeed in updating against an unchanged value */
564   do
565   {
566      origvalue = *ptr;
567   } while (osd_compare_exchange32(ptr, origvalue, origvalue + delta) != origvalue);
568
569   /* return the final result */
570   return origvalue + delta;
571}
572#endif
573
574
575/*-----------------------------------------------------------------------------
576    osd_compare_exchange_ptr: INLINE wrapper to compare and exchange a
577        pointer value of the appropriate size
578-----------------------------------------------------------------------------*/
579#ifndef osd_compare_exchange_ptr
580INLINE void *osd_compare_exchange_ptr(void * volatile *ptr, void *compare, void *exchange)
581{
582#ifdef PTR64
583   INT64 result = osd_compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
584   return (void *)result;
585#else
586   INT32 result = osd_compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
587   return (void *)result;
588#endif
589}
590#endif
591
592
593
594509/***************************************************************************
595510    WORK ITEM INTERFACES
596511***************************************************************************/
src/osd/windows/osd_cpu.h
r1215r1216
5656#define MUL_U64_U32_U32(A,B)  ((A)*(UINT64)(UINT32)(B))
5757
5858
59/***************************************************************************
6059
61    Inline math helpers
62
63***************************************************************************/
64
65#ifdef __GNUC__
66
67INLINE UINT32 _count_leading_zeros(UINT32 value)
68{
69   UINT32 result;
70
71   __asm__ (
72      "bsrl %1,%0;"
73      "xorl $31,%0;"
74      : "=r,r" (result)      /* result can be in any register */
75      : "r,m" (value)         /* 'value' can be register or memory */
76      : "%cc"               /* clobbers condition codes */
77   );
78
79   return result;
80}
81#define count_leading_zeros _count_leading_zeros
82
83INLINE UINT32 _count_leading_ones(UINT32 value)
84{
85   UINT32 result;
86
87   __asm__ (
88      "notl %1;"
89      "bsrl %1,%0;"
90      "notl %1;"
91      "xorl $31,%0;"
92      : "=r,r" (result)      /* result can be in any register */
93      : "r,m" (value)         /* 'value' can be register or memory */
94      : "%cc"               /* clobbers condition codes */
95   );
96
97   return result;
98}
99#define count_leading_ones _count_leading_ones
100
101INLINE INT32 _fixed_mul_shift(INT32 val1, INT32 val2, UINT8 shift)
102{
103   INT32 result;
104
105   __asm__ (
106      "imull %2;"
107      "shrdl %3,%%edx,%0;"
108      : "=a,a,a,a" (result)      /* result ends up in eax */
109      : "0,0,0,0" (val1),      /* 'val1' should also be in eax on entry */
110        "r,m,r,m" (val2),      /* 'val2' can be memory or register */
111        "I,I,c,c" (shift)      /* 'shift' must be constant in 0-31 range or in CL */
112      : "%edx", "%cc"         /* clobbers EDX and condition codes */
113   );
114
115   return result;
116}
117#define fixed_mul_shift _fixed_mul_shift
118
119#endif
120
121
12260#endif   /* defined OSD_CPU_H */
src/osd/windows/windows.mak
r1215r1216
103103endif
104104
105105ifdef PTR64
106CC += /wd4267 /wd4312 /Wp64
106CC += /wd4267 /Wp64
107107endif
108108
109109# add some VC++-specific defines
r1215r1216
238238endif
239239
240240# add a stub resource file
241ifdef PTR64
242RESFILE = $(WINOBJ)/mamex64.res
243else
244241RESFILE = $(WINOBJ)/mame.res
245endif
246242
247243
248244
src/osd/windows/osinline.h
r1215r1216
11//============================================================
22//
3//  osinline.h - Win32 inline functions
3//  osinline.h
44//
5//  x86 inline implementations for MSVC compiler.
6//
57//  Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
68//  Visit http://mamedev.org for licensing and usage restrictions.
79//
r1215r1216
1012#ifndef __OSINLINE__
1113#define __OSINLINE__
1214
13#include "osd_cpu.h"
15#ifdef PTR64
16#include <intrin.h>
17#endif
1418
1519
16//============================================================
17//  INLINE MATH FUNCTIONS
18//============================================================
20/***************************************************************************
21    INLINE MATH FUNCTIONS
22***************************************************************************/
1923
20#if defined(_MSC_VER) && defined(_M_IX86) && !defined(PTR64)
24/*-------------------------------------------------
25    mul_32x32 - perform a signed 32 bit x 32 bit
26    multiply and return the full 64 bit result
27-------------------------------------------------*/
2128
22// Microsoft Visual C, x86, 32-bit
23#define vec_mult _vec_mult
24INLINE int _vec_mult(int x, int y)
29#ifndef PTR64
30#define mul_32x32 _mul_32x32
31INLINE INT64 _mul_32x32(INT32 a, INT32 b)
2532{
26    int result;
33   // in theory this should work, but it is untested
34    __asm
35    {
36        mov   eax,a
37        imul  b
38        // leave results in edx:eax
39    }
40}
41#endif
2742
28    __asm {
29        mov eax, x
30        imul y
31        mov result, edx
43
44/*-------------------------------------------------
45    mulu_32x32 - perform an unsigned 32 bit x
46    32 bit multiply and return the full 64 bit
47    result
48-------------------------------------------------*/
49
50#ifndef PTR64
51#define mulu_32x32 _mulu_32x32
52INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b)
53{
54   // in theory this should work, but it is untested
55    __asm
56    {
57        mov   eax,a
58        mul   b
59        // leave results in edx:eax
3260    }
61}
62#endif
3363
34    return result;
64
65/*-------------------------------------------------
66    mul_32x32_hi - perform a signed 32 bit x 32 bit
67    multiply and return the upper 32 bits of the
68    result
69-------------------------------------------------*/
70
71#ifndef PTR64
72#define mul_32x32_hi _mul_32x32_hi
73INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
74{
75   INT32 result;
76
77    __asm
78    {
79        mov   eax,a
80        imul  b
81        mov   result,edx
82    }
83
84   return result;
3585}
86#endif
3687
3788
89/*-------------------------------------------------
90    mulu_32x32_hi - perform an unsigned 32 bit x
91    32 bit multiply and return the upper 32 bits
92    of the result
93-------------------------------------------------*/
3894
39c:\Program Files (x86)\Microsoft Visual Studio 8\VC\include
95#ifndef PTR64
96#define mulu_32x32_hi _mulu_32x32_hi
97INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
98{
99   INT32 result;
40100
41#elif defined(__GNUC__) && !defined(PTR64)
101    __asm
102    {
103        mov   eax,a
104        mul   b
105        mov   result,edx
106    }
42107
43// GCC, x86, 32-bit
44#define vec_mult _vec_mult
45INLINE int _vec_mult(int x, int y)
108   return result;
109}
110#endif
111
112
113/*-------------------------------------------------
114    mul_32x32_shift - perform a signed 32 bit x
115    32 bit multiply and shift the result by the
116    given number of bits before truncating the
117    result to 32 bits
118-------------------------------------------------*/
119
120#ifndef PTR64
121#define mul_32x32_shift _mul_32x32_shift
122INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
46123{
47   int result;
48   __asm__ (
49         "movl  %1    , %0    ; "
50         "imull %2            ; "    /* do the multiply */
51         "movl  %%edx , %%eax ; "
52         :  "=&a" (result)           /* the result has to go in eax */
53         :  "mr" (x),                /* x and y can be regs or mem */
54            "mr" (y)
55         :  "%edx", "%cc"            /* clobbers edx and flags */
56      );
124   INT32 result;
125
126    __asm
127    {
128        mov   eax,a
129        imul  b
130        mov   cl,shift
131        shrd  eax,edx,cl
132        mov   result,eax
133    }
134
57135   return result;
58136}
137#endif
59138
60#else
61139
62// other
63#define vec_mult _vec_mult
64INLINE int _vec_mult(int x, int y)
140/*-------------------------------------------------
141    mulu_32x32_shift - perform an unsigned 32 bit x
142    32 bit multiply and shift the result by the
143    given number of bits before truncating the
144    result to 32 bits
145-------------------------------------------------*/
146
147#ifndef PTR64
148#define mulu_32x32_shift _mulu_32x32_shift
149INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
65150{
66   return (int)(((INT64)x * (INT64)y) >> 32);
151   INT32 result;
152
153    __asm
154    {
155        mov   eax,a
156        mul   b
157        mov   cl,shift
158        shrd  eax,edx,cl
159        mov   result,eax
160    }
161
162   return result;
67163}
164#endif
68165
69#endif // defined(_MSC_VER) && defined(_M_IX86) && !defined(PTR64)
70166
167/*-------------------------------------------------
168    div_64x32 - perform a signed 64 bit x 32 bit
169    divide and return the 32 bit quotient
170-------------------------------------------------*/
71171
172/* TBD */
72173
73//============================================================
74//  INLINE SYNCHRONIZATION FUNCTIONS
75//============================================================
76174
77#if defined(_MSC_VER)
175/*-------------------------------------------------
176    divu_64x32 - perform an unsigned 64 bit x 32 bit
177    divide and return the 32 bit quotient
178-------------------------------------------------*/
78179
79// Microsoft Visual C
80#include <intrin.h>
180/* TBD */
81181
82#pragma intrinsic(_InterlockedCompareExchange)
83#pragma intrinsic(_InterlockedCompareExchange64)
84#pragma intrinsic(_InterlockedExchangeAdd)
85182
86#define osd_compare_exchange32 _osd_compare_exchange32
87INLINE INT32 _osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
183/*-------------------------------------------------
184    div_32x32_shift - perform a signed divide of
185    two 32 bit values, shifting the first before
186    division, and returning the 32 bit quotient
187-------------------------------------------------*/
188
189#ifndef PTR64
190#define div_32x32_shift _div_32x32_shift
191INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
88192{
193   INT32 result;
194
195    __asm
196    {
197        mov   eax,a
198        cdq
199        mov   cl,shift
200        shld  edx,eax,cl
201        shl   eax,cl
202        idiv  b
203        mov   result,eax
204    }
205
206   return result;
207}
208#endif
209
210
211/*-------------------------------------------------
212    divu_32x32_shift - perform an unsigned divide of
213    two 32 bit values, shifting the first before
214    division, and returning the 32 bit quotient
215-------------------------------------------------*/
216
217#ifndef PTR64
218#define divu_32x32_shift _divu_32x32_shift
219INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
220{
221   INT32 result;
222
223    __asm
224    {
225        mov   eax,a
226        xor   edx,edx
227        mov   cl,shift
228        shld  edx,eax,cl
229        shl   eax,cl
230        div   b
231        mov   result,eax
232    }
233
234   return result;
235}
236#endif
237
238
239/*-------------------------------------------------
240    mod_64x32 - perform a signed 64 bit x 32 bit
241    divide and return the 32 bit remainder
242-------------------------------------------------*/
243
244/* TBD */
245
246
247/*-------------------------------------------------
248    modu_64x32 - perform an unsigned 64 bit x 32 bit
249    divide and return the 32 bit remainder
250-------------------------------------------------*/
251
252/* TBD */
253
254
255/*-------------------------------------------------
256    recip_approx - compute an approximate floating
257    point reciprocal
258-------------------------------------------------*/
259
260#ifdef PTR64
261#define recip_approx _recip_approx
262INLINE float _recip_approx(float z)
263{
264   __m128 mz = _mm_set_ss(z);
265   __m128 mooz = _mm_rcp_ss(mz);
266   float ooz;
267   _mm_store_ss(&ooz, mooz);
268   return ooz;
269}
270#endif
271
272
273
274/***************************************************************************
275    INLINE BIT MANIPULATION FUNCTIONS
276***************************************************************************/
277
278/*-------------------------------------------------
279    count_leading_zeros - return the number of
280    leading zero bits in a 32-bit value
281-------------------------------------------------*/
282
283#define count_leading_zeros _count_leading_zeros
284INLINE UINT8 _count_leading_zeros(UINT32 value)
285{
286#ifdef PTR64
287   UINT32 index;
288   return _BitScanReverse(&index, value) ? (index ^ 31) : 32;
289#else
290   INT32 result;
291
292    __asm
293    {
294       bsr   eax,value
295       jnz   skip
296       mov   eax,63
297    skip:
298       xor   eax,31
299        mov   result,eax
300    }
301
302   return result;
303#endif
304}
305
306
307/*-------------------------------------------------
308    count_leading_ones - return the number of
309    leading one bits in a 32-bit value
310-------------------------------------------------*/
311
312#define count_leading_ones _count_leading_ones
313INLINE UINT8 _count_leading_ones(UINT32 value)
314{
315#ifdef PTR64
316   UINT32 index;
317   return _BitScanReverse(&index, ~value) ? (index ^ 31) : 32;
318#else
319   INT32 result;
320
321    __asm
322    {
323       mov   eax,value
324       not   eax
325       bsr   eax,eax
326       jnz   skip
327       mov   eax,63
328    skip:
329       xor   eax,31
330        mov   result,eax
331    }
332
333   return result;
334#endif
335}
336
337
338
339/***************************************************************************
340    INLINE SYNCHRONIZATION FUNCTIONS
341***************************************************************************/
342
343/*-------------------------------------------------
344    compare_exchange32 - compare the 'compare'
345    value against the memory at 'ptr'; if equal,
346    swap in the 'exchange' value. Regardless,
347    return the previous value at 'ptr'.
348-------------------------------------------------*/
349
350#define compare_exchange32 _compare_exchange32
351INLINE INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
352{
89353   return _InterlockedCompareExchange(ptr, exchange, compare);
90354}
91355
356
357/*-------------------------------------------------
358    compare_exchange64 - compare the 'compare'
359    value against the memory at 'ptr'; if equal,
360    swap in the 'exchange' value. Regardless,
361    return the previous value at 'ptr'.
362-------------------------------------------------*/
363
92364#ifdef PTR64
93#define osd_compare_exchange64 _osd_compare_exchange64
94INLINE INT64 _osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
365#define compare_exchange64 _compare_exchange64
366INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
95367{
96368   return _InterlockedCompareExchange64(ptr, exchange, compare);
97369}
98370#endif
99371
100#define osd_sync_add _osd_sync_add
101INLINE INT32 osd_sync_add(INT32 volatile *ptr, INT32 delta)
372
373/*-------------------------------------------------
374    atomic_exchange32 - atomically exchange the
375    exchange value with the memory at 'ptr',
376    returning the original value.
377-------------------------------------------------*/
378
379#define atomic_exchange32 _atomic_exchange32
380INLINE INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
102381{
103   return _InterlockedExchangeAdd(ptr, delta) + delta;
382   return _InterlockedExchange(ptr, exchange);
104383}
105384
106#elif defined(__GNUC__) && !defined(PTR64)
107385
108// need to copy this from the SDL implementation
386/*-------------------------------------------------
387    atomic_add32 - atomically add the delta value
388    to the memory at 'ptr', returning the final
389    result.
390-------------------------------------------------*/
109391
110#endif
392#define atomic_add32 _atomic_add32
393INLINE INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
394{
395   return _InterlockedExchangeAdd(ptr, delta) + delta;
396}
111397
112398
113
114399#endif /* __OSINLINE__ */
src/emu/cpu/tms32031/32031ops.c
r1215r1216
710710#endif
711711
712712
713/* normalize a floating point value */
714#if USE_FP
715static void norm(union genreg *dst, union genreg *src)
716{
717   fatalerror("norm not implemented");
718}
719#else
720static void norm(union genreg *dst, union genreg *src)
721{
722   INT32 man = MANTISSA(src);
723   int exp = EXPONENT(src);
713724
725   CLR_NZVUF();
726
727   if (exp == -128 || man == 0)
728   {
729      SET_MANTISSA(dst, 0);
730      SET_EXPONENT(dst, -128);
731      if (man != 0)
732         IREG(TMR_ST) |= UFFLAG | LUFFLAG;
733   }
734   else
735   {
736      int cnt;
737      if (man > 0)
738      {
739         cnt = count_leading_zeros((UINT32)man);
740         man <<= cnt;
741         exp -= cnt;
742      }
743      else
744      {
745         cnt = count_leading_ones((UINT32)man);
746         man <<= cnt;
747         exp -= cnt;
748      }
749
750      /* check for underflow */
751      if (exp <= -128)
752      {
753         man = 0x00000000;
754         exp = -128;
755         IREG(TMR_ST) |= UFFLAG | LUFFLAG;
756      }
757   }
758
759   SET_MANTISSA(dst, man);
760   SET_EXPONENT(dst, exp);
761   OR_NZF(dst);
762}
763#endif
764
765
766
767
714768/***************************************************************************
715769    INDIRECT MEMORY REFS
716770***************************************************************************/
r1215r1216
21922246
21932247/*-----------------------------------------------------*/
21942248
2195static void norm_reg(void) { unimplemented(); }
2196static void norm_dir(void) { unimplemented(); }
2197static void norm_ind(void) { unimplemented(); }
2198static void norm_imm(void) { unimplemented(); }
2249static void norm_reg(void)
2250{
2251   int dreg = (OP >> 16) & 7;
2252   norm(&tms32031.r[dreg], &tms32031.r[OP & 7]);
2253}
21992254
2255static void norm_dir(void)
2256{
2257   UINT32 res = RMEM(DIRECT());
2258   int dreg = (OP >> 16) & 7;
2259   LONG2FP(TMR_TEMP1, res);
2260   norm(&tms32031.r[dreg], &tms32031.r[TMR_TEMP1]);
2261}
2262
2263static void norm_ind(void)
2264{
2265   UINT32 res = RMEM(INDIRECT_D(OP >> 8));
2266   int dreg = (OP >> 16) & 7;
2267   LONG2FP(TMR_TEMP1, res);
2268   norm(&tms32031.r[dreg], &tms32031.r[TMR_TEMP1]);
2269}
2270
2271static void norm_imm(void)
2272{
2273   int dreg = (OP >> 16) & 7;
2274   SHORT2FP(TMR_TEMP1, OP);
2275   norm(&tms32031.r[dreg], &tms32031.r[TMR_TEMP1]);
2276}
2277
22002278/*-----------------------------------------------------*/
22012279
22022280#define NOT(dreg, src)                                    \
src/emu/cpu/tms32031/tms32031.c
r1215r1216
88
99#include "debugger.h"
1010#include "tms32031.h"
11#include "eminline.h"
1112
1213
1314#define LOG_OPCODE_USAGE   (0)
src/emu/cpu/m6800/m6800.c
r1215r1216
5353
5454/*
5555
56   Chip            RAM      NVRAM   ROM      SCI
57   -----------------------------------------------
58   MC6800            -      -      -      no
59   MC6801            128      64      2K      yes
60   MC68701            128      64      -      yes
61   MC6803            128      64      -      yes
62   MC6802            128      32      -      no
63   MC6802NS         128      -      -      no
64   MC6808            -      -      -      no
56    Chip                RAM     NVRAM   ROM     SCI
57    -----------------------------------------------
58    MC6800              -       -       -       no
59    MC6801              128     64      2K      yes
60    MC68701             128     64      -       yes
61    MC6803              128     64      -       yes
62    MC6802              128     32      -       no
63    MC6802NS            128     -       -       no
64    MC6808              -       -       -       no
6565
66   HD6301            128      -      4K      yes
67   HD63701            192      -      4K      yes
68   HD6303            128      -      -      yes
69   HD6801            128      64      2K      yes
66    HD6301              128     -       4K      yes
67    HD63701             192     -       4K      yes
68    HD6303              128     -       -       yes
69    HD6801              128     64      2K      yes
7070
71   NSC8105           
72   MS2010-A         
71    NSC8105
72    MS2010-A
7373
7474*/
7575
src/emu/eigccx86.h
r0r1216
1/***************************************************************************
2
3    eigccx86.h
4
5    x86 (32 and 64-bit) inline implementations for GCC compilers. This
6    code is automatically included if appropriate by eminline.h.
7
8    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
9    Visit http://mamedev.org for licensing and usage restrictions.
10
11***************************************************************************/
12
13#ifndef __EIGCCX86__
14#define __EIGCCX86__
15
16
17/***************************************************************************
18    INLINE MATH FUNCTIONS
19***************************************************************************/
20
21/*-------------------------------------------------
22    mul_32x32 - perform a signed 32 bit x 32 bit
23    multiply and return the full 64 bit result
24-------------------------------------------------*/
25
26#ifndef PTR64
27#define mul_32x32 _mul_32x32
28INLINE INT64 _mul_32x32(INT32 a, INT32 b)
29{
30   INT64 result;
31
32   __asm__ (
33      "imull %2;"
34      : "=A,A" (result)         /* result in edx:eax */
35      : "0,0" (a),            /* 'a' should also be in eax on entry */
36        "r,m" (b)            /* 'b' can be memory or register */
37   );
38
39   return result;
40}
41#endif
42
43
44/*-------------------------------------------------
45    mulu_32x32 - perform an unsigned 32 bit x
46    32 bit multiply and return the full 64 bit
47    result
48-------------------------------------------------*/
49
50#ifndef PTR64
51#define mulu_32x32 _mulu_32x32
52INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b)
53{
54   UINT64 result;
55
56   __asm__ (
57      "mull  %2;"
58      : "=A,A" (result)         /* result in edx:eax */
59      : "0,0" (a),            /* 'a' should also be in eax on entry */
60        "r,m" (b)            /* 'b' can be memory or register */
61   );
62
63   return result;
64}
65#endif
66
67
68/*-------------------------------------------------
69    mul_32x32_hi - perform a signed 32 bit x 32 bit
70    multiply and return the upper 32 bits of the
71    result
72-------------------------------------------------*/
73
74#ifndef PTR64
75#define mul_32x32_hi _mul_32x32_hi
76INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
77{
78   INT32 result;
79
80   __asm__ (
81      "imull %2;"
82      "movl  %%edx,%0;"
83      : "=a,a" (result)         /* result ends up in eax */
84      : "0,0" (a),            /* 'a' should also be in eax on entry */
85        "r,m" (b)            /* 'b' can be memory or register */
86      : "%edx", "%cc"         /* clobbers EDX and condition codes */
87   );
88
89   return result;
90}
91#endif
92
93
94/*-------------------------------------------------
95    mulu_32x32_hi - perform an unsigned 32 bit x
96    32 bit multiply and return the upper 32 bits
97    of the result
98-------------------------------------------------*/
99
100#ifndef PTR64
101#define mulu_32x32_hi _mulu_32x32_hi
102INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
103{
104   UINT32 result;
105
106   __asm__ (
107      "mull  %2;"
108      "movl  %%edx,%0;"
109      : "=a,a" (result)         /* result ends up in eax */
110      : "0,0" (a),            /* 'a' should also be in eax on entry */
111        "r,m" (b)            /* 'b' can be memory or register */
112      : "%edx", "%cc"         /* clobbers EDX and condition codes */
113   );
114
115   return result;
116}
117#endif
118
119
120/*-------------------------------------------------
121    mul_32x32_shift - perform a signed 32 bit x
122    32 bit multiply and shift the result by the
123    given number of bits before truncating the
124    result to 32 bits
125-------------------------------------------------*/
126
127#ifndef PTR64
128#define mul_32x32_shift _mul_32x32_shift
129INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
130{
131   INT32 result;
132
133   __asm__ (
134      "imull %2;"
135      "shrdl %3,%%edx,%0;"
136      : "=a,a,a,a" (result)      /* result ends up in eax */
137      : "0,0,0,0" (a),         /* 'a' should also be in eax on entry */
138        "r,m,r,m" (b),         /* 'b' can be memory or register */
139        "I,I,c,c" (shift)      /* 'shift' must be constant in 0-31 range or in CL */
140      : "%edx", "%cc"         /* clobbers EDX and condition codes */
141   );
142
143   return result;
144}
145#endif
146
147
148/*-------------------------------------------------
149    mulu_32x32_shift - perform an unsigned 32 bit x
150    32 bit multiply and shift the result by the
151    given number of bits before truncating the
152    result to 32 bits
153-------------------------------------------------*/
154
155#ifndef PTR64
156#define mulu_32x32_shift _mulu_32x32_shift
157INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
158{
159   UINT32 result;
160
161   __asm__ (
162      "imull %2;"
163      "shrdl %3,%%edx,%0;"
164      : "=a,a,a,a" (result)      /* result ends up in eax */
165      : "0,0,0,0" (a),         /* 'a' should also be in eax on entry */
166        "r,m,r,m" (b),         /* 'b' can be memory or register */
167        "I,I,c,c" (shift)      /* 'shift' must be constant in 0-31 range or in CL */
168      : "%edx", "%cc"         /* clobbers EDX and condition codes */
169   );
170
171   return result;
172}
173#endif
174
175
176/*-------------------------------------------------
177    div_64x32 - perform a signed 64 bit x 32 bit
178    divide and return the 32 bit quotient
179-------------------------------------------------*/
180
181/* TBD */
182
183
184/*-------------------------------------------------
185    divu_64x32 - perform an unsigned 64 bit x 32 bit
186    divide and return the 32 bit quotient
187-------------------------------------------------*/
188
189/* TBD */
190
191
192/*-------------------------------------------------
193    div_32x32_shift - perform a signed divide of
194    two 32 bit values, shifting the first before
195    division, and returning the 32 bit quotient
196-------------------------------------------------*/
197
198#ifndef PTR64
199/* TBD - I get an error if this is enabled: error: 'asm' operand requires impossible reload */
200#if 0
201#define div_32x32_shift _div_32x32_shift
202INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
203{
204   INT32 result;
205
206   __asm__ (
207       "cdq;"
208       "shldl %3,%0,%%edx;"
209       "shll  %3,%0;"
210      "idivl %2;"
211      : "=a,a,a,a" (result)      /* result ends up in eax */
212      : "0,0,0,0" (a),         /* 'a' should also be in eax on entry */
213        "r,m,r,m" (b),         /* 'b' can be memory or register */
214        "I,I,c,c" (shift)      /* 'shift' must be constant in 0-31 range or in CL */
215      : "%edx", "%cc"         /* clobbers EDX and condition codes */
216   );
217
218   return result;
219}
220#endif
221#endif
222
223
224/*-------------------------------------------------
225    divu_32x32_shift - perform an unsigned divide of
226    two 32 bit values, shifting the first before
227    division, and returning the 32 bit quotient
228-------------------------------------------------*/
229
230#ifndef PTR64
231#define divu_32x32_shift _divu_32x32_shift
232INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
233{
234   INT32 result;
235
236   __asm__ (
237       "xorl  %%edx,%%edx;"
238       "shldl %3,%0,%%edx;"
239       "shll  %3,%0;"
240      "divl  %2;"
241      : "=a,a,a,a" (result)      /* result ends up in eax */
242      : "0,0,0,0" (a),         /* 'a' should also be in eax on entry */
243        "r,m,r,m" (b),         /* 'b' can be memory or register */
244        "I,I,c,c" (shift)      /* 'shift' must be constant in 0-31 range or in CL */
245      : "%edx", "%cc"         /* clobbers EDX and condition codes */
246   );
247
248   return result;
249}
250#endif
251
252
253/*-------------------------------------------------
254    mod_64x32 - perform a signed 64 bit x 32 bit
255    divide and return the 32 bit remainder
256-------------------------------------------------*/
257
258/* TBD */
259
260
261/*-------------------------------------------------
262    modu_64x32 - perform an unsigned 64 bit x 32 bit
263    divide and return the 32 bit remainder
264-------------------------------------------------*/
265
266/* TBD */
267
268
269/*-------------------------------------------------
270    recip_approx - compute an approximate floating
271    point reciprocal
272-------------------------------------------------*/
273
274/* TBD */
275
276
277
278/***************************************************************************
279    INLINE BIT MANIPULATION FUNCTIONS
280***************************************************************************/
281
282/*-------------------------------------------------
283    count_leading_zeros - return the number of
284    leading zero bits in a 32-bit value
285-------------------------------------------------*/
286
287#define count_leading_zeros _count_leading_zeros
288INLINE UINT8 _count_leading_zeros(UINT32 value)
289{
290   UINT32 result;
291
292   __asm__ (
293      "bsrl  %1,%0;"
294      "jnz   1f;"
295      "movl  $63,%0;"
296     "1:xorl  $31,%0;"
297     : "=r,r" (result)         /* result can be in any register */
298     : "r,m" (value)         /* 'value' can be register or memory */
299     : "%cc"               /* clobbers condition codes */
300   );
301
302   return result;
303}
304
305
306/*-------------------------------------------------
307    count_leading_ones - return the number of
308    leading one bits in a 32-bit value
309-------------------------------------------------*/
310
311#define count_leading_ones _count_leading_ones
312INLINE UINT8 _count_leading_ones(UINT32 value)
313{
314   UINT32 result;
315
316   __asm__ (
317      "movl  %1,%0;"
318      "notl  %0;"
319      "bsrl  %0,%0;"
320      "jnz   1f;"
321      "movl  $63,%0;"
322     "1:xorl  $31,%0;"
323     : "=r,r" (result)         /* result can be in any register */
324     : "r,m" (value)         /* 'value' can be register or memory */
325     : "%cc"               /* clobbers condition codes */
326   );
327
328   return result;
329}
330
331
332
333/***************************************************************************
334    INLINE SYNCHRONIZATION FUNCTIONS
335***************************************************************************/
336
337/*-------------------------------------------------
338    compare_exchange32 - compare the 'compare'
339    value against the memory at 'ptr'; if equal,
340    swap in the 'exchange' value. Regardless,
341    return the previous value at 'ptr'.
342-------------------------------------------------*/
343
344#define compare_exchange32 _compare_exchange32
345INLINE INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
346{
347   register INT32 result;
348
349   __asm__ __volatile__ (
350      " lock ; cmpxchg %[exchange], %[ptr] ;"
351     : [ptr]      "+m" (*ptr)
352     , [result]   "=a" (result)
353     : [compare]  "1"  (compare)
354     , [exchange] "q"  (exchange)
355     : "%cc"
356   );
357
358   return result;
359}
360
361
362/*-------------------------------------------------
363    compare_exchange64 - compare the 'compare'
364    value against the memory at 'ptr'; if equal,
365    swap in the 'exchange' value. Regardless,
366    return the previous value at 'ptr'.
367-------------------------------------------------*/
368
369#ifdef PTR64
370#define compare_exchange64 _compare_exchange64
371INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
372{
373   register INT64 result;
374
375   __asm__ __volatile__ (
376      " lock ; cmpxchg %[exchange], %[ptr] ;"
377     : [ptr]      "+m" (*ptr)
378     , [result]   "=a" (result)
379     : [compare]  "1"  (compare)
380     , [exchange] "q"  (exchange)
381     : "%cc"
382   );
383
384   return result;
385}
386#endif
387
388
389/*-------------------------------------------------
390    atomic_exchange32 - atomically exchange the
391    exchange value with the memory at 'ptr',
392    returning the original value.
393-------------------------------------------------*/
394
395#define atomic_exchange32 _atomic_exchange32
396INLINE INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
397{
398   register INT32 result;
399
400   __asm__ __volatile__ (
401      " lock ; xchg %[exchange], %[ptr] ;"
402      : [ptr]      "+m" (*ptr)
403      , [result]   "=r" (result)
404      : [exchange] "1"  (exchange)
405   );
406
407   return result;
408}
409
410
411/*-------------------------------------------------
412    atomic_add32 - atomically add the delta value
413    to the memory at 'ptr', returning the final
414    result.
415-------------------------------------------------*/
416
417#define atomic_add32 _atomic_add32
418INLINE INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
419{
420   register INT32 result;
421
422   __asm __volatile__ (
423      " mov           %[delta],%[result] ;"
424      " lock ; xadd   %[result],%[ptr]   ;"
425      " add           %[delta],%[result] ;"
426     : [ptr]    "+m"  (*ptr)
427     , [result] "=&r" (result)
428     : [delta]  "rmi" (delta)
429     : "%cc"
430   );
431
432   return result;
433}
434
435
436#endif /* __EIGCCX86__ */
src/emu/video/vector.c
r1215r1216
3333#include <math.h>
3434#include "rendutil.h"
3535#include "vector.h"
36#include "osinline.h"
3736
3837
3938
src/emu/video/voodoo.c
r1215r1216
135135#define EXPAND_RASTERIZERS
136136
137137#include "driver.h"
138#include "eminline.h"
138139#include "profiler.h"
139140#include "video/polynew.h"
140141#include "voodoo.h"
r1215r1216
47174718      v->fbi.startb += (dy * v->fbi.dbdy + dx * v->fbi.dbdx) >> 4;
47184719      v->fbi.starta += (dy * v->fbi.dady + dx * v->fbi.dadx) >> 4;
47194720      v->fbi.startw += (dy * v->fbi.dwdy + dx * v->fbi.dwdx) >> 4;
4720      v->fbi.startz += fixed_mul_shift(dy, v->fbi.dzdy, 4) + fixed_mul_shift(dx, v->fbi.dzdx, 4);
4721      v->fbi.startz += mul_32x32_shift(dy, v->fbi.dzdy, 4) + mul_32x32_shift(dx, v->fbi.dzdx, 4);
47214722
47224723      /* adjust iterated W/S/T for TMU 0 */
47234724      if (texcount >= 1)
src/emu/video/rgbgen.h
r0r1216
1/***************************************************************************
2
3    rgbgen.h
4
5    General RGB utilities.
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#ifndef __RGBGEN__
13#define __RGBGEN__
14
15
16/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
19
20/* intermediate RGB values are stored in a struct */
21typedef struct { INT16 dummy, r, g, b; } rgbint;
22
23/* intermediate RGB values are stored in a struct */
24typedef struct { INT16 a, r, g, b; } rgbaint;
25
26
27
28/***************************************************************************
29    BASIC CONVERSIONS
30***************************************************************************/
31
32/*-------------------------------------------------
33    rgb_comp_to_rgbint - converts a trio of RGB
34    components to an rgbint type
35-------------------------------------------------*/
36
37INLINE void rgb_comp_to_rgbint(rgbint *rgb, INT16 r, INT16 g, INT16 b)
38{
39   rgb->r = r;
40   rgb->g = g;
41   rgb->b = b;
42}
43
44
45/*-------------------------------------------------
46    rgba_comp_to_rgbint - converts a quad of RGB
47    components to an rgbint type
48-------------------------------------------------*/
49
50INLINE void rgba_comp_to_rgbaint(rgbaint *rgb, INT16 a, INT16 r, INT16 g, INT16 b)
51{
52   rgb->a = a;
53   rgb->r = r;
54   rgb->g = g;
55   rgb->b = b;
56}
57
58
59/*-------------------------------------------------
60    rgb_to_rgbint - converts a packed trio of RGB
61    components to an rgbint type
62-------------------------------------------------*/
63
64INLINE void rgb_to_rgbint(rgbint *rgb, rgb_t color)
65{
66   rgb->r = RGB_RED(color);
67   rgb->g = RGB_GREEN(color);
68   rgb->b = RGB_BLUE(color);
69}
70
71
72/*-------------------------------------------------
73    rgba_to_rgbaint - converts a packed quad of RGB
74    components to an rgbint type
75-------------------------------------------------*/
76
77INLINE void rgba_to_rgbaint(rgbaint *rgb, rgb_t color)
78{
79   rgb->a = RGB_ALPHA(color);
80   rgb->r = RGB_RED(color);
81   rgb->g = RGB_GREEN(color);
82   rgb->b = RGB_BLUE(color);
83}
84
85
86/*-------------------------------------------------
87    rgbint_to_rgb - converts an rgbint back to
88    a packed trio of RGB values
89-------------------------------------------------*/
90
91INLINE rgb_t rgbint_to_rgb(const rgbint *color)
92{
93   return MAKE_RGB(color->r, color->g, color->b);
94}
95
96
97/*-------------------------------------------------
98    rgbaint_to_rgba - converts an rgbint back to
99    a packed quad of RGB values
100-------------------------------------------------*/
101
102INLINE rgb_t rgbaint_to_rgba(const rgbaint *color)
103{
104   return MAKE_ARGB(color->a, color->r, color->g, color->b);
105}
106
107
108/*-------------------------------------------------
109    rgbint_to_rgb_clamp - converts an rgbint back
110    to a packed trio of RGB values, clamping them
111    to bytes first
112-------------------------------------------------*/
113
114INLINE rgb_t rgbint_to_rgb_clamp(const rgbint *color)
115{
116   UINT8 r = (color->r < 0) ? 0 : (color->r > 255) ? 255 : color->r;
117   UINT8 g = (color->g < 0) ? 0 : (color->g > 255) ? 255 : color->g;
118   UINT8 b = (color->b < 0) ? 0 : (color->b > 255) ? 255 : color->b;
119   return MAKE_RGB(r, g, b);
120}
121
122
123/*-------------------------------------------------
124    rgbaint_to_rgba_clamp - converts an rgbint back
125    to a packed quad of RGB values, clamping them
126    to bytes first
127-------------------------------------------------*/
128
129INLINE rgb_t rgbaint_to_rgba_clamp(const rgbaint *color)
130{
131   UINT8 a = (color->a < 0) ? 0 : (color->a > 255) ? 255 : color->a;
132   UINT8 r = (color->r < 0) ? 0 : (color->r > 255) ? 255 : color->r;
133   UINT8 g = (color->g < 0) ? 0 : (color->g > 255) ? 255 : color->g;
134   UINT8 b = (color->b < 0) ? 0 : (color->b > 255) ? 255 : color->b;
135   return MAKE_ARGB(a, r, g, b);
136}
137
138
139
140/***************************************************************************
141    CORE MATH
142***************************************************************************/
143
144/*-------------------------------------------------
145    rgbint_add - add two rgbint values
146-------------------------------------------------*/
147
148INLINE void rgbint_add(rgbint *color1, const rgbint *color2)
149{
150   color1->r += color2->r;
151   color1->g += color2->g;
152   color1->b += color2->b;
153}
154
155
156/*-------------------------------------------------
157    rgbaint_add - add two rgbaint values
158-------------------------------------------------*/
159
160INLINE void rgbaint_add(rgbaint *color1, const rgbaint *color2)
161{
162   color1->a += color2->a;
163   color1->r += color2->r;
164   color1->g += color2->g;
165   color1->b += color2->b;
166}
167
168
169/*-------------------------------------------------
170    rgbint_sub - subtract two rgbint values
171-------------------------------------------------*/
172
173INLINE void rgbint_sub(rgbint *color1, const rgbint *color2)
174{
175   color1->r -= color2->r;
176   color1->g -= color2->g;
177   color1->b -= color2->b;
178}
179
180
181/*-------------------------------------------------
182    rgbaint_sub - subtract two rgbaint values
183-------------------------------------------------*/
184
185INLINE void rgbaint_sub(rgbaint *color1, const rgbaint *color2)
186{
187   color1->a -= color2->a;
188   color1->r -= color2->r;
189   color1->g -= color2->g;
190   color1->b -= color2->b;
191}
192
193
194/*-------------------------------------------------
195    rgbint_subr - reverse subtract two rgbint
196    values
197-------------------------------------------------*/
198
199INLINE void rgbint_subr(rgbint *color1, const rgbint *color2)
200{
201   color1->r = color2->r - color1->r;
202   color1->g = color2->g - color1->g;
203   color1->b = color2->b - color1->b;
204}
205
206
207/*-------------------------------------------------
208    rgbaint_subr - reverse subtract two rgbaint
209    values
210-------------------------------------------------*/
211
212INLINE void rgbaint_subr(rgbaint *color1, const rgbaint *color2)
213{
214   color1->a = color2->a - color1->a;
215   color1->r = color2->r - color1->r;
216   color1->g = color2->g - color1->g;
217   color1->b = color2->b - color1->b;
218}
219
220
221
222/***************************************************************************
223    HIGHER LEVEL OPERATIONS
224***************************************************************************/
225
226/*-------------------------------------------------
227    rgbint_blend - blend two colors by the given
228    scale factor
229-------------------------------------------------*/
230
231INLINE void rgbint_blend(rgbint *color1, const rgbint *color2, UINT8 color1scale)
232{
233   int scale1 = (int)color1scale + 1;
234   int scale2 = 256 - scale1;
235
236   color1->r = (color1->r * scale1 + color2->r * scale2) >> 8;
237   color1->g = (color1->g * scale1 + color2->g * scale2) >> 8;
238   color1->b = (color1->b * scale1 + color2->b * scale2) >> 8;
239}
240
241
242/*-------------------------------------------------
243    rgbaint_blend - blend two colors by the given
244    scale factor
245-------------------------------------------------*/
246
247INLINE void rgbaint_blend(rgbaint *color1, const rgbaint *color2, UINT8 color1scale)
248{
249   int scale1 = (int)color1scale + 1;
250   int scale2 = 256 - scale1;
251
252   color1->a = (color1->a * scale1 + color2->a * scale2) >> 8;
253   color1->r = (color1->r * scale1 + color2->r * scale2) >> 8;
254   color1->g = (color1->g * scale1 + color2->g * scale2) >> 8;
255   color1->b = (color1->b * scale1 + color2->b * scale2) >> 8;
256}
257
258
259/*-------------------------------------------------
260    rgbint_scale_and_clamp - scale the given
261    color by an 8.8 scale factor and clamp to
262    byte values
263-------------------------------------------------*/
264
265INLINE void rgbint_scale_and_clamp(rgbint *color, INT16 colorscale)
266{
267   color->r = (color->r * colorscale) >> 8;
268   if ((UINT16)color->r > 255) { color->r = (color->r < 0) ? 0 : 255; }
269   color->g = (color->g * colorscale) >> 8;
270   if ((UINT16)color->g > 255) { color->g = (color->g < 0) ? 0 : 255; }
271   color->b = (color->b * colorscale) >> 8;
272   if ((UINT16)color->b > 255) { color->b = (color->b < 0) ? 0 : 255; }
273}
274
275
276/*-------------------------------------------------
277    rgbaint_scale_and_clamp - scale the given
278    color by an 8.8 scale factor and clamp to
279    byte values
280-------------------------------------------------*/
281
282INLINE void rgbaint_scale_and_clamp(rgbaint *color, INT16 colorscale)
283{
284   color->a = (color->a * colorscale) >> 8;
285   if ((UINT16)color->a > 255) { color->a = (color->a < 0) ? 0 : 255; }
286   color->r = (color->r * colorscale) >> 8;
287   if ((UINT16)color->r > 255) { color->r = (color->r < 0) ? 0 : 255; }
288   color->g = (color->g * colorscale) >> 8;
289   if ((UINT16)color->g > 255) { color->g = (color->g < 0) ? 0 : 255; }
290   color->b = (color->b * colorscale) >> 8;
291   if ((UINT16)color->b > 255) { color->b = (color->b < 0) ? 0 : 255; }
292}
293
294
295/*-------------------------------------------------
296    rgb_bilinear_filter - bilinear filter between
297    four pixel values; this code is derived from
298    code provided by Michael Herf
299-------------------------------------------------*/
300
301INLINE rgb_t rgb_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, UINT8 u, UINT8 v)
302{
303   UINT32 agd1 = (rgb01 & 0xff00ff00) - (rgb00 & 0xff00ff00);
304   UINT32 agd2 = (rgb11 & 0xff00ff00) - (rgb10 & 0xff00ff00);
305   UINT32 rbd1 = (rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff);
306   UINT32 rbd2 = (rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff);
307   agd1 >>= 8;
308   agd2 >>= 8;
309
310   rbd1 *= u;  rgb01 = (rgb00 & 0x00ff00ff);
311   agd1 *= u;  rbd1 >>= 8;
312   rbd2 *= u;  rgb11 = (rgb10 & 0x00ff00ff);
313   agd2 *= u;  rbd2 >>= 8;
314
315   rgb01 += rbd1;
316   rgb00 += agd1;
317
318   rgb11 += rbd2;
319   rgb10 += agd2;
320
321   rgb01 &= 0x00ff00ff;
322   rgb00 &= 0xff00ff00;
323   rgb10 &= 0xff00ff00;
324   rgb11 &= 0x00ff00ff;
325
326   // ---- rgb11 is now rb for the bottom
327   //      rgb10 is     ag for the bottom
328   //      rgb01 is     rb for the top
329   //      rgb00 is     ag for the top
330
331   rgb10 -= rgb00;  // agd
332   rgb11 -= rgb01;  // rbd
333   rgb10 >>= 8;
334
335   rgb11 *= v;
336   rgb10 *= v;
337   rgb11 >>= 8;
338
339   rgb00 += rgb10;
340   rgb01 += rgb11;
341
342   rgb00 &= 0xff00ff00;
343   rgb01 &= 0x00ff00ff;
344
345   return rgb00 | rgb01;
346}
347
348
349/*-------------------------------------------------
350    rgba_bilinear_filter - bilinear filter between
351    four pixel values; this code is derived from
352    code provided by Michael Herf
353-------------------------------------------------*/
354
355INLINE rgb_t rgba_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, UINT8 u, UINT8 v)
356{
357   UINT32 agd1 = (rgb01 & 0xff00ff00) - (rgb00 & 0xff00ff00);
358   UINT32 agd2 = (rgb11 & 0xff00ff00) - (rgb10 & 0xff00ff00);
359   UINT32 rbd1 = (rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff);
360   UINT32 rbd2 = (rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff);
361   agd1 >>= 8;
362   agd2 >>= 8;
363
364   rbd1 *= u;  rgb01 = (rgb00 & 0x00ff00ff);
365   agd1 *= u;  rbd1 >>= 8;
366   rbd2 *= u;  rgb11 = (rgb10 & 0x00ff00ff);
367   agd2 *= u;  rbd2 >>= 8;
368
369   rgb01 += rbd1;
370   rgb00 += agd1;
371
372   rgb11 += rbd2;
373   rgb10 += agd2;
374
375   rgb01 &= 0x00ff00ff;
376   rgb00 &= 0xff00ff00;
377   rgb10 &= 0xff00ff00;
378   rgb11 &= 0x00ff00ff;
379
380   // ---- rgb11 is now rb for the bottom
381   //      rgb10 is     ag for the bottom
382   //      rgb01 is     rb for the top
383   //      rgb00 is     ag for the top
384
385   rgb10 -= rgb00;  // agd
386   rgb11 -= rgb01;  // rbd
387   rgb10 >>= 8;
388
389   rgb11 *= v;
390   rgb10 *= v;
391   rgb11 >>= 8;
392
393   rgb00 += rgb10;
394   rgb01 += rgb11;
395
396   rgb00 &= 0xff00ff00;
397   rgb01 &= 0x00ff00ff;
398
399   return rgb00 | rgb01;
400}
401
402
403#endif /* __RGBUTIL__ */
src/emu/video/rgbutil.h
r0r1216
1/***************************************************************************
2
3    rgbutil.h
4
5    Utility definitions for RGB manipulation. Allows RGB handling to be
6    performed in an abstracted fashion and optimized with SIMD.
7
8    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
9    Visit http://mamedev.org for licensing and usage restrictions.
10
11***************************************************************************/
12
13#ifndef __RGBUTIL__
14#define __RGBUTIL__
15
16/* use SSE on 64-bit implementations, where it can be assumed */
17#if defined(PTR64) && (defined(__x86_64__) || defined(_MSC_VER))
18#include "rgbsse.h"
19#else
20#include "rgbgen.h"
21#endif
22
23#endif /* __RGBUTIL__ */
src/emu/video/vooddefs.h
r1215r1216
13861386};
13871387
13881388
1389/* note that this structure is an even 32 bytes long */
1389/* note that this structure is an even 64 bytes long */
13901390typedef struct _stats_block stats_block;
13911391struct _stats_block
13921392{
src/emu/video/rgbsse.h
r0r1216
1/***************************************************************************
2
3    rgbgen.h
4
5    SSE optimized RGB utilities.
6
7    WARNING: This code assumes SSE2 or greater capability.
8
9    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
10    Visit http://mamedev.org for licensing and usage restrictions.
11
12***************************************************************************/
13
14#ifndef __RGBSSE__
15#define __RGBSSE__
16
17#include <xmmintrin.h>
18
19
20/***************************************************************************
21    TYPE DEFINITIONS
22***************************************************************************/
23
24/* intermediate RGB values are stored in an __m128i */
25typedef __m128i rgbint;
26
27/* intermediate RGB values are stored in an __m128i */
28typedef __m128i rgbaint;
29
30
31
32/***************************************************************************
33    BASIC CONVERSIONS
34***************************************************************************/
35
36/*-------------------------------------------------
37    rgb_comp_to_rgbint - converts a trio of RGB
38    components to an rgbint type
39-------------------------------------------------*/
40
41INLINE void rgb_comp_to_rgbint(rgbint *rgb, INT16 r, INT16 g, INT16 b)
42{
43   *rgb = _mm_set_epi16(0, 0, 0, 0, 0, r, g, b);
44}
45
46
47/*-------------------------------------------------
48    rgba_comp_to_rgbint - converts a quad of RGB
49    components to an rgbint type
50-------------------------------------------------*/
51
52INLINE void rgba_comp_to_rgbaint(rgbaint *rgb, INT16 a, INT16 r, INT16 g, INT16 b)
53{
54   *rgb = _mm_set_epi16(0, 0, 0, 0, a, r, g, b);
55}
56
57
58/*-------------------------------------------------
59    rgb_to_rgbint - converts a packed trio of RGB
60    components to an rgbint type
61-------------------------------------------------*/
62
63INLINE void rgb_to_rgbint(rgbint *rgb, rgb_t color)
64{
65   *rgb = _mm_unpacklo_epi8(_mm_cvtsi32_si128(color), _mm_setzero_si128());
66}
67
68
69/*-------------------------------------------------
70    rgba_to_rgbaint - converts a packed quad of RGB
71    components to an rgbint type
72-------------------------------------------------*/
73
74INLINE void rgba_to_rgbaint(rgbaint *rgb, rgb_t color)
75{
76   *rgb = _mm_unpacklo_epi8(_mm_cvtsi32_si128(color), _mm_setzero_si128());
77}
78
79
80/*-------------------------------------------------
81    rgbint_to_rgb - converts an rgbint back to
82    a packed trio of RGB values
83-------------------------------------------------*/
84
85INLINE rgb_t rgbint_to_rgb(const rgbint *color)
86{
87   return _mm_cvtsi128_si32(_mm_packus_epi16(*color, *color));
88}
89
90
91/*-------------------------------------------------
92    rgbaint_to_rgba - converts an rgbint back to
93    a packed quad of RGB values
94-------------------------------------------------*/
95
96INLINE rgb_t rgbaint_to_rgba(const rgbaint *color)
97{
98   return _mm_cvtsi128_si32(_mm_packus_epi16(*color, *color));
99}
100
101
102/*-------------------------------------------------
103    rgbint_to_rgb_clamp - converts an rgbint back
104    to a packed trio of RGB values, clamping them
105    to bytes first
106-------------------------------------------------*/
107
108INLINE rgb_t rgbint_to_rgb_clamp(const rgbint *color)
109{
110   return _mm_cvtsi128_si32(_mm_packus_epi16(*color, *color));
111}
112
113
114/*-------------------------------------------------
115    rgbaint_to_rgba_clamp - converts an rgbint back
116    to a packed quad of RGB values, clamping them
117    to bytes first
118-------------------------------------------------*/
119
120INLINE rgb_t rgbaint_to_rgba_clamp(const rgbaint *color)
121{
122   return _mm_cvtsi128_si32(_mm_packus_epi16(*color, *color));
123}
124
125
126
127/***************************************************************************
128    CORE MATH
129***************************************************************************/
130
131/*-------------------------------------------------
132    rgbint_add - add two rgbint values
133-------------------------------------------------*/
134
135INLINE void rgbint_add(rgbint *color1, const rgbint *color2)
136{
137   *color1 = _mm_add_epi16(*color1, *color2);
138}
139
140
141/*-------------------------------------------------
142    rgbaint_add - add two rgbaint values
143-------------------------------------------------*/
144
145INLINE void rgbaint_add(rgbaint *color1, const rgbaint *color2)
146{
147   *color1 = _mm_add_epi16(*color1, *color2);
148}
149
150
151/*-------------------------------------------------
152    rgbint_sub - subtract two rgbint values
153-------------------------------------------------*/
154
155INLINE void rgbint_sub(rgbint *color1, const rgbint *color2)
156{
157   *color1 = _mm_sub_epi16(*color1, *color2);
158}
159
160
161/*-------------------------------------------------
162    rgbaint_sub - subtract two rgbaint values
163-------------------------------------------------*/
164
165INLINE void rgbaint_sub(rgbaint *color1, const rgbaint *color2)
166{
167   *color1 = _mm_sub_epi16(*color1, *color2);
168}
169
170
171/*-------------------------------------------------
172    rgbint_subr - reverse subtract two rgbint
173    values
174-------------------------------------------------*/
175
176INLINE void rgbint_subr(rgbint *color1, const rgbint *color2)
177{
178   __m128i temp = *color1;
179   *color1 = *color2;
180   *color1 = _mm_sub_epi16(*color1, temp);
181}
182
183
184/*-------------------------------------------------
185    rgbaint_subr - reverse subtract two rgbaint
186    values
187-------------------------------------------------*/
188
189INLINE void rgbaint_subr(rgbaint *color1, const rgbaint *color2)
190{
191   __m128i temp = *color1;
192   *color1 = *color2;
193   *color1 = _mm_sub_epi16(*color1, temp);
194}
195
196
197
198/***************************************************************************
199    TABLES
200***************************************************************************/
201
202static struct
203{
204   __m128   dummy_for_alignment;
205   INT16   zero[8];
206   INT16   maxbyte[8];
207   INT16   scale_table[256][8];
208} rgbsse_statics =
209{
210   { 0 },
211   {   0,   0,   0,   0,   0,   0,   0,   0 },
212   { 255, 255, 255, 255, 255, 255, 255, 255 },
213   {
214      {   1, 256,   1, 256,   1, 256,   1, 256 }, {   2, 255,   2, 255,   2, 255,   2, 255 },
215      {   3, 254,   3, 254,   3, 254,   3, 254 }, {   4, 253,   4, 253,   4, 253,   4, 253 },
216      {   5, 252,   5, 252,   5, 252,   5, 252 }, {   6, 251,   6, 251,   6, 251,   6, 251 },
217      {   7, 250,   7, 250,   7, 250,   7, 250 }, {   8, 249,   8, 249,   8, 249,   8, 249 },
218      {   9, 248,   9, 248,   9, 248,   9, 248 }, {  10, 247,  10, 247,  10, 247,  10, 247 },
219      {  11, 246,  11, 246,  11, 246,  11, 246 }, {  12, 245,  12, 245,  12, 245,  12, 245 },
220      {  13, 244,  13, 244,  13, 244,  13, 244 }, {  14, 243,  14, 243,  14, 243,  14, 243 },
221      {  15, 242,  15, 242,  15, 242,  15, 242 }, {  16, 241,  16, 241,  16, 241,  16, 241 },
222      {  17, 240,  17, 240,  17, 240,  17, 240 }, {  18, 239,  18, 239,  18, 239,  18, 239 },
223      {  19, 238,  19, 238,  19, 238,  19, 238 }, {  20, 237,  20, 237,  20, 237,  20, 237 },
224      {  21, 236,  21, 236,  21, 236,  21, 236 }, {  22, 235,  22, 235,  22, 235,  22, 235 },
225      {  23, 234,  23, 234,  23, 234,  23, 234 }, {  24, 233,  24, 233,  24, 233,  24, 233 },
226      {  25, 232,  25, 232,  25, 232,  25, 232 }, {  26, 231,  26, 231,  26, 231,  26, 231 },
227      {  27, 230,  27, 230,  27, 230,  27, 230 }, {  28, 229,  28, 229,  28, 229,  28, 229 },
228      {  29, 228,  29, 228,  29, 228,  29, 228 }, {  30, 227,  30, 227,  30, 227,  30, 227 },
229      {  31, 226,  31, 226,  31, 226,  31, 226 }, {  32, 225,  32, 225,  32, 225,  32, 225 },
230      {  33, 224,  33, 224,  33, 224,  33, 224 }, {  34, 223,  34, 223,  34, 223,  34, 223 },
231      {  35, 222,  35, 222,  35, 222,  35, 222 }, {  36, 221,  36, 221,  36, 221,  36, 221 },
232      {  37, 220,  37, 220,  37, 220,  37, 220 }, {  38, 219,  38, 219,  38, 219,  38, 219 },
233      {  39, 218,  39, 218,  39, 218,  39, 218 }, {  40, 217,  40, 217,  40, 217,  40, 217 },
234      {  41, 216,  41, 216,  41, 216,  41, 216 }, {  42, 215,  42, 215,  42, 215,  42, 215 },
235      {  43, 214,  43, 214,  43, 214,  43, 214 }, {  44, 213,  44, 213,  44, 213,  44, 213 },
236      {  45, 212,  45, 212,  45, 212,  45, 212 }, {  46, 211,  46, 211,  46, 211,  46, 211 },
237      {  47, 210,  47, 210,  47, 210,  47, 210 }, {  48, 209,  48, 209,  48, 209,  48, 209 },
238      {  49, 208,  49, 208,  49, 208,  49, 208 }, {  50, 207,  50, 207,  50, 207,  50, 207 },
239      {  51, 206,  51, 206,  51, 206,  51, 206 }, {  52, 205,  52, 205,  52, 205,  52, 205 },
240      {  53, 204,  53, 204,  53, 204,  53, 204 }, {  54, 203,  54, 203,  54, 203,  54, 203 },
241      {  55, 202,  55, 202,  55, 202,  55, 202 }, {  56, 201,  56, 201,  56, 201,  56, 201 },
242      {  57, 200,  57, 200,  57, 200,  57, 200 }, {  58, 199,  58, 199,  58, 199,  58, 199 },
243      {  59, 198,  59, 198,  59, 198,  59, 198 }, {  60, 197,  60, 197,  60, 197,  60, 197 },
244      {  61, 196,  61, 196,  61, 196,  61, 196 }, {  62, 195,  62, 195,  62, 195,  62, 195 },
245      {  63, 194,  63, 194,  63, 194,  63, 194 }, {  64, 193,  64, 193,  64, 193,  64, 193 },
246      {  65, 192,  65, 192,  65, 192,  65, 192 }, {  66, 191,  66, 191,  66, 191,  66, 191 },
247      {  67, 190,  67, 190,  67, 190,  67, 190 }, {  68, 189,  68, 189,  68, 189,  68, 189 },
248      {  69, 188,  69, 188,  69, 188,  69, 188 }, {  70, 187,  70, 187,  70, 187,  70, 187 },
249      {  71, 186,  71, 186,  71, 186,  71, 186 }, {  72, 185,  72, 185,  72, 185,  72, 185 },
250      {  73, 184,  73, 184,  73, 184,  73, 184 }, {  74, 183,  74, 183,  74, 183,  74, 183 },
251      {  75, 182,  75, 182,  75, 182,  75, 182 }, {  76, 181,  76, 181,  76, 181,  76, 181 },
252      {  77, 180,  77, 180,  77, 180,  77, 180 }, {  78, 179,  78, 179,  78, 179,  78, 179 },
253      {  79, 178,  79, 178,  79, 178,  79, 178 }, {  80, 177,  80, 177,  80, 177,  80, 177 },
254      {  81, 176,  81, 176,  81, 176,  81, 176 }, {  82, 175,  82, 175,  82, 175,  82, 175 },
255      {  83, 174,  83, 174,  83, 174,  83, 174 }, {  84, 173,  84, 173,  84, 173,  84, 173 },
256      {  85, 172,  85, 172,  85, 172,  85, 172 }, {  86, 171,  86, 171,  86, 171,  86, 171 },
257      {  87, 170,  87, 170,  87, 170,  87, 170 }, {  88, 169,  88, 169,  88, 169,  88, 169 },
258      {  89, 168,  89, 168,  89, 168,  89, 168 }, {  90, 167,  90, 167,  90, 167,  90, 167 },
259      {  91, 166,  91, 166,  91, 166,  91, 166 }, {  92, 165,  92, 165,  92, 165,  92, 165 },
260      {  93, 164,  93, 164,  93, 164,  93, 164 }, {  94, 163,  94, 163,  94, 163,  94, 163 },
261      {  95, 162,  95, 162,  95, 162,  95, 162 }, {  96, 161,  96, 161,  96, 161,  96, 161 },
262      {  97, 160,  97, 160,  97, 160,  97, 160 }, {  98, 159,  98, 159,  98, 159,  98, 159 },
263      {  99, 158,  99, 158,  99, 158,  99, 158 }, { 100, 157, 100, 157, 100, 157, 100, 157 },
264      { 101, 156, 101, 156, 101, 156, 101, 156 }, { 102, 155, 102, 155, 102, 155, 102, 155 },
265      { 103, 154, 103, 154, 103, 154, 103, 154 }, { 104, 153, 104, 153, 104, 153, 104, 153 },
266      { 105, 152, 105, 152, 105, 152, 105, 152 }, { 106, 151, 106, 151, 106, 151, 106, 151 },
267      { 107, 150, 107, 150, 107, 150, 107, 150 }, { 108, 149, 108, 149, 108, 149, 108, 149 },
268      { 109, 148, 109, 148, 109, 148, 109, 148 }, { 110, 147, 110, 147, 110, 147, 110, 147 },
269      { 111, 146, 111, 146, 111, 146, 111, 146 }, { 112, 145, 112, 145, 112, 145, 112, 145 },
270      { 113, 144, 113, 144, 113, 144, 113, 144 }, { 114, 143, 114, 143, 114, 143, 114, 143 },
271      { 115, 142, 115, 142, 115, 142, 115, 142 }, { 116, 141, 116, 141, 116, 141, 116, 141 },
272      { 117, 140, 117, 140, 117, 140, 117, 140 }, { 118, 139, 118, 139, 118, 139, 118, 139 },
273      { 119, 138, 119, 138, 119, 138, 119, 138 }, { 120, 137, 120, 137, 120, 137, 120, 137 },
274      { 121, 136, 121, 136, 121, 136, 121, 136 }, { 122, 135, 122, 135, 122, 135, 122, 135 },
275      { 123, 134, 123, 134, 123, 134, 123, 134 }, { 124, 133, 124, 133, 124, 133, 124, 133 },
276      { 125, 132, 125, 132, 125, 132, 125, 132 }, { 126, 131, 126, 131, 126, 131, 126, 131 },
277      { 127, 130, 127, 130, 127, 130, 127, 130 }, { 128, 129, 128, 129, 128, 129, 128, 129 },
278      { 129, 128, 129, 128, 129, 128, 129, 128 }, { 130, 127, 130, 127, 130, 127, 130, 127 },
279      { 131, 126, 131, 126, 131, 126, 131, 126 }, { 132, 125, 132, 125, 132, 125, 132, 125 },
280      { 133, 124, 133, 124, 133, 124, 133, 124 }, { 134, 123, 134, 123, 134, 123, 134, 123 },
281      { 135, 122, 135, 122, 135, 122, 135, 122 }, { 136, 121, 136, 121, 136, 121, 136, 121 },
282      { 137, 120, 137, 120, 137, 120, 137, 120 }, { 138, 119, 138, 119, 138, 119, 138, 119 },
283      { 139, 118, 139, 118, 139, 118, 139, 118 }, { 140, 117, 140, 117, 140, 117, 140, 117 },
284      { 141, 116, 141, 116, 141, 116, 141, 116 }, { 142, 115, 142, 115, 142, 115, 142, 115 },
285      { 143, 114, 143, 114, 143, 114, 143, 114 }, { 144, 113, 144, 113, 144, 113, 144, 113 },
286      { 145, 112, 145, 112, 145, 112, 145, 112 }, { 146, 111, 146, 111, 146, 111, 146, 111 },
287      { 147, 110, 147, 110, 147, 110, 147, 110 }, { 148, 109, 148, 109, 148, 109, 148, 109 },
288      { 149, 108, 149, 108, 149, 108, 149, 108 }, { 150, 107, 150, 107, 150, 107, 150, 107 },
289      { 151, 106, 151, 106, 151, 106, 151, 106 }, { 152, 105, 152, 105, 152, 105, 152, 105 },
290      { 153, 104, 153, 104, 153, 104, 153, 104 }, { 154, 103, 154, 103, 154, 103, 154, 103 },
291      { 155, 102, 155, 102, 155, 102, 155, 102 }, { 156, 101, 156, 101, 156, 101, 156, 101 },
292      { 157, 100, 157, 100, 157, 100, 157, 100 }, { 158,  99, 158,  99, 158,  99, 158,  99 },
293      { 159,  98, 159,  98, 159,  98, 159,  98 }, { 160,  97, 160,  97, 160,  97, 160,  97 },
294      { 161,  96, 161,  96, 161,  96, 161,  96 }, { 162,  95, 162,  95, 162,  95, 162,  95 },
295      { 163,  94, 163,  94, 163,  94, 163,  94 }, { 164,  93, 164,  93, 164,  93, 164,  93 },
296      { 165,  92, 165,  92, 165,  92, 165,  92 }, { 166,  91, 166,  91, 166,  91, 166,  91 },
297      { 167,  90, 167,  90, 167,  90, 167,  90 }, { 168,  89, 168,  89, 168,  89, 168,  89 },
298      { 169,  88, 169,  88, 169,  88, 169,  88 }, { 170,  87, 170,  87, 170,  87, 170,  87 },
299      { 171,  86, 171,  86, 171,  86, 171,  86 }, { 172,  85, 172,  85, 172,  85, 172,  85 },
300      { 173,  84, 173,  84, 173,  84, 173,  84 }, { 174,  83, 174,  83, 174,  83, 174,  83 },
301      { 175,  82, 175,  82, 175,  82, 175,  82 }, { 176,  81, 176,  81, 176,  81, 176,  81 },
302      { 177,  80, 177,  80, 177,  80, 177,  80 }, { 178,  79, 178,  79, 178,  79, 178,  79 },
303      { 179,  78, 179,  78, 179,  78, 179,  78 }, { 180,  77, 180,  77, 180,  77, 180,  77 },
304      { 181,  76, 181,  76, 181,  76, 181,  76 }, { 182,  75, 182,  75, 182,  75, 182,  75 },
305      { 183,  74, 183,  74, 183,  74, 183,  74 }, { 184,  73, 184,  73, 184,  73, 184,  73 },
306      { 185,  72, 185,  72, 185,  72, 185,  72 }, { 186,  71, 186,  71, 186,  71, 186,  71 },
307      { 187,  70, 187,  70, 187,  70, 187,  70 }, { 188,  69, 188,  69, 188,  69, 188,  69 },
308      { 189,  68, 189,  68, 189,  68, 189,  68 }, { 190,  67, 190,  67, 190,  67, 190,  67 },
309      { 191,  66, 191,  66, 191,  66, 191,  66 }, { 192,  65, 192,  65, 192,  65, 192,  65 },
310      { 193,  64, 193,  64, 193,  64, 193,  64 }, { 194,  63, 194,  63, 194,  63, 194,  63 },
311      { 195,  62, 195,  62, 195,  62, 195,  62 }, { 196,  61, 196,  61, 196,  61, 196,  61 },
312      { 197,  60, 197,  60, 197,  60, 197,  60 }, { 198,  59, 198,  59, 198,  59, 198,  59 },
313      { 199,  58, 199,  58, 199,  58, 199,  58 }, { 200,  57, 200,  57, 200,  57, 200,  57 },
314      { 201,  56, 201,  56, 201,  56, 201,  56 }, { 202,  55, 202,  55, 202,  55, 202,  55 },
315      { 203,  54, 203,  54, 203,  54, 203,  54 }, { 204,  53, 204,  53, 204,  53, 204,  53 },
316      { 205,  52, 205,  52, 205,  52, 205,  52 }, { 206,  51, 206,  51, 206,  51, 206,  51 },
317      { 207,  50, 207,  50, 207,  50, 207,  50 }, { 208,  49, 208,  49, 208,  49, 208,  49 },
318      { 209,  48, 209,  48, 209,  48, 209,  48 }, { 210,  47, 210,  47, 210,  47, 210,  47 },
319      { 211,  46, 211,  46, 211,  46, 211,  46 }, { 212,  45, 212,  45, 212,  45, 212,  45 },
320      { 213,  44, 213,  44, 213,  44, 213,  44 }, { 214,  43, 214,  43, 214,  43, 214,  43 },
321      { 215,  42, 215,  42, 215,  42, 215,  42 }, { 216,  41, 216,  41, 216,  41, 216,  41 },
322      { 217,  40, 217,  40, 217,  40, 217,  40 }, { 218,  39, 218,  39, 218,  39, 218,  39 },
323      { 219,  38, 219,  38, 219,  38, 219,  38 }, { 220,  37, 220,  37, 220,  37, 220,  37 },
324      { 221,  36, 221,  36, 221,  36, 221,  36 }, { 222,  35, 222,  35, 222,  35, 222,  35 },
325      { 223,  34, 223,  34, 223,  34, 223,  34 }, { 224,  33, 224,  33, 224,  33, 224,  33 },
326      { 225,  32, 225,  32, 225,  32, 225,  32 }, { 226,  31, 226,  31, 226,  31, 226,  31 },
327      { 227,  30, 227,  30, 227,  30, 227,  30 }, { 228,  29, 228,  29, 228,  29, 228,  29 },
328      { 229,  28, 229,  28, 229,  28, 229,  28 }, { 230,  27, 230,  27, 230,  27, 230,  27 },
329      { 231,  26, 231,  26, 231,  26, 231,  26 }, { 232,  25, 232,  25, 232,  25, 232,  25 },
330      { 233,  24, 233,  24, 233,  24, 233,  24 }, { 234,  23, 234,  23, 234,  23, 234,  23 },
331      { 235,  22, 235,  22, 235,  22, 235,  22 }, { 236,  21, 236,  21, 236,  21, 236,  21 },
332      { 237,  20, 237,  20, 237,  20, 237,  20 }, { 238,  19, 238,  19, 238,  19, 238,  19 },
333      { 239,  18, 239,  18, 239,  18, 239,  18 }, { 240,  17, 240,  17, 240,  17, 240,  17 },
334      { 241,  16, 241,  16, 241,  16, 241,  16 }, { 242,  15, 242,  15, 242,  15, 242,  15 },
335      { 243,  14, 243,  14, 243,  14, 243,  14 }, { 244,  13, 244,  13, 244,  13, 244,  13 },
336      { 245,  12, 245,  12, 245,  12, 245,  12 }, { 246,  11, 246,  11, 246,  11, 246,  11 },
337      { 247,  10, 247,  10, 247,  10, 247,  10 }, { 248,   9, 248,   9, 248,   9, 248,   9 },
338      { 249,   8, 249,   8, 249,   8, 249,   8 }, { 250,   7, 250,   7, 250,   7, 250,   7 },
339      { 251,   6, 251,   6, 251,   6, 251,   6 }, { 252,   5, 252,   5, 252,   5, 252,   5 },
340      { 253,   4, 253,   4, 253,   4, 253,   4 }, { 254,   3, 254,   3, 254,   3, 254,   3 },
341      { 255,   2, 255,   2, 255,   2, 255,   2 }, { 256,   1, 256,   1, 256,   1, 256,   1 }
342   }
343};
344
345
346
347/***************************************************************************
348    HIGHER LEVEL OPERATIONS
349***************************************************************************/
350
351/*-------------------------------------------------
352    rgbint_blend - blend two colors by the given
353    scale factor
354-------------------------------------------------*/
355
356INLINE void rgbint_blend(rgbint *color1, const rgbint *color2, UINT8 color1scale)
357{
358   *color1 = _mm_unpacklo_epi16(*color1, *color2);
359   *color1 = _mm_madd_epi16(*color1, *(__m128i *)&rgbsse_statics.scale_table[color1scale][0]);
360   *color1 = _mm_srli_epi32(*color1, 8);
361   *color1 = _mm_packs_epi32(*color1, *color1);
362}
363
364
365/*-------------------------------------------------
366    rgbaint_blend - blend two colors by the given
367    scale factor
368-------------------------------------------------*/
369
370INLINE void rgbaint_blend(rgbaint *color1, const rgbaint *color2, UINT8 color1scale)
371{
372   rgbint_blend(color1, color2, color1scale);
373}
374
375
376/*-------------------------------------------------
377    rgbint_scale_and_clamp - scale the given
378    color by an 8.8 scale factor and clamp to
379    byte values
380-------------------------------------------------*/
381
382INLINE void rgbint_scale_and_clamp(rgbint *color, INT16 colorscale)
383{
384   __m128i mscale = _mm_set1_epi16(colorscale);
385   *color = _mm_unpacklo_epi16(*color, _mm_setzero_si128());
386   *color = _mm_madd_epi16(*color, mscale);
387   *color = _mm_srli_epi32(*color, 8);
388   *color = _mm_packs_epi32(*color, *color);
389   *color = _mm_min_epi16(*color, *(__m128i *)&rgbsse_statics.maxbyte);
390}
391
392
393/*-------------------------------------------------
394    rgbaint_scale_and_clamp - scale the given
395    color by an 8.8 scale factor and clamp to
396    byte values
397-------------------------------------------------*/
398
399INLINE void rgbaint_scale_and_clamp(rgbaint *color, INT16 colorscale)
400{
401   rgbint_scale_and_clamp(color, colorscale);
402}
403
404
405/*-------------------------------------------------
406    rgb_bilinear_filter - bilinear filter between
407    four pixel values
408-------------------------------------------------*/
409
410INLINE rgb_t rgb_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, UINT8 u, UINT8 v)
411{
412   __m128i color00 = _mm_cvtsi32_si128(rgb00);
413   __m128i color01 = _mm_cvtsi32_si128(rgb01);
414   __m128i color10 = _mm_cvtsi32_si128(rgb10);
415   __m128i color11 = _mm_cvtsi32_si128(rgb11);
416
417   /* interleave color01 and color00 at the byte level */
418   color01 = _mm_unpacklo_epi8(color01, color00);
419   color11 = _mm_unpacklo_epi8(color11, color10);
420   color01 = _mm_unpacklo_epi8(color01, _mm_setzero_si128());
421   color11 = _mm_unpacklo_epi8(color11, _mm_setzero_si128());
422   color01 = _mm_madd_epi16(color01, *(__m128i *)&rgbsse_statics.scale_table[u][0]);
423   color11 = _mm_madd_epi16(color11, *(__m128i *)&rgbsse_statics.scale_table[u][0]);
424   color01 = _mm_slli_epi32(color01, 15);
425   color11 = _mm_srli_epi32(color11, 1);
426   color01 = _mm_max_epi16(color01, color11);
427   color01 = _mm_madd_epi16(color01, *(__m128i *)&rgbsse_statics.scale_table[v][0]);
428   color01 = _mm_srli_epi32(color01, 15);
429   color01 = _mm_packs_epi32(color01, color01);
430   color01 = _mm_packus_epi16(color01, color01);
431   return _mm_cvtsi128_si32(color01);
432}
433
434
435/*-------------------------------------------------
436    rgba_bilinear_filter - bilinear filter between
437    four pixel values
438-------------------------------------------------*/
439
440INLINE rgb_t rgba_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, UINT8 u, UINT8 v)
441{
442   return rgb_bilinear_filter(rgb00, rgb01, rgb10, rgb11, u, v);
443}
444
445
446#endif /* __RGBUTIL__ */
src/emu/video/polynew.c
r1215r1216
77***************************************************************************/
88
99#include "polynew.h"
10#include "eminline.h"
1011#include "mame.h"
1112#include <math.h>
1213
r1215r1216
614615            {
615616               orig_count_next = prevunit->count_next;
616617               new_count_next = orig_count_next | (unitnum << 16);
617            } while (osd_compare_exchange32((volatile INT32 *)&prevunit->count_next, orig_count_next, new_count_next) != orig_count_next);
618            } while (compare_exchange32((volatile INT32 *)&prevunit->count_next, orig_count_next, new_count_next) != orig_count_next);
618619
619620#if KEEP_STATISTICS
620621            /* track resolved conflicts */
r1215r1216
636637      do
637638      {
638639         orig_count_next = unit->count_next;
639      } while (osd_compare_exchange32((volatile INT32 *)&unit->count_next, orig_count_next, 0) != orig_count_next);
640      } while (compare_exchange32((volatile INT32 *)&unit->count_next, orig_count_next, 0) != orig_count_next);
640641
641642      /* if we have no more work to do, do nothing */
642643      orig_count_next >>= 16;
src/emu/tilemap.c
r1215r1216
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "osinline.h"
1413#include "tilemap.h"
1514#include "profiler.h"
1615
src/emu/eminline.h
r0r1216
1/***************************************************************************
2
3    eminline.h
4
5    Definitions for inline functions that can be overriden by OSD-
6    specific code.
7
8    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
9    Visit http://mamedev.org for licensing and usage restrictions.
10
11***************************************************************************/
12
13#ifndef __EMINLINE__
14#define __EMINLINE__
15
16/* we come with implementations for GCC x86 and PPC */
17#ifdef __GNUC__
18
19#if defined(__i386__) || defined(__x86_64__)
20#include "eigccx86.h"
21#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
22#include "eigccppc.h"
23#else
24#include "osinline.h"
25#endif
26
27#else
28
29#include "osinline.h"
30
31#endif
32
33
34/***************************************************************************
35    INLINE MATH FUNCTIONS
36***************************************************************************/
37
38/*-------------------------------------------------
39    mul_32x32 - perform a signed 32 bit x 32 bit
40    multiply and return the full 64 bit result
41-------------------------------------------------*/
42
43#ifndef mul_32x32
44INLINE INT64 mul_32x32(INT32 a, INT32 b)
45{
46   return (INT64)a * (INT64)b;
47}
48#endif
49
50
51/*-------------------------------------------------
52    mulu_32x32 - perform an unsigned 32 bit x
53    32 bit multiply and return the full 64 bit
54    result
55-------------------------------------------------*/
56
57#ifndef mulu_32x32
58INLINE UINT64 mulu_32x32(UINT32 a, UINT32 b)
59{
60   return (UINT64)a * (UINT64)b;
61}
62#endif
63
64
65/*-------------------------------------------------
66    mul_32x32_hi - perform a signed 32 bit x 32 bit
67    multiply and return the upper 32 bits of the
68    result
69-------------------------------------------------*/
70
71#ifndef mul_32x32_hi
72INLINE INT32 mul_32x32_hi(INT32 a, INT32 b)
73{
74   return (UINT32)(((INT64)a * (INT64)b) >> 32);
75}
76#endif
77
78
79/*-------------------------------------------------
80    mulu_32x32_hi - perform an unsigned 32 bit x
81    32 bit multiply and return the upper 32 bits
82    of the result
83-------------------------------------------------*/
84
85#ifndef mulu_32x32_hi
86INLINE UINT32 mulu_32x32_hi(UINT32 a, UINT32 b)
87{
88   return (UINT32)(((UINT64)a * (UINT64)b) >> 32);
89}
90#endif
91
92
93/*-------------------------------------------------
94    mul_32x32_shift - perform a signed 32 bit x
95    32 bit multiply and shift the result by the
96    given number of bits before truncating the
97    result to 32 bits
98-------------------------------------------------*/
99
100#ifndef mul_32x32_shift
101INLINE INT32 mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
102{
103   return (INT32)(((INT64)a * (INT64)b) >> shift);
104}
105#endif
106
107
108/*-------------------------------------------------
109    mulu_32x32_shift - perform an unsigned 32 bit x
110    32 bit multiply and shift the result by the
111    given number of bits before truncating the
112    result to 32 bits
113-------------------------------------------------*/
114
115#ifndef mulu_32x32_shift
116INLINE UINT32 mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
117{
118   return (UINT32)(((UINT64)a * (UINT64)b) >> shift);
119}
120#endif
121
122
123/*-------------------------------------------------
124    div_64x32 - perform a signed 64 bit x 32 bit
125    divide and return the 32 bit quotient
126-------------------------------------------------*/
127
128#ifndef div_64x32
129INLINE INT32 div_64x32(INT64 a, INT32 b)
130{
131   return a / (INT64)b;
132}
133#endif
134
135
136/*-------------------------------------------------
137    divu_64x32 - perform an unsigned 64 bit x 32 bit
138    divide and return the 32 bit quotient
139-------------------------------------------------*/
140
141#ifndef divu_64x32
142INLINE UINT32 divu_64x32(UINT64 a, UINT32 b)
143{
144   return a / (UINT64)b;
145}
146#endif
147
148
149/*-------------------------------------------------
150    div_32x32_shift - perform a signed divide of
151    two 32 bit values, shifting the first before
152    division, and returning the 32 bit quotient
153-------------------------------------------------*/
154
155#ifndef div_32x32_shift
156INLINE INT32 div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
157{
158   return ((INT64)a << shift) / (INT64)b;
159}
160#endif
161
162
163/*-------------------------------------------------
164    divu_32x32_shift - perform an unsigned divide of
165    two 32 bit values, shifting the first before
166    division, and returning the 32 bit quotient
167-------------------------------------------------*/
168
169#ifndef divu_32x32_shift
170INLINE UINT32 divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
171{
172   return ((UINT64)a << shift) / (UINT64)b;
173}
174#endif
175
176
177/*-------------------------------------------------
178    mod_64x32 - perform a signed 64 bit x 32 bit
179    divide and return the 32 bit remainder
180-------------------------------------------------*/
181
182#ifndef mod_64x32
183INLINE INT32 mod_64x32(INT64 a, INT32 b)
184{
185   return a % (INT64)b;
186}
187#endif
188
189
190/*-------------------------------------------------
191    modu_64x32 - perform an unsigned 64 bit x 32 bit
192    divide and return the 32 bit remainder
193-------------------------------------------------*/
194
195#ifndef modu_64x32
196INLINE UINT32 modu_64x32(UINT64 a, UINT32 b)
197{
198   return a % (UINT64)b;
199}
200#endif
201
202
203/*-------------------------------------------------
204    recip_approx - compute an approximate floating
205    point reciprocal
206-------------------------------------------------*/
207
208#ifndef recip_approx
209INLINE float recip_approx(float value)
210{
211   return 1.0f / value;
212}
213#endif
214
215
216
217/***************************************************************************
218    INLINE BIT MANIPULATION FUNCTIONS
219***************************************************************************/
220
221/*-------------------------------------------------
222    count_leading_zeros - return the number of
223    leading zero bits in a 32-bit value
224-------------------------------------------------*/
225
226#ifndef count_leading_zeros
227INLINE UINT8 count_leading_zeros(UINT32 val)
228{
229   UINT8 count;
230   for (count = 0; (INT32)val >= 0; count++) val <<= 1;
231   return count;
232}
233#endif
234
235
236/*-------------------------------------------------
237    count_leading_ones - return the number of
238    leading one bits in a 32-bit value
239-------------------------------------------------*/
240
241#ifndef count_leading_ones
242INLINE UINT8 count_leading_ones(UINT32 val)
243{
244   UINT8 count;
245   for (count = 0; (INT32)val < 0; count++) val <<= 1;
246   return count;
247}
248#endif
249
250
251
252/***************************************************************************
253    INLINE SYNCHRONIZATION FUNCTIONS
254***************************************************************************/
255
256/*-------------------------------------------------
257    compare_exchange32 - compare the 'compare'
258    value against the memory at 'ptr'; if equal,
259    swap in the 'exchange' value. Regardless,
260    return the previous value at 'ptr'.
261
262    Note that the default implementation does
263    no synchronization. You MUST override this
264    in osinline.h for it to be useful in a
265    multithreaded environment!
266-------------------------------------------------*/
267
268#ifndef compare_exchange32
269INLINE INT32 compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
270{
271   INT32 oldval = *ptr;
272   if (*ptr == compare)
273      *ptr = exchange;
274   return oldval;
275}
276#endif
277
278
279/*-------------------------------------------------
280    compare_exchange64 - compare the 'compare'
281    value against the memory at 'ptr'; if equal,
282    swap in the 'exchange' value. Regardless,
283    return the previous value at 'ptr'.
284
285    Note that the default implementation does
286    no synchronization. You MUST override this
287    in osinline.h for it to be useful in a
288    multithreaded environment!
289-------------------------------------------------*/
290
291#ifdef PTR64
292#ifndef compare_exchange64
293INLINE INT64 compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
294{
295   INT64 oldval = *ptr;
296   if (*ptr == compare)
297      *ptr = exchange;
298   return oldval;
299}
300#endif
301#endif
302
303
304/*-------------------------------------------------
305    compare_exchange_ptr - compare the 'compare'
306    value against the memory at 'ptr'; if equal,
307    swap in the 'exchange' value. Regardless,
308    return the previous value at 'ptr'.
309-------------------------------------------------*/
310
311#ifdef PTR64
312#ifndef compare_exchange_ptr
313INLINE void *compare_exchange_ptr(void * volatile *ptr, void *compare, void *exchange)
314{
315#ifdef PTR64
316   return (void *)compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
317#else
318   return (void *)compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
319#endif
320}
321#endif
322#endif
323
324
325/*-------------------------------------------------
326    atomic_exchange32 - atomically exchange the
327    exchange value with the memory at 'ptr',
328    returning the original value.
329
330    Note that the default implementation does
331    no synchronization. You MUST override this
332    in osinline.h for it to be useful in a
333    multithreaded environment!
334-------------------------------------------------*/
335
336#ifndef atomic_exchange32
337INLINE INT32 atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
338{
339   INT32 oldval = *ptr;
340   *ptr = exchange;
341   return oldval;
342}
343#endif
344
345
346/*-------------------------------------------------
347    atomic_add32 - atomically add the delta value
348    to the memory at 'ptr', returning the final
349    result.
350
351    Note that the default implementation does
352    no synchronization. You MUST override this
353    in osinline.h for it to be useful in a
354    multithreaded environment!
355-------------------------------------------------*/
356
357#ifndef atomic_add32
358INLINE INT32 atomic_add32(INT32 volatile *ptr, INT32 delta)
359{
360   return (*ptr += delta);
361}
362#endif
363
364#endif /* __EMINLINE__ */
src/emu/emu.mak
r1215r1216
130130   $(EMUMACHINE)/ds2404.o \
131131   $(EMUMACHINE)/eeprom.o \
132132   $(EMUMACHINE)/generic.o \
133   $(EMUMACHINE)/i2cmem.o \
133134    $(EMUMACHINE)/idectrl.o \
134135    $(EMUMACHINE)/intelfsh.o \
135136   $(EMUMACHINE)/laserdsc.o \
r1215r1216
145146   $(EMUMACHINE)/roc10937.o \
146147   $(EMUMACHINE)/rp5h01.o \
147148   $(EMUMACHINE)/rtc65271.o \
149   $(EMUMACHINE)/scsi.o \
148150   $(EMUMACHINE)/scsicd.o \
151   $(EMUMACHINE)/scsidev.o \
149152   $(EMUMACHINE)/scsihd.o \
153   $(EMUMACHINE)/cr589.o \
150154    $(EMUMACHINE)/smc91c9x.o \
151155   $(EMUMACHINE)/timekpr.o \
152156   $(EMUMACHINE)/tmp68301.o \
src/emu/mame.c
r1215r1216
605605   else
606606      mame->exit_pending = TRUE;
607607
608   /* if we're executing, abort out immediately */
609   if (cpu_getactivecpu() >= 0)
610      activecpu_adjust_icount(-activecpu_get_icount() - 1);
611
608612   /* if we're autosaving on exit, schedule a save as well */
609613   if (options_get_bool(mame_options(), OPTION_AUTOSAVE) && (machine->gamedrv->flags & GAME_SUPPORTS_SAVE))
610614      mame_schedule_save(machine, "auto");
r1215r1216
620624{
621625   mame_private *mame = machine->mame_data;
622626   mame->hard_reset_pending = TRUE;
627
628   /* if we're executing, abort out immediately */
629   if (cpu_getactivecpu() >= 0)
630      activecpu_adjust_icount(-activecpu_get_icount() - 1);
623631}
624632
625633
r1215r1216
636644
637645   /* we can't be paused since the timer needs to fire */
638646   mame_pause(machine, FALSE);
647
648   /* if we're executing, abort out immediately */
649   if (cpu_getactivecpu() >= 0)
650      activecpu_adjust_icount(-activecpu_get_icount() - 1);
639651}
640652
641653
r1215r1216
649661   mame_private *mame = machine->mame_data;
650662   mame->hard_reset_pending = TRUE;
651663   mame->new_driver_pending = driver;
664
665   /* if we're executing, abort out immediately */
666   if (cpu_getactivecpu() >= 0)
667      activecpu_adjust_icount(-activecpu_get_icount() - 1);
652668}
653669
654670
src/emu/eigccppc.h
r0r1216
1/***************************************************************************
2
3    eigccppc.h
4
5    PowerPC (32 and 64-bit) inline implementations for GCC compilers. This
6    code is automatically included if appropriate by eminline.h.
7
8    Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
9    Visit http://mamedev.org for licensing and usage restrictions.
10
11***************************************************************************/
12
13#ifndef __EIGCCPPC__
14#define __EIGCCPPC__
15
16
17/***************************************************************************
18    INLINE MATH FUNCTIONS
19***************************************************************************/
20
21/*-------------------------------------------------
22    mul_32x32 - perform a signed 32 bit x 32 bit
23    multiply and return the full 64 bit result
24-------------------------------------------------*/
25
26/* TBD */
27
28
29/*-------------------------------------------------
30    mulu_32x32 - perform an unsigned 32 bit x
31    32 bit multiply and return the full 64 bit
32    result
33-------------------------------------------------*/
34
35/* TBD */
36
37
38/*-------------------------------------------------
39    mul_32x32_hi - perform a signed 32 bit x 32 bit
40    multiply and return the upper 32 bits of the
41    result
42-------------------------------------------------*/
43
44#define mul_32x32_hi _mul_32x32_hi
45INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
46{
47   INT32 result;
48
49   __asm__ (
50      " mulhw  %0,%1,%2   \n"
51     : "=&r" (result),
52      "+r" (val1)
53     : "r" (val2)
54     : "xer"
55   );
56
57   return result;
58}
59
60
61/*-------------------------------------------------
62    mulu_32x32_hi - perform an unsigned 32 bit x
63    32 bit multiply and return the upper 32 bits
64    of the result
65-------------------------------------------------*/
66
67#define mulu_32x32_hi _mulu_32x32_hi
68INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
69{
70   UINT32 result;
71
72   __asm__ (
73      " mulhwu %0,%1,%2   \n"
74     : "=&r" (result),
75      "+r" (val1)
76     : "r" (val2)
77     : "xer"
78   );
79
80   return result;
81}
82
83
84/*-------------------------------------------------
85    mul_32x32_shift - perform a signed 32 bit x
86    32 bit multiply and shift the result by the
87    given number of bits before truncating the
88    result to 32 bits
89-------------------------------------------------*/
90
91#define mul_32x32_shift _mul_32x32_shift
92INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
93{
94   INT32 result;
95
96#if defined(__ppc64__) || defined(__PPC64__)
97   __asm__ (
98      " mulld  %0,%1,%2 \n"
99      " srd    %0,%0,%3 \n"
100     : "=&r" (result)         /* result can go in any register */
101     : "%r" (val1)            /* any register, can swap with val2 */
102      "r" (val2)            /* any register */
103      "r" (shift)            /* any register */
104   );
105#else
106   __asm__ (
107      " mullw  %0,%2,%3   \n"
108      " mulhw  %2,%2,%3   \n"
109      " srw    %0,%0,%1   \n"
110      " subfic %1,%1,0x20 \n"
111      " slw    %2,%2,%1   \n"
112      " or     %0,%0,%2   \n"
113     : "=&r" (result),
114      "+r" (shift),
115      "+r" (val1)
116     : "r" (val2)
117     : "xer"
118   );
119#endif
120
121   return result;
122}
123
124
125/*-------------------------------------------------
126    mulu_32x32_shift - perform an unsigned 32 bit x
127    32 bit multiply and shift the result by the
128    given number of bits before truncating the
129    result to 32 bits
130-------------------------------------------------*/
131
132#define mulu_32x32_shift _mulu_32x32_shift
133INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
134{
135   UINT32 result;
136
137#if defined(__ppc64__) || defined(__PPC64__)
138   __asm__ (
139      " mulldu %0,%1,%2 \n"
140      " srd    %0,%0,%3 \n"
141     : "=&r" (result)         /* result can go in any register */
142     : "%r" (val1)            /* any register, can swap with val2 */
143      "r" (val2)            /* any register */
144      "r" (shift)            /* any register */
145   );
146#else
147   __asm__ (
148      " mullw  %0,%2,%3   \n"
149      " mulhwu %2,%2,%3   \n"
150      " srw    %0,%0,%1   \n"
151      " subfic %1,%1,0x20 \n"
152      " slw    %2,%2,%1   \n"
153      " or     %0,%0,%2   \n"
154     : "=&r" (result),
155      "+r" (shift),
156      "+r" (val1)
157     : "r" (val2)
158     : "xer"
159   );
160#endif
161
162   return result;
163}
164
165
166/*-------------------------------------------------
167    div_64x32 - perform a signed 64 bit x 32 bit
168    divide and return the 32 bit quotient
169-------------------------------------------------*/
170
171/* TBD */
172
173
174/*-------------------------------------------------
175    divu_64x32 - perform an unsigned 64 bit x 32 bit
176    divide and return the 32 bit quotient
177-------------------------------------------------*/
178
179/* TBD */
180
181
182/*-------------------------------------------------
183    div_32x32_shift - perform a signed divide of
184    two 32 bit values, shifting the first before
185    division, and returning the 32 bit quotient
186-------------------------------------------------*/
187
188/* TBD */
189
190
191/*-------------------------------------------------
192    divu_32x32_shift - perform an unsigned divide of
193    two 32 bit values, shifting the first before
194    division, and returning the 32 bit quotient
195-------------------------------------------------*/
196
197/* TBD */
198
199
200/*-------------------------------------------------
201    mod_64x32 - perform a signed 64 bit x 32 bit
202    divide and return the 32 bit remainder
203-------------------------------------------------*/
204
205/* TBD */
206
207
208/*-------------------------------------------------
209    modu_64x32 - perform an unsigned 64 bit x 32 bit
210    divide and return the 32 bit remainder
211-------------------------------------------------*/
212
213/* TBD */
214
215
216/*-------------------------------------------------
217    recip_approx - compute an approximate floating
218    point reciprocal
219-------------------------------------------------*/
220
221/* TBD */
222
223
224
225/***************************************************************************
226    INLINE BIT MANIPULATION FUNCTIONS
227***************************************************************************/
228
229/*-------------------------------------------------
230    count_leading_zeros - return the number of
231    leading zero bits in a 32-bit value
232-------------------------------------------------*/
233
234#define count_leading_zeros _count_leading_zeros
235INLINE UINT8 _count_leading_zeros(UINT32 value)
236{
237   UINT32 result;
238
239   __asm__ (
240      " cntlzw %0,%1 \n"
241      : "=r" (result)      /* result can be in any register */
242      : "r" (value)      /* 'value' can be in any register */
243   );
244
245   return result;
246}
247
248
249/*-------------------------------------------------
250    count_leading_ones - return the number of
251    leading one bits in a 32-bit value
252-------------------------------------------------*/
253
254#define count_leading_ones _count_leading_ones
255INLINE UINT8 _count_leading_ones(UINT32 value)
256{
257   UINT32 result;
258
259   __asm__ (
260      " not %0,%1 \n"
261      " cntlzw %0,%0 \n"
262      : "=r" (result)      /* result can be in any register */
263      : "r" (value)      /* 'value' can be in any register */
264   );
265
266   return result;
267}
268
269
270
271/***************************************************************************
272    INLINE SYNCHRONIZATION FUNCTIONS
273***************************************************************************/
274
275/*-------------------------------------------------
276    compare_exchange32 - compare the 'compare'
277    value against the memory at 'ptr'; if equal,
278    swap in the 'exchange' value. Regardless,
279    return the previous value at 'ptr'.
280-------------------------------------------------*/
281
282#define compare_exchange32 _compare_exchange32
283INLINE INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
284{
285   register INT32 result;
286
287   __asm__ __volatile__ (
288      "1: lwarx  %[result], 0, %[ptr]   \n"
289      "   cmpw   %[compare], %[result]  \n"
290      "   bne    2f                     \n"
291      "   sync                          \n"
292      "   stwcx. %[exchange], 0, %[ptr] \n"
293      "   bne- 1b                       \n"
294      "2:                                 "
295      : [result]   "=&r" (result)
296      : [ptr]      "r"   (ptr)
297      , [exchange] "r"   (exchange)
298      , [compare]  "r"   (compare)
299      : "cr0"
300   );
301
302   return result;
303}
304
305
306/*-------------------------------------------------
307    compare_exchange64 - compare the 'compare'
308    value against the memory at 'ptr'; if equal,
309    swap in the 'exchange' value. Regardless,
310    return the previous value at 'ptr'.
311-------------------------------------------------*/
312
313#ifdef PTR64
314#define compare_exchange64 _compare_exchange64
315INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
316{
317   register INT64 result;
318
319   __asm__ __volatile__ (
320      "1: ldarx  %[result], 0, %[ptr]   \n"
321      "   cmpd   %[compare], %[result]  \n"
322      "   bne    2f                     \n"
323      "   sync                          \n"
324      "   stdcx. %[exchange], 0, %[ptr] \n"
325      "   bne--  1b                     \n"
326      "2:                                 "
327      : [result]   "=&r" (result)
328      : [ptr]      "r"   (ptr)
329      , [exchange] "r"   (exchange)
330      , [compare]  "r"   (compare)
331      : "cr0"
332   );
333
334   return result;
335}
336#endif
337
338
339/*-------------------------------------------------
340    atomic_exchange32 - atomically exchange the
341    exchange value with the memory at 'ptr',
342    returning the original value.
343-------------------------------------------------*/
344
345#define atomic_exchange32 _atomic_exchange32
346INLINE INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
347{
348   register INT32 result;
349
350   __asm__ __volatile__ (
351      "1: lwarx  %[result], 0, %[ptr]   \n"
352      "   sync                          \n"
353      "   stwcx. %[exchange], 0, %[ptr] \n"
354      "   bne-   1b                     \n"
355      : [result]      "=&r" (result)
356      : [ptr]      "r"   (ptr)
357      , [exchange] "r"   (exchange)
358      : "cr0"
359   );
360
361   return result;
362}
363
364
365/*-------------------------------------------------
366    atomic_add32 - atomically add the delta value
367    to the memory at 'ptr', returning the final
368    result.
369-------------------------------------------------*/
370
371#define atomic_add32 _atomic_add32
372INLINE INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
373{
374   register INT32 result;
375
376   __asm __volatile__ (
377      "1: lwarx  %[result], 0, %[ptr]     \n"
378      "   add    %[result], %[result], %[delta] \n"
379      "   sync                            \n"
380      "   stwcx. %[result], 0, %[ptr]     \n"
381      "   bne- 1b                         \n"
382      : [result]   "=&b" (result)
383      : [ptr]   "r"   (ptr)
384      , [delta] "r"   (delta)
385      : "cr0"
386   );
387
388   return result;
389}
390
391
392#endif /* __EIGCCPPC__ */
src/emu/machine/cr589.c
r0r1216
1/*
2 * Matsushita CR-589
3 *
4 */
5
6#include "driver.h"
7#include "cr589.h"
8
9typedef struct
10{
11   int download;
12   UINT8 buffer[ 65536 ];
13   int bufferOffset;
14} SCSICr589;
15
16static const int identity_offset = 0x3ab;
17static const char *download_identity = "MATSHITA CD98Q4 DOWNLOADGS0N";
18
19static int cr589_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode )
20{
21   UINT8 *command;
22   int commandLength;
23   SCSICr589 *our_this = SCSIThis( &SCSIClassCr589, scsiInstance );
24   SCSIGetCommand( scsiInstance, &command, &commandLength );
25
26   switch( command[ 0 ] )
27   {
28      case 0x3b: // WRITE BUFFER
29         our_this->bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ];
30         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
31         return ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ];
32
33      case 0x3c: // READ BUFFER
34         our_this->bufferOffset = ( command[ 3 ] << 16 ) | ( command[ 4 ] << 8 ) | command[ 5 ];
35         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
36         return ( command[ 6 ] << 16 ) | ( command[ 7 ] << 8 ) | command[ 8 ];
37
38      case 0xcc: // FIRMWARE DOWNLOAD ENABLE
39         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
40         return SCSILengthFromUINT16( &command[7] );
41
42      default:
43         return SCSIBase( &SCSIClassCr589, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL );
44   }
45}
46
47static void cr589_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
48{
49   UINT8 *command;
50   int commandLength;
51   SCSICr589 *our_this = SCSIThis( &SCSIClassCr589, scsiInstance );
52   SCSIGetCommand( scsiInstance, &command, &commandLength );
53
54   switch( command[ 0 ] )
55   {
56      case 0x12: // INQUIRY
57         SCSIBase( &SCSIClassCr589, SCSIOP_READ_DATA, scsiInstance, dataLength, data );
58
59         if( our_this->download )
60         {
61            memcpy( &data[ 8 ], download_identity, 28 );
62         }
63         else
64         {
65            memcpy( &data[ 8 ], &our_this->buffer[ identity_offset ], 28 );
66         }
67         break;
68
69      case 0x3c: // READ BUFFER
70         memcpy( data, &our_this->buffer[ our_this->bufferOffset ], dataLength );
71         our_this->bufferOffset += dataLength;
72         break;
73
74      default:
75         SCSIBase( &SCSIClassCr589, SCSIOP_READ_DATA, scsiInstance, dataLength, data );
76         break;
77   }
78}
79
80static void cr589_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
81{
82   UINT8 *command;
83   int commandLength;
84   SCSICr589 *our_this = SCSIThis( &SCSIClassCr589, scsiInstance );
85   SCSIGetCommand( scsiInstance, &command, &commandLength );
86
87   switch( command[ 0 ] )
88   {
89      case 0x3b: // WRITE BUFFER
90         memcpy( &our_this->buffer[ our_this->bufferOffset ], data + 32, dataLength - 32 );
91         our_this->bufferOffset += dataLength;
92         break;
93
94      case 0xcc: // FIRMWARE DOWNLOAD ENABLE
95         if( memcmp( data, &our_this->buffer[ identity_offset ], 28 ) == 0 )
96         {
97            our_this->download = 1;
98         }
99         else if( memcmp( data, download_identity, 28 ) == 0 )
100         {
101            our_this->download = 0;
102         }
103         break;
104
105      default:
106         SCSIBase( &SCSIClassCr589, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data );
107         break;
108   }
109}
110
111static void cr589_alloc_instance( SCSIInstance *scsiInstance, int diskId )
112{
113   SCSICr589 *our_this = SCSIThis( &SCSIClassCr589, scsiInstance );
114
115   our_this->download = 0;
116   memcpy( &our_this->buffer[ identity_offset ], "MATSHITACD-ROM CR-589   GS0N", 28 );
117
118   state_save_register_item( "cr589", diskId, our_this->download );
119   state_save_register_item_array( "cr589", diskId, our_this->buffer );
120   state_save_register_item( "cr589", diskId, our_this->bufferOffset );
121}
122
123static int cr589_dispatch( int operation, void *file, INT64 intparm, void *ptrparm )
124{
125   switch( operation )
126   {
127      case SCSIOP_EXEC_COMMAND:
128         return cr589_exec_command( file, ptrparm );
129
130      case SCSIOP_READ_DATA:
131         cr589_read_data( file, ptrparm, intparm );
132         return 0;
133
134      case SCSIOP_WRITE_DATA:
135         cr589_write_data( file, ptrparm, intparm );
136         return 0;
137
138      case SCSIOP_ALLOC_INSTANCE:
139         SCSIBase( &SCSIClassCr589, operation, file, intparm, ptrparm );
140         cr589_alloc_instance( *((SCSIInstance **) ptrparm), intparm );
141         return 0;
142   }
143
144   return SCSIBase( &SCSIClassCr589, operation, file, intparm, ptrparm );
145}
146
147SCSIClass SCSIClassCr589 =
148{
149   &SCSIClassCDROM,
150   cr589_dispatch,
151   sizeof( SCSICr589 )
152};
src/emu/machine/scsihd.c
r1215r1216
1414
1515typedef struct
1616{
17   UINT32 lba, blocks, last_lba;
18   int last_command;
17   UINT32 lba;
18   UINT32 blocks;
1919    hard_disk_file *disk;
20   UINT8 last_packet[16];
21   UINT8 inquiry_buffer[96];
2220} SCSIHd;
2321
2422
2523// scsihd_exec_command
2624
27int scsihd_exec_command(SCSIHd *our_this, UINT8 *pCmdBuf)
25int scsihd_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode )
2826{
29   int retdata = 0;
27   UINT8 *command;
28   int commandLength;
29   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
30   SCSIGetCommand( scsiInstance, &command, &commandLength );
3031
31   // remember the last command for the data transfer phase
32   our_this->last_command = pCmdBuf[0] & 0x7f;
33
34   // remember the actual command packet too
35   memcpy(our_this->last_packet, pCmdBuf, 16);
36
37   switch (our_this->last_command)
32   switch ( command[0] )
3833   {
39      case 0:      // TEST UNIT READY
40         retdata = 12;
41         break;
42      case 3:    // REQUEST SENSE
43         retdata = 16;
44         break;
45      case 4:      // FORMAT UNIT
46         // (do nothing)
47         break;
34      case 0x03: // REQUEST SENSE
35         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
36         return SCSILengthFromUINT8( &command[ 4 ] );
4837
49      case 0x08:       // READ (6 byte)
50         our_this->lba = (pCmdBuf[1]&0x1f)<<16 | pCmdBuf[2]<<8 | pCmdBuf[3];
51         our_this->blocks = pCmdBuf[4];
52         if (our_this->blocks == 0)
53         {
54            our_this->blocks = 256;
55         }
38      case 0x04: // FORMAT UNIT
39         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
40         return 0;
5641
42      case 0x08: // READ(6)
43         our_this->lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3];
44         our_this->blocks = SCSILengthFromUINT8( &command[4] );
45
5746         logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
5847
59         retdata = our_this->blocks * 512;
60         break;
48         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
49         return our_this->blocks * 512;
6150
62      case 0x0a:   // WRITE (6 byte)
63         our_this->lba = (pCmdBuf[1]&0x1f)<<16 | pCmdBuf[2]<<8 | pCmdBuf[3];
64         our_this->blocks = pCmdBuf[4];
65         if (our_this->blocks == 0)
66         {
67            our_this->blocks = 256;
68         }
51      case 0x0a: // WRITE(6)
52         our_this->lba = (command[1]&0x1f)<<16 | command[2]<<8 | command[3];
53         our_this->blocks = SCSILengthFromUINT8( &command[4] );
6954
7055         logerror("SCSIHD: WRITE to LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
7156
72         retdata = our_this->blocks * 512;
73         break;
57         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
58         return our_this->blocks * 512;
7459
75      case 0x12:   // INQUIRY
76         retdata = 40;   // (12)
77         break;
78      case 0x15:   // MODE SELECT (used to set CDDA volume)
79         logerror("SCSIHD: MODE SELECT length %x control %x\n", pCmdBuf[4], pCmdBuf[5]);
80         retdata = 0x18;
81         break;
82      case 0x1a:   // MODE SENSE (6 byte)
83         retdata = 8;
60      case 0x12: // INQUIRY
61         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
62         return SCSILengthFromUINT8( &command[ 4 ] );
8463
85         // check for special Apple ID code
86         if ((pCmdBuf[2]&0x3f) == 0x30)
87         {
88            retdata = 40;
89         }
90         break;
91      case 0x25:   // READ CAPACITY
92         retdata = 8;
93         break;
94      case 0x28:    // READ (10 byte)
95         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
96         our_this->blocks = pCmdBuf[6]<<24 | pCmdBuf[7]<<16 | pCmdBuf[8]<<8 | pCmdBuf[9];
64      case 0x15: // MODE SELECT (used to set CDDA volume)
65         logerror("SCSIHD: MODE SELECT length %x control %x\n", command[4], command[5]);
66         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
67         return SCSILengthFromUINT8( &command[ 4 ] );
9768
69      case 0x1a: // MODE SENSE(6)
70         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
71         return SCSILengthFromUINT8( &command[ 4 ] );
72
73      case 0x25: // READ CAPACITY
74         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
75         return 8;
76
77      case 0x28: // READ(10)
78         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
79         our_this->blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9];
80
9881         logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
9982
100         retdata = our_this->blocks * 512;
101         break;
102      case 0xa8:    // READ (12 byte)
103         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
104         our_this->blocks = pCmdBuf[7]<<8 | pCmdBuf[8];
83         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
84         return our_this->blocks * 512;
10585
86      case 0xa8: // READ(12)
87         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
88         our_this->blocks = SCSILengthFromUINT16( &command[7] );
89
10690         logerror("SCSIHD: READ at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
10791
108         retdata = our_this->blocks * 512;
109         break;
92         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
93         return our_this->blocks * 512;
94
11095      default:
111         logerror("SCSIHD: unknown SCSI command %x!\n", our_this->last_command);
112         break;
96         return SCSIBase( &SCSIClassHARDDISK, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL );
11397   }
114
115   return retdata;
11698}
11799
118void scsihd_read_data(SCSIHd *our_this, int bytes, UINT8 *pData)
100static void scsihd_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
119101{
120102   int i;
103   UINT8 *command;
104   int commandLength;
105   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
106   SCSIGetCommand( scsiInstance, &command, &commandLength );
121107
122   switch (our_this->last_command)
108   switch ( command[0] )
123109   {
124110      case 0x03:   // REQUEST SENSE
125         pData[0] = 0x80;   // valid sense
111         data[0] = 0x80;   // valid sense
126112         for (i = 1; i < 12; i++)
127113         {
128            pData[i] = 0;
114            data[i] = 0;
129115         }
130116         break;
131117
132118      case 0x12:   // INQUIRY
133         i = sizeof( our_this->inquiry_buffer );
134         if( i > bytes )
135         {
136            i = bytes;
137         }
138
139         memcpy( pData, our_this->inquiry_buffer, i );
140
141         if( i < bytes )
142         {
143            memset( pData + i, 0, bytes - i );
144         }
145
119         memset( data, 0, dataLength );
120         data[0] = 0x00; // device is direct-access (e.g. hard disk)
121         data[1] = 0x00; // media is not removable
122         data[2] = 0x05; // device complies with SPC-3 standard
123         data[3] = 0x02; // response data format = SPC-3 standard
124         // Apple HD SC setup utility needs to see this
125         strcpy((char *)&data[8], " SEAGATE");
126         strcpy((char *)&data[16], "          ST225N");
127         strcpy((char *)&data[32], "1.0");
146128         break;
147129
148130      case 0x1a:   // MODE SENSE (6 byte)
149131         // special Apple ID page.  this is a vendor-specific page,
150132         // so unless collisions occur there should be no need
151133         // to change it.
152         if ((our_this->last_packet[2] & 0x3f) == 0x30)
134         if ((command[2] & 0x3f) == 0x30)
153135         {
154            memset(pData, 0, 40);
155            pData[0] = 0x14;
156            strcpy((char *)&pData[14], "APPLE COMPUTER, INC.");
136            memset(data, 0, 40);
137            data[0] = 0x14;
138            strcpy((char *)&data[14], "APPLE COMPUTER, INC.");
157139         }
158140         break;
159141
160      case 0x08:   // READ (6 byte)
161      case 0x28:   // READ (10 byte)
162      case 0xa8:   // READ (12 byte)
142      case 0x08: // READ(6)
143      case 0x28: // READ(10)
144      case 0xa8: // READ(12)
163145         if ((our_this->disk) && (our_this->blocks))
164146         {
165            while (bytes > 0)
147            while (dataLength > 0)
166148            {
167               if (!hard_disk_read(our_this->disk, our_this->lba,  pData))
149               if (!hard_disk_read(our_this->disk, our_this->lba,  data))
168150               {
169151                  logerror("SCSIHD: HD read error!\n");
170152               }
171153               our_this->lba++;
172               our_this->last_lba = our_this->lba;
173154               our_this->blocks--;
174               bytes -= 512;
175               pData += 512;
155               dataLength -= 512;
156               data += 512;
176157            }
177158         }
178159         break;
179160
180161
181      case 0x25:   // READ CAPACITY
162      case 0x25: // READ CAPACITY
182163         {
183164            hard_disk_info *info;
184165            UINT32 temp;
r1215r1216
191172            temp = info->cylinders * info->heads * info->sectors;
192173            temp--;
193174
194            pData[0] = (temp>>24) & 0xff;
195            pData[1] = (temp>>16) & 0xff;
196            pData[2] = (temp>>8) & 0xff;
197            pData[3] = (temp & 0xff);
198            pData[4] = (info->sectorbytes>>24)&0xff;
199            pData[5] = (info->sectorbytes>>16)&0xff;
200            pData[6] = (info->sectorbytes>>8)&0xff;
201            pData[7] = (info->sectorbytes & 0xff);
175            data[0] = (temp>>24) & 0xff;
176            data[1] = (temp>>16) & 0xff;
177            data[2] = (temp>>8) & 0xff;
178            data[3] = (temp & 0xff);
179            data[4] = (info->sectorbytes>>24)&0xff;
180            data[5] = (info->sectorbytes>>16)&0xff;
181            data[6] = (info->sectorbytes>>8)&0xff;
182            data[7] = (info->sectorbytes & 0xff);
202183         }
203184         break;
204185
205186      default:
206         logerror("SCSIHD: readback of data from unknown command %d\n", our_this->last_command);
187         SCSIBase( &SCSIClassHARDDISK, SCSIOP_READ_DATA, scsiInstance, dataLength, data );
207188         break;
208189   }
209190}
210191
211void scsihd_write_data(SCSIHd *our_this, int bytes, UINT8 *pData)
192static void scsihd_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
212193{
213   switch (our_this->last_command)
194   UINT8 *command;
195   int commandLength;
196   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
197   SCSIGetCommand( scsiInstance, &command, &commandLength );
198
199   switch ( command[0] )
214200   {
215      case 0x0a:   // WRITE (6 byte)
201      case 0x0a: // WRITE(6)
216202         if ((our_this->disk) && (our_this->blocks))
217203         {
218            while (bytes > 0)
204            while (dataLength > 0)
219205            {
220               if (!hard_disk_write(our_this->disk, our_this->lba, pData))
206               if (!hard_disk_write(our_this->disk, our_this->lba, data))
221207               {
222208                  logerror("SCSIHD: HD write error!\n");
223209               }
224210               our_this->lba++;
225               our_this->last_lba = our_this->lba;
226211               our_this->blocks--;
227               bytes -= 512;
228               pData += 512;
212               dataLength -= 512;
213               data += 512;
229214            }
230215         }
231216         break;
217
218      default:
219         SCSIBase( &SCSIClassHARDDISK, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data );
220         break;
232221   }
233222}
234223
235int scsihd_dispatch(int operation, void *file, INT64 intparm, UINT8 *ptrparm)
224static void scsihd_alloc_instance( SCSIInstance *scsiInstance, int diskId )
236225{
237   SCSIHd *instance;
238   void **ptrresult;
226   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
239227
228   our_this->lba = 0;
229   our_this->blocks = 0;
230
231   state_save_register_item( "scsihd", diskId, our_this->lba );
232   state_save_register_item( "scsihd", diskId, our_this->blocks );
233
234#ifdef MESS
235   our_this->disk = mess_hd_get_hard_disk_file_by_number( diskId );
236#else
237   our_this->disk = hard_disk_open(get_disk_handle( diskId ));
238
239   if (!our_this->disk)
240   {
241      logerror("SCSIHD: no HD found!\n");
242   }
243#endif
244}
245
246static void scsihd_delete_instance( SCSIInstance *scsiInstance )
247{
248#ifndef MESS
249   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
250
251   if( our_this->disk )
252   {
253      hard_disk_close( our_this->disk );
254   }
255#endif
256}
257
258static void scsihd_get_device( SCSIInstance *scsiInstance, hard_disk_file **disk )
259{
260   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
261   *disk = our_this->disk;
262}
263
264static void scsihd_set_device( SCSIInstance *scsiInstance, hard_disk_file *disk )
265{
266   SCSIHd *our_this = SCSIThis( &SCSIClassHARDDISK, scsiInstance );
267   our_this->disk = disk;
268}
269
270static int scsihd_dispatch(int operation, void *file, INT64 intparm, void *ptrparm)
271{
240272   switch (operation)
241273   {
242274      case SCSIOP_EXEC_COMMAND:
243         return scsihd_exec_command((SCSIHd *)file, ptrparm);
244         break;
275         return scsihd_exec_command( file, ptrparm );
245276
246277      case SCSIOP_READ_DATA:
247         scsihd_read_data((SCSIHd *)file, intparm, ptrparm);
248         break;
278         scsihd_read_data( file, ptrparm, intparm );
279         return 0;
249280
250281      case SCSIOP_WRITE_DATA:
251         scsihd_write_data((SCSIHd *)file, intparm, ptrparm);
252         break;
282         scsihd_write_data( file, ptrparm, intparm );
283         return 0;
253284
254285      case SCSIOP_ALLOC_INSTANCE:
255         instance = (SCSIHd *)malloc_or_die(sizeof(SCSIHd));
286         SCSIBase( &SCSIClassHARDDISK, operation, file, intparm, ptrparm );
287         scsihd_alloc_instance( *((SCSIInstance **) ptrparm), intparm );
288         return 0;
256289
257         instance->lba = 0;
258         instance->blocks = 0;
259
260         memset(instance->inquiry_buffer, 0, sizeof(instance->inquiry_buffer));
261         instance->inquiry_buffer[0] = 0x00; // device is direct-access (e.g. hard disk)
262         instance->inquiry_buffer[1] = 0x00; // media is not removable
263         instance->inquiry_buffer[2] = 0x05; // device complies with SPC-3 standard
264         instance->inquiry_buffer[3] = 0x02; // response data format = SPC-3 standard
265         // Apple HD SC setup utility needs to see this
266         strcpy((char *)&instance->inquiry_buffer[8], " SEAGATE");
267         strcpy((char *)&instance->inquiry_buffer[16], "          ST225N");
268         strcpy((char *)&instance->inquiry_buffer[32], "1.0");
269
270         #ifdef MESS
271         instance->disk = mess_hd_get_hard_disk_file_by_number(intparm);
272         #else
273         instance->disk = hard_disk_open(get_disk_handle(intparm));
274
275         if (!instance->disk)
276         {
277            logerror("SCSIHD: no HD found!\n");
278         }
279         #endif
280
281         ptrresult = file;
282         *ptrresult = instance;
283         break;
284
285290      case SCSIOP_DELETE_INSTANCE:
286         free(file);
291         scsihd_delete_instance( file );
287292         break;
288293
289294      case SCSIOP_GET_DEVICE:
290         ptrresult = (void **)ptrparm;
291         instance = (SCSIHd *)file;
292         *ptrresult = instance->disk;
293         break;
295         scsihd_get_device( file, ptrparm );
296         return 0;
294297
295298      case SCSIOP_SET_DEVICE:
296         instance = (SCSIHd *)file;
297         instance->disk = (hard_disk_file *)ptrparm;
298         break;
299
300
301      case SCSIOP_GET_INQUIRY_BUFFER:
302         ptrresult = (void **)ptrparm;
303         instance = (SCSIHd *)file;
304
305         if( intparm > sizeof( instance->inquiry_buffer ) )
306         {
307            *ptrresult = NULL;
308         }
309         else
310         {
311            *ptrresult = instance->inquiry_buffer;
312         }
313         break;
299         scsihd_set_device( file, ptrparm );
300         return 0;
314301   }
315302
316   return 0;
303   return SCSIBase( &SCSIClassHARDDISK, operation, file, intparm, ptrparm );
317304}
305
306SCSIClass SCSIClassHARDDISK =
307{
308   &SCSIClassDevice,
309   scsihd_dispatch,
310   sizeof( SCSIHd )
311};
src/emu/machine/cr589.h
r0r1216
1#include "scsi.h"
2
3extern SCSIClass SCSIClassCr589;
src/emu/machine/6850acia.c
r1215r1216
134134   if (acia_p->first_reset)
135135   {
136136      acia_p->first_reset = 0;
137     
137
138138      if (acia_p->rts_pin)
139139      {
140140         *acia_p->rts_pin = 1;
r1215r1216
209209   acia_6850 *acia_p = &acia[which];
210210
211211   acia_p->status_read = 1;
212   
212
213213   return acia_p->status;
214214}
215215
src/emu/machine/scsihd.h
r0r1216
1/***************************************************************************
2
3 scsihd.h
4
5***************************************************************************/
6
7#ifndef _SCSIHD_H_
8#define _SCSIHD_H_
9
10#include "machine/scsi.h"
11
12// CD-ROM handler
13extern SCSIClass SCSIClassHARDDISK;
14#define SCSI_DEVICE_HARDDISK &SCSIClassHARDDISK
15
16#endif
src/emu/machine/53c810.c
r1215r1216
66#define DMA_MAX_ICOUNT   512      /* Maximum number of DMA Scripts opcodes to run */
77#define DASM_OPCODES 0
88
9typedef struct
10{
11   void *data;      /* device's "this" pointer */
12   pSCSIDispatch handler;   /* device's handler routine */
13} SCSIDev;
14
15static SCSIDev devices[8];   /* SCSI IDs 0-7 */
9static SCSIInstance *devices[8];   /* SCSI IDs 0-7 */
1610static struct LSI53C810interface *intf;
1711static UINT8 last_id;
1812
r1215r1216
4640   int dma_icount;
4741   int halted;
4842   int carry;
49
50   struct
51   {
52      void *data;      // device's "this" pointer
53      pSCSIDispatch handler;   // device's handler routine
54   } devices[8];
55
5643   UINT32 (* fetch)(UINT32 dsp);
5744   void (* irq_callback)(void);
5845   void (* dma_callback)(UINT32, UINT32, int, int);
r1215r1216
707694   // try to open the devices
708695   for (i = 0; i < interface->scsidevs->devs_present; i++)
709696   {
710      devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler;
711      interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL);
697      SCSIAllocInstance( interface->scsidevs->devices[i].scsiClass, &devices[interface->scsidevs->devices[i].scsiID], interface->scsidevs->devices[i].diskID );
712698   }
713699}
714700
715701void lsi53c810_read_data(int bytes, UINT8 *pData)
716702{
717   if (devices[last_id].handler)
703   if (devices[last_id])
718704   {
719      devices[last_id].handler(SCSIOP_READ_DATA, devices[last_id].data, bytes, pData);
705      SCSIReadData( devices[last_id], pData, bytes);
720706   }
721707   else
722708   {
r1215r1216
726712
727713void lsi53c810_write_data(int bytes, UINT8 *pData)
728714{
729   if (devices[last_id].handler)
715   if (devices[last_id])
730716   {
731      devices[last_id].handler(SCSIOP_WRITE_DATA, devices[last_id].data, bytes, pData);
717      SCSIWriteData( devices[last_id], pData, bytes );
732718   }
733719   else
734720   {
r1215r1216
740726{
741727   void *ret;
742728
743   if (devices[id].handler)
729   if (devices[id])
744730   {
745731      logerror("lsi53c810: fetching dev pointer for SCSI ID %d\n", id);
746      devices[id].handler(SCSIOP_GET_DEVICE, devices[id].data, 0, (UINT8 *)&ret);
732      SCSIGetDevice( devices[id], &ret );
747733
748734      return ret;
749735   }
src/emu/machine/53c810.h
r1215r1216
11#ifndef LSI53C810_H
22#define LSI53C810_H
33
4#include "machine/scsidev.h"
4#include "machine/scsi.h"
55
66struct LSI53C810interface
77{
src/emu/machine/wd33c93.c
r1215r1216
1717
1818#define VERBOSE 0
1919
20typedef struct
21{
22   void *data;      // device's "this" pointer
23   pSCSIDispatch handler;   // device's handler routine
24} SCSIDev;
25
26static SCSIDev devices[8];   // SCSI IDs 0-7
20static SCSIInstance *devices[8];   // SCSI IDs 0-7
2721static struct WD33C93interface *intf;
2822
2923/* wd register names */
r1215r1216
230224{
231225   UINT8   unit = wd33c93_getunit();
232226
233   if ( devices[unit].handler )
227   if ( devices[unit] )
234228   {
235      devices[unit].handler(SCSIOP_READ_DATA, devices[unit].data, bytes, pData);
229      SCSIReadData( devices[unit], pData, bytes );
236230   }
237231   else
238232   {
r1215r1216
339333   UINT8   newstatus;
340334
341335   /* see if we can select that device */
342   if ( devices[unit].handler )
336   if ( devices[unit] )
343337   {
344338      /* device is available - signal selection done */
345339      newstatus = CSR_SELECT;
r1215r1216
375369   UINT8   newstatus;
376370
377371   /* see if we can select that device */
378   if ( devices[unit].handler )
372   if ( devices[unit] )
379373   {
380374      if ( scsi_data.regs[WD_COMMAND_PHASE] < 0x45 )
381375      {
382376         /* device is available */
383377         int xfercount;
378         int phase;
384379
385380         /* do the request */
386         xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.regs[WD_CDB_1]);
381         SCSISetCommand( devices[unit], &scsi_data.regs[WD_CDB_1], 12 );
382         SCSIExecCommand( devices[unit], &xfercount );
383         SCSIGetPhase( devices[unit], &phase );
387384
388385         /* set transfer count */
389386         if ( wd33c93_get_xfer_count() > TEMP_INPUT_LEN )
r1215r1216
392389            wd33c93_set_xfer_count( TEMP_INPUT_LEN );
393390         }
394391
395         scsi_data.read_pending = 1;
392         switch( phase )
393         {
394            case SCSI_PHASE_DATAIN:
395               scsi_data.read_pending = 1;
396               break;
397         }
396398      }
397399
398400      if ( scsi_data.read_pending )
r1215r1216
590592                     {
591593                        UINT8   unit = wd33c93_getunit();
592594                        int      xfercount;
595                        int phase;
593596
594597                        /* Execute the command. Depending on the command, we'll move to data in or out */
595                        xfercount = devices[unit].handler(SCSIOP_EXEC_COMMAND, devices[unit].data, 0, &scsi_data.fifo[0]);
598                        SCSISetCommand( devices[unit], &scsi_data.fifo[0], 12 );
599                        SCSIExecCommand( devices[unit], &xfercount );
600                        SCSIGetPhase( devices[unit], &phase );
596601
597602                        /* reset fifo */
598603                        scsi_data.fifo_pos = 0;
r1215r1216
600605                        /* set the new count */
601606                        wd33c93_set_xfer_count( xfercount );
602607
603                        if ( xfercount == 0 )
608                        switch( phase )
604609                        {
605                           /* move to status phase */
610                        case SCSI_PHASE_STATUS:
606611                           scsi_data.busphase = PHS_STATUS;
612                           break;
613
614                        case SCSI_PHASE_DATAIN:
615                           scsi_data.busphase = PHS_DATA_IN;
616                           scsi_data.read_pending = 1;
617                           break;
618
619                        case SCSI_PHASE_DATAOUT:
620                           scsi_data.busphase = PHS_DATA_OUT;
621                           break;
607622                        }
608                        else
609                        {
610                           /* update bus phase */
611                           if ( scsi_data.fifo[0] == 0x15 || scsi_data.fifo[0] == 0x55 ) /* MODE SELECT */
612                           {
613                              scsi_data.busphase = PHS_DATA_OUT;
614                           }
615                           else
616                           {
617                              scsi_data.busphase = PHS_DATA_IN;
618                              scsi_data.read_pending = 1;
619                           }
620                        }
621623                     }
622624                     break;
623625
r1215r1216
796798   // try to open the devices
797799   for (i = 0; i < interface->scsidevs->devs_present; i++)
798800   {
799      devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler;
800      interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL);
801      SCSIAllocInstance( interface->scsidevs->devices[i].scsiClass, &devices[interface->scsidevs->devices[i].scsiID], interface->scsidevs->devices[i].diskID );
801802   }
802803
803804   /* allocate a timer for commands */
r1215r1216
835836{
836837   UINT8   unit = wd33c93_getunit();
837838
838   if (devices[unit].handler)
839   if (devices[unit])
839840   {
840      devices[unit].handler(SCSIOP_WRITE_DATA, devices[unit].data, bytes, pData);
841      SCSIWriteData( devices[unit], pData, bytes );
841842   }
842843   else
843844   {
r1215r1216
849850{
850851   void *ret;
851852
852   if (devices[id].handler)
853   if (devices[id])
853854   {
854      devices[id].handler(SCSIOP_GET_DEVICE, devices[id].data, 0, (UINT8 *)&ret);
855
855      SCSIGetDevice( devices[id], &ret );
856856      return ret;
857857   }
858858
src/emu/machine/scsidev.c
r0r1216
1/***************************************************************************
2
3 scsidev.c - Base class for scsi devices.
4
5***************************************************************************/
6
7#include "scsidev.h"
8
9typedef struct
10{
11   UINT8 command[16];
12   int commandLength;
13   int phase;
14} SCSIDev;
15
16static int scsidev_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode )
17{
18   UINT8 *command;
19   int commandLength;
20//  SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
21   SCSIGetCommand( scsiInstance, &command, &commandLength );
22
23   switch( command[ 0 ] )
24   {
25      case 0x00: // TEST UNIT READY
26         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
27         return 0;
28
29      default:
30         logerror( "%08x: SCSIDEV unknown command %02x\n", activecpu_get_pc(), command[ 0 ] );
31         return 0;
32   }
33}
34
35static void scsidev_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
36{
37   UINT8 *command;
38   int commandLength;
39//  SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
40   SCSIGetCommand( scsiInstance, &command, &commandLength );
41
42   switch( command[ 0 ] )
43   {
44      default:
45         logerror( "%08x: SCSIDEV unknown read %02x\n", activecpu_get_pc(), command[ 0 ] );
46         break;
47   }
48}
49
50static void scsidev_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
51{
52   UINT8 *command;
53   int commandLength;
54//  SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
55   SCSIGetCommand( scsiInstance, &command, &commandLength );
56
57   switch( command[ 0 ] )
58   {
59      default:
60         logerror( "%08x: SCSIDEV unknown write %02x\n", activecpu_get_pc(), command[ 0 ] );
61         break;
62   }
63}
64
65static void scsidev_set_phase( SCSIInstance *scsiInstance, int phase )
66{
67   SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
68   our_this->phase = phase;
69}
70
71static int scsidev_get_phase( SCSIInstance *scsiInstance )
72{
73   SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
74   return our_this->phase;
75}
76
77static void scsidev_set_command( SCSIInstance *scsiInstance, void *command, int commandLength )
78{
79   SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
80
81   if( commandLength > sizeof( our_this->command ) )
82   {
83      /// TODO: output an error.
84      return;
85   }
86
87   memcpy( our_this->command, command, commandLength );
88   our_this->commandLength = commandLength;
89
90   SCSISetPhase( scsiInstance, SCSI_PHASE_COMMAND );
91}
92
93static int scsidev_get_command( SCSIInstance *scsiInstance, void **command )
94{
95   SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
96   *command = our_this->command;
97   return our_this->commandLength;
98}
99
100static void scsidev_alloc_instance( SCSIInstance *scsiInstance, int diskId )
101{
102   SCSIDev *our_this = SCSIThis( &SCSIClassDevice, scsiInstance );
103
104   state_save_register_item_array( "scsidev", diskId, our_this->command );
105   state_save_register_item( "scsidev", diskId, our_this->commandLength );
106   state_save_register_item( "scsidev", diskId, our_this->phase );
107}
108
109static int scsidev_dispatch( int operation, void *file, INT64 intparm, void *ptrparm )
110{
111   switch( operation )
112   {
113      case SCSIOP_EXEC_COMMAND:
114         return scsidev_exec_command( file, ptrparm );
115
116      case SCSIOP_READ_DATA:
117         scsidev_read_data( file, ptrparm, intparm );
118         break;
119
120      case SCSIOP_WRITE_DATA:
121         scsidev_write_data( file, ptrparm, intparm );
122         break;
123
124      case SCSIOP_SET_PHASE:
125         scsidev_set_phase( file, intparm );
126         return 0;
127
128      case SCSIOP_GET_PHASE:
129         return scsidev_get_phase( file );
130
131      case SCSIOP_SET_COMMAND:
132         scsidev_set_command( file, ptrparm, intparm );
133         return 0;
134
135      case SCSIOP_GET_COMMAND:
136         return scsidev_get_command( file, ptrparm );
137
138      case SCSIOP_ALLOC_INSTANCE:
139         *((SCSIInstance **) ptrparm) = SCSIMalloc( file );
140         scsidev_alloc_instance( *((SCSIInstance **) ptrparm), intparm );
141         return 0;
142
143      case SCSIOP_DELETE_INSTANCE:
144         free( file );
145         return 0;
146   }
147   return 0;
148}
149
150SCSIClass SCSIClassDevice =
151{
152   NULL,
153   scsidev_dispatch,
154   sizeof( SCSIDev )
155};
src/emu/machine/wd33c93.h
r1215r1216
66#ifndef _WD33C93_H_
77#define _WD33C93_H_
88
9#include "machine/scsidev.h"
9#include "machine/scsi.h"
1010
1111struct WD33C93interface
1212{
src/emu/machine/scsidev.h
r1215r1216
11/***************************************************************************
22
3 scsidev.h - Header which defines the interface between SCSI device handlers
4             and SCSI interfaces.
3 scsidev.h
54
65***************************************************************************/
76
87#ifndef _SCSIDEV_H_
98#define _SCSIDEV_H_
109
11#define SCSI_MAX_DEVICES   (16)
10#include "machine/scsi.h"
1211
13typedef int (* pSCSIDispatch)(int operation, void *file, INT64 intparm, UINT8 *ptrparm);
12// base handler
13extern SCSIClass SCSIClassDevice;
1414
15typedef struct scsiconfigitem
16{
17   int scsiID;
18   int diskID;
19   pSCSIDispatch handler;
20} SCSIConfigItem;
21
22typedef struct scsiconfigtable
23{
24   int devs_present;
25   SCSIConfigItem devices[SCSI_MAX_DEVICES];
26} SCSIConfigTable;
27
28// SCSI IDs
29enum
30{
31   SCSI_ID_0 = 0,
32   SCSI_ID_1,
33   SCSI_ID_2,
34   SCSI_ID_3,
35   SCSI_ID_4,
36   SCSI_ID_5,
37   SCSI_ID_6,
38   SCSI_ID_7
39};
40
41// commands accepted by a SCSI device's dispatch handler
42enum
43{
44   SCSIOP_EXEC_COMMAND = 0,   // execute a command packet
45   SCSIOP_READ_DATA,      // data transfer from the device
46   SCSIOP_WRITE_DATA,      // data transfer to the device
47   SCSIOP_ALLOC_INSTANCE,      // allocate an instance of the device
48   SCSIOP_DELETE_INSTANCE,      // delete an instance of the device
49   SCSIOP_GET_DEVICE,      // get the device's internal device (CDROM or HDD pointer)
50   SCSIOP_SET_DEVICE,      // set the device's internal device (CDROM or HDD pointer)
51   SCSIOP_GET_INQUIRY_BUFFER,   // get the device's inquiry buffer
52};
53
54// macros to make config structs cleaner
55#define SCSI_DEVICE_CDROM scsicd_dispatch
56#define SCSI_DEVICE_HARDDISK scsihd_dispatch
57
58
59/*----------- defined in machine/scsicd.c -----------*/
60
61// CD-ROM handler
62int scsicd_dispatch(int operation, void *file, INT64 intparm, UINT8 *ptrparm);
63
64/*----------- defined in machine/scsihd.c -----------*/
65
66// hard disk handler
67int scsihd_dispatch(int operation, void *file, INT64 intparm, UINT8 *ptrparm);
68
6915#endif
70
src/emu/machine/scsicd.c
r1215r1216
44
55***************************************************************************/
66
7#include "driver.h"
7#include "state.h"
88#include "scsidev.h"
99#include "cdrom.h"
1010#include "sound/cdda.h"
r1215r1216
1414
1515typedef struct
1616{
17   UINT32 lba, blocks, last_lba, bytes_per_sector, num_subblocks, cur_subblock, play_err_flag;
18   int last_command, last_retval;
17   UINT32 lba;
18   UINT32 blocks;
19   UINT32 last_lba;
20   UINT32 bytes_per_sector;
21   UINT32 num_subblocks;
22   UINT32 cur_subblock;
23   UINT32 play_err_flag;
1924    cdrom_file *cdrom;
20   UINT8 last_packet[16];
21   UINT8 inquiry_buffer[96];
2225} SCSICd;
2326
24
2527static void phys_frame_to_msf(int phys_frame, int *m, int *s, int *f)
2628{
2729   *m = phys_frame / (60*75);
r1215r1216
3335
3436// scsicd_exec_command
3537//
36// Execute a SCSI command passed in via pCmdBuf.
38// Execute a SCSI command.
3739
38int scsicd_exec_command(SCSICd *our_this, UINT8 *pCmdBuf)
40static int scsicd_exec_command( SCSIInstance *scsiInstance, UINT8 *statusCode )
3941{
42   UINT8 *command;
43   int commandLength;
44   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
45
4046   cdrom_file *cdrom = our_this->cdrom;
41   int retval = 12, trk, temp;
4247   int cddanum;
48   int trk;
4349
44   // remember the last command for the data transfer phase
45   our_this->last_command = pCmdBuf[0];
50   SCSIGetCommand( scsiInstance, &command, &commandLength );
4651
47   // remember the actual command packet too
48   memcpy(our_this->last_packet, pCmdBuf, 16);
52   switch ( command[0] )
53   {
54      case 0x03: // REQUEST SENSE
55         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
56         return SCSILengthFromUINT8( &command[ 4 ] );
4957
50   switch (our_this->last_command)
51   {
52      case 0:      // TEST UNIT READY
53         retval = 0;
54         break;
55      case 3:    // REQUEST SENSE
58      case 0x12: // INQUIRY
5659         logerror("SCSICD: REQUEST SENSE\n");
60         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
61         return SCSILengthFromUINT8( &command[ 4 ] );
5762
58         temp = pCmdBuf[5]<<8 | pCmdBuf[4];
59         if (temp < 18)
60         {
61            retval = temp;
62         }
63         else
64         {
65            retval = 18;
66         }
67         break;
68      case 0x12:   // INQUIRY
69         retval = pCmdBuf[4];
70         break;
71      case 0x15:   // MODE SELECT (6)
72         logerror("SCSICD: MODE SELECT (6) length %x control %x\n", pCmdBuf[4], pCmdBuf[5]);
73         retval = 0x18;
74         break;
75      case 0x1a:   // MODE SENSE
76         retval = 8;
77         break;
78      case 0x1b:   // START/STOP UNIT
63      case 0x15: // MODE SELECT(6)
64         logerror("SCSICD: MODE SELECT(6) length %x control %x\n", command[4], command[5]);
65         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
66         return SCSILengthFromUINT8( &command[ 4 ] );
67
68      case 0x1a: // MODE SENSE(6)
69         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
70         return SCSILengthFromUINT8( &command[ 4 ] );
71
72      case 0x1b: // START STOP UNIT
7973         cddanum = cdda_num_from_cdrom(cdrom);
8074         if (cddanum != -1)
75         {
8176            cdda_stop_audio(cddanum);
82         retval = 0;
83         break;
84      case 0x25:   // READ CD-ROM CAPACITY
85         retval = 8;
86         break;
87      case 0x28:    // READ (10 byte)
88         cddanum = cdda_num_from_cdrom(cdrom);
89         if (cddanum != -1)
90            cdda_stop_audio(cddanum);
91         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
92         our_this->blocks = pCmdBuf[7]<<8 | pCmdBuf[8];
77         }
78         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
79         return 0;
9380
94         retval = our_this->blocks * our_this->bytes_per_sector;
81      case 0x1e: // PREVENT ALLOW MEDIUM REMOVAL
82         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
83         return 0;
9584
85      case 0x25: // READ CAPACITY
86         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
87         return 8;
88
89      case 0x28: // READ(10)
90
91         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
92         our_this->blocks = SCSILengthFromUINT16( &command[7] );
93
94         logerror("SCSICD: READ(10) at LBA %x for %d blocks (%d bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector);
95
9696         if (our_this->num_subblocks > 1)
9797         {
9898            our_this->cur_subblock = our_this->lba % our_this->num_subblocks;
r1215r1216
103103            our_this->cur_subblock = 0;
104104         }
105105
106         /* convert physical frame to CHD */
107         if (cdrom)
106         cddanum = cdda_num_from_cdrom(cdrom);
107         if (cddanum != -1)
108108         {
109            if (cddanum != -1)
110               cdda_stop_audio(cddanum);
109            cdda_stop_audio(cddanum);
111110         }
112111
113         logerror("SCSICD: READ (10) at LBA %x for %d blocks (%d bytes)\n", our_this->lba, our_this->blocks, retval);
114         break;
115      case 0x42:   // READ SUB-CHANNEL
116   //                      logerror("SCSICD: READ SUB-CHANNEL type %d\n", pCmdBuf[3]);
117         retval = 16;
118         break;
119      case 0x43:   // READ TOC
112         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
113         return our_this->blocks * our_this->bytes_per_sector;
114
115      case 0x42: // READ SUB-CHANNEL
116//                      logerror("SCSICD: READ SUB-CHANNEL type %d\n", command[3]);
117         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
118         return SCSILengthFromUINT16( &command[ 7 ] );
119
120      case 0x43: // READ TOC
120121      {
121         int start_trk = pCmdBuf[6];
122         int start_trk = command[6];
122123         int end_trk = cdrom_get_last_track(cdrom);
123         int allocation_length = pCmdBuf[7]<<8 | pCmdBuf[8];
124         int length;
125         int allocation_length = SCSILengthFromUINT16( &command[ 7 ] );
124126
125127         if( start_trk == 0 )
126128         {
r1215r1216
131133            end_trk = start_trk;
132134         }
133135
134         retval = 4 + ( 8 * ( ( end_trk - start_trk ) + 1 ) );
135         if( retval > allocation_length )
136         length = 4 + ( 8 * ( ( end_trk - start_trk ) + 1 ) );
137         if( length > allocation_length )
136138         {
137            retval = allocation_length;
139            length = allocation_length;
138140         }
139         else if( retval < 4 )
141         else if( length < 4 )
140142         {
141            retval = 4;
143            length = 4;
142144         }
143145
144146         cddanum = cdda_num_from_cdrom(cdrom);
145147         if (cddanum != -1)
148         {
146149            cdda_stop_audio(cddanum);
147         break;
150         }
151
152         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
153         return length;
148154      }
149      case 0x45:   // PLAY AUDIO  (10 byte)
150         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
151         our_this->blocks = pCmdBuf[7]<<8 | pCmdBuf[8];
155      case 0x45: // PLAY AUDIO(10)
156         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
157         our_this->blocks = SCSILengthFromUINT16( &command[7] );
152158
153159         // special cases: lba of 0 means MSF of 00:02:00
154160         if (our_this->lba == 0)
r1215r1216
160166            logerror("SCSICD: play audio from current not implemented!\n");
161167         }
162168
163         logerror("SCSICD: PLAY AUDIO (10) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
169         logerror("SCSICD: PLAY AUDIO(10) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
164170
165171         trk = cdrom_get_track(cdrom, our_this->lba);
166172
r1215r1216
176182            logerror("SCSICD: track is NOT audio!\n");
177183            our_this->play_err_flag = 1;
178184         }
179         retval = 0;
180         break;
181      case 0x48:   // PLAY AUDIO TRACK/INDEX
185
186         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
187         return 0;
188
189      case 0x48: // PLAY AUDIO TRACK/INDEX
182190         // be careful: tracks here are zero-based, but the SCSI command
183191         // uses the real CD track number which is 1-based!
184         our_this->lba = cdrom_get_track_start(cdrom, pCmdBuf[4]-1);
185         our_this->blocks = cdrom_get_track_start(cdrom, pCmdBuf[7]-1) - our_this->lba;
186         if (pCmdBuf[4] > pCmdBuf[7])
192         our_this->lba = cdrom_get_track_start(cdrom, command[4]-1);
193         our_this->blocks = cdrom_get_track_start(cdrom, command[7]-1) - our_this->lba;
194         if (command[4] > command[7])
187195         {
188196            our_this->blocks = 0;
189197         }
190198
191         if (pCmdBuf[4] == pCmdBuf[7])
199         if (command[4] == command[7])
192200         {
193            our_this->blocks = cdrom_get_track_start(cdrom, pCmdBuf[4]) - our_this->lba;
201            our_this->blocks = cdrom_get_track_start(cdrom, command[4]) - our_this->lba;
194202         }
195203
196204         if (our_this->blocks && cdrom)
r1215r1216
200208               cdda_start_audio(cddanum, our_this->lba, our_this->blocks);
201209         }
202210
203         logerror("SCSICD: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", pCmdBuf[4], pCmdBuf[5], pCmdBuf[7], pCmdBuf[8], our_this->blocks);
204         retval = 0;
205         break;
206      case 0x4b:   // PAUSE/RESUME
211         logerror("SCSICD: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], our_this->blocks);
212         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
213         return 0;
214
215      case 0x4b: // PAUSE/RESUME
207216         if (cdrom)
208217         {
209218            cddanum = cdda_num_from_cdrom(cdrom);
210219            if (cddanum != -1)
211               cdda_pause_audio(cddanum, (pCmdBuf[8] & 0x01) ^ 0x01);
220               cdda_pause_audio(cddanum, (command[8] & 0x01) ^ 0x01);
212221         }
213222
214         logerror("SCSICD: PAUSE/RESUME: %s\n", pCmdBuf[8]&1 ? "RESUME" : "PAUSE");
215         retval = 0;
216         break;
217      case 0x55:   // MODE SELECT
218         logerror("SCSICD: MODE SELECT length %x control %x\n", pCmdBuf[7]<<8 | pCmdBuf[8], pCmdBuf[1]);
219         retval = 0x18;
220         break;
221      case 0x5a:   // MODE SENSE
222         retval = 0x18;
223         break;
224      case 0xa5:   // PLAY AUDIO  (12 byte)
225         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
226         our_this->blocks = pCmdBuf[6]<<24 | pCmdBuf[7]<<16 | pCmdBuf[8]<<8 | pCmdBuf[9];
223         logerror("SCSICD: PAUSE/RESUME: %s\n", command[8]&1 ? "RESUME" : "PAUSE");
224         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
225         return 0;
227226
227      case 0x55: // MODE SELECT(10)
228         logerror("SCSICD: MODE SELECT length %x control %x\n", command[7]<<8 | command[8], command[1]);
229         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAOUT );
230         return SCSILengthFromUINT16( &command[ 7 ] );
231
232      case 0x5a: // MODE SENSE(10)
233         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
234         return SCSILengthFromUINT16( &command[ 7 ] );
235
236      case 0xa5: // PLAY AUDIO(12)
237         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
238         our_this->blocks = command[6]<<24 | command[7]<<16 | command[8]<<8 | command[9];
239
228240         // special cases: lba of 0 means MSF of 00:02:00
229241         if (our_this->lba == 0)
230242         {
r1215r1216
235247            logerror("SCSICD: play audio from current not implemented!\n");
236248         }
237249
238         logerror("SCSICD: PLAY AUDIO (12) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
250         logerror("SCSICD: PLAY AUDIO(12) at LBA %x for %x blocks\n", our_this->lba, our_this->blocks);
239251
240252         trk = cdrom_get_track(cdrom, our_this->lba);
241253
r1215r1216
251263            logerror("SCSICD: track is NOT audio!\n");
252264            our_this->play_err_flag = 1;
253265         }
254         retval = 0;
255         break;
256      case 0xa8:    // READ (12 byte)
257         cddanum = cdda_num_from_cdrom(cdrom);
258         if (cddanum != -1)
259            cdda_stop_audio(cddanum);
260         our_this->lba = pCmdBuf[2]<<24 | pCmdBuf[3]<<16 | pCmdBuf[4]<<8 | pCmdBuf[5];
261         our_this->blocks = pCmdBuf[7]<<16 | pCmdBuf[8]<<8 | pCmdBuf[9];
266         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
267         return 0;
262268
263         retval = our_this->blocks * our_this->bytes_per_sector;
269      case 0xa8: // READ(12)
270         our_this->lba = command[2]<<24 | command[3]<<16 | command[4]<<8 | command[5];
271         our_this->blocks = command[7]<<16 | command[8]<<8 | command[9];
264272
273         logerror("SCSICD: READ(12) at LBA %x for %x blocks (%x bytes)\n", our_this->lba, our_this->blocks, our_this->blocks * our_this->bytes_per_sector);
274
265275         if (our_this->num_subblocks > 1)
266276         {
267277            our_this->cur_subblock = our_this->lba % our_this->num_subblocks;
r1215r1216
272282            our_this->cur_subblock = 0;
273283         }
274284
275         /* convert physical frame to CHD */
276         if (cdrom)
285         cddanum = cdda_num_from_cdrom(cdrom);
286         if (cddanum != -1)
277287         {
278288            cdda_stop_audio(cddanum);
279289         }
280290
281         logerror("SCSICD: READ (12) at LBA %x for %x blocks (%x bytes)\n", our_this->lba, our_this->blocks, retval);
282         break;
283      case 0xbb:   // SET CD SPEED
284         logerror("SCSICD: SET CD SPEED to %d kbytes/sec.\n", pCmdBuf[2]<<8 | pCmdBuf[3]);
285         break;
291         SCSISetPhase( scsiInstance, SCSI_PHASE_DATAIN );
292         return our_this->blocks * our_this->bytes_per_sector;
293
294      case 0xbb: // SET CD SPEED
295         logerror("SCSICD: SET CD SPEED to %d kbytes/sec.\n", command[2]<<8 | command[3]);
296         SCSISetPhase( scsiInstance, SCSI_PHASE_STATUS );
297         return 0;
298
286299      default:
287         logerror("SCSICD: unknown SCSI command %x!\n", our_this->last_command);
288         break;
300         return SCSIBase( &SCSIClassCDROM, SCSIOP_EXEC_COMMAND, scsiInstance, 0, NULL );
289301   }
290
291   our_this->last_retval = retval;
292   return retval;
293302}
294303
295304// scsicd_read_data
296305//
297306// Read data from the device resulting from the execution of a command
298307
299void scsicd_read_data(SCSICd *our_this, int bytes, UINT8 *pData)
308static void scsicd_read_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
300309{
310   UINT8 *command;
311   int commandLength;
312   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
313
301314   int i;
302315   UINT32 last_phys_frame;
303   UINT8 *fifo = our_this->last_packet;
304316   cdrom_file *cdrom = our_this->cdrom;
305317   UINT32 temp;
306318   UINT8 tmp_buffer[2048];
307319   int cddanum;
308320
309   switch (our_this->last_command)
321   SCSIGetCommand( scsiInstance, &command, &commandLength );
322
323   switch ( command[0] )
310324   {
311      case 0x03:   // REQUEST SENSE
325      case 0x03: // REQUEST SENSE
312326         logerror("SCSICD: Reading REQUEST SENSE data\n");
313327
314         pData[0] = 0x71;   // deferred error
328         memset( data, 0, dataLength );
315329
316         if (our_this->last_retval == -1)
317         {
318            our_this->last_retval = 16;
319         }
330         data[0] = 0x71;   // deferred error
320331
321         for (i = 1; i < our_this->last_retval; i++)
322         {
323            pData[i] = 0;
324         }
325
326332         cddanum = cdda_num_from_cdrom(cdrom);
327333         if (cddanum != -1 && cdda_audio_active(cddanum))
328334         {
329            pData[12] = 0x00;
330            pData[13] = 0x11;   // AUDIO PLAY OPERATION IN PROGRESS
335            data[12] = 0x00;
336            data[13] = 0x11;   // AUDIO PLAY OPERATION IN PROGRESS
331337         }
332338         else if (our_this->play_err_flag)
333339         {
334340            our_this->play_err_flag = 0;
335            pData[12] = 0x64;   // ILLEGAL MODE FOR THIS TRACK
336            pData[13] = 0x00;
341            data[12] = 0x64;   // ILLEGAL MODE FOR THIS TRACK
342            data[13] = 0x00;
337343         }
338344         // (else 00/00 means no error to report)
339345         break;
340346
341      case 0x12:   // INQUIRY
342         i = sizeof( our_this->inquiry_buffer );
343         if( i > bytes )
344         {
345            i = bytes;
346         }
347
348         memcpy( pData, our_this->inquiry_buffer, i );
349
350         if( i < bytes )
351         {
352            memset( pData + i, 0, bytes - i );
353         }
354
347      case 0x12: // INQUIRY
348         memset( data, 0, dataLength );
349         data[0] = 0x05; // device is present, device is CD/DVD (MMC-3)
350         data[1] = 0x80; // media is removable
351         data[2] = 0x05; // device complies with SPC-3 standard
352         data[3] = 0x02; // response data format = SPC-3 standard
353         // some Konami games freak out if this isn't "Sony", so we'll lie
354         // this is the actual drive on my Nagano '98 board
355         strcpy((char *)&data[8], "Sony");
356         strcpy((char *)&data[16], "CDU-76S");
357         strcpy((char *)&data[32], "1.0");
355358         break;
356359
357      case 0x25:   // READ CAPACITY
360      case 0x25: // READ CAPACITY
358361         logerror("SCSICD: READ CAPACITY\n");
359362
360363         temp = cdrom_get_track_start(cdrom, 0xaa);
361364         temp--;   // return the last used block on the disc
362365
363         pData[0] = (temp>>24) & 0xff;
364         pData[1] = (temp>>16) & 0xff;
365         pData[2] = (temp>>8) & 0xff;
366         pData[3] = (temp & 0xff);
367         pData[4] = 0;
368         pData[5] = 0;
369         pData[6] = (our_this->bytes_per_sector>>8)&0xff;
370         pData[7] = (our_this->bytes_per_sector & 0xff);
366         data[0] = (temp>>24) & 0xff;
367         data[1] = (temp>>16) & 0xff;
368         data[2] = (temp>>8) & 0xff;
369         data[3] = (temp & 0xff);
370         data[4] = 0;
371         data[5] = 0;
372         data[6] = (our_this->bytes_per_sector>>8)&0xff;
373         data[7] = (our_this->bytes_per_sector & 0xff);
371374         break;
372375
373      case 0x28:   // READ (10 byte)
374      case 0xa8:   // READ (12 byte)
375         logerror("SCSICD: read %x bytes, \n", bytes);
376      case 0x28: // READ(10)
377      case 0xa8: // READ(12)
378         logerror("SCSICD: read %x dataLength, \n", dataLength);
376379         if ((our_this->cdrom) && (our_this->blocks))
377380         {
378            while (bytes > 0)
381            while (dataLength > 0)
379382            {
380383               if (!cdrom_read_data(our_this->cdrom, our_this->lba, tmp_buffer, CD_TRACK_MODE1))
381384               {
r1215r1216
384387
385388               logerror("True LBA: %d, buffer half: %d\n", our_this->lba, our_this->cur_subblock * our_this->bytes_per_sector);
386389
387               memcpy(pData, &tmp_buffer[our_this->cur_subblock * our_this->bytes_per_sector], our_this->bytes_per_sector);
390               memcpy(data, &tmp_buffer[our_this->cur_subblock * our_this->bytes_per_sector], our_this->bytes_per_sector);
388391
389392               our_this->cur_subblock++;
390393               if (our_this->cur_subblock >= our_this->num_subblocks)
r1215r1216
396399               }
397400
398401               our_this->last_lba = our_this->lba;
399               bytes -= our_this->bytes_per_sector;
400               pData += our_this->bytes_per_sector;
402               dataLength -= our_this->bytes_per_sector;
403               data += our_this->bytes_per_sector;
401404            }
402405         }
403406         break;
404407
405      case 0x42:   // READ SUB-CHANNEL
406         switch (fifo[3])
408      case 0x42: // READ SUB-CHANNEL
409         switch (command[3])
407410         {
408411            case 1:   // return current position
409412            {
r1215r1216
415418                  return;
416419               }
417420
418               logerror("SCSICD: READ SUB-CHANNEL Time = %x, SUBQ = %x\n", fifo[1], fifo[2]);
421               logerror("SCSICD: READ SUB-CHANNEL Time = %x, SUBQ = %x\n", command[1], command[2]);
419422
420               msf = fifo[1] & 0x2;
423               msf = command[1] & 0x2;
421424
422425               cddanum = cdda_num_from_cdrom(cdrom);
423426               audio_active = cddanum != -1 && cdda_audio_active(cddanum);
r1215r1216
425428               {
426429                  if (cdda_audio_paused(cddanum))
427430                  {
428                     pData[1] = 0x12;      // audio is paused
431                     data[1] = 0x12;      // audio is paused
429432                  }
430433                  else
431434                  {
432                     pData[1] = 0x11;      // audio in progress
435                     data[1] = 0x11;      // audio in progress
433436                  }
434437               }
435438               else
436439               {
437440                  if (cddanum != -1 && cdda_audio_ended(cddanum))
438441                  {
439                     pData[1] = 0x13;   // ended successfully
442                     data[1] = 0x13;   // ended successfully
440443                  }
441444                  else
442445                  {
443//                          pData[1] = 0x14;    // stopped due to error
444                     pData[1] = 0x15;   // No current audio status to return
446//                          data[1] = 0x14;    // stopped due to error
447                     data[1] = 0x15;   // No current audio status to return
445448                  }
446449               }
447450
r1215r1216
455458                  our_this->last_lba = 0;
456459               }
457460
458               pData[2] = 0;
459               pData[3] = 12;      // data length
460               pData[4] = 0x01;   // sub-channel format code
461               pData[5] = 0x10 | (audio_active ? 0 : 4);
462               pData[6] = cdrom_get_track(cdrom, our_this->last_lba) + 1;   // track
463               pData[7] = 0;   // index
461               data[2] = 0;
462               data[3] = 12;      // data length
463               data[4] = 0x01;   // sub-channel format code
464               data[5] = 0x10 | (audio_active ? 0 : 4);
465               data[6] = cdrom_get_track(cdrom, our_this->last_lba) + 1;   // track
466               data[7] = 0;   // index
464467
465468               last_phys_frame = our_this->last_lba;
466469
r1215r1216
468471               {
469472                  int m,s,f;
470473                  phys_frame_to_msf(last_phys_frame, &m, &s, &f);
471                  pData[8] = 0;
472                  pData[9] = m;
473                  pData[10] = s;
474                  pData[11] = f;
474                  data[8] = 0;
475                  data[9] = m;
476                  data[10] = s;
477                  data[11] = f;
475478               }
476479               else
477480               {
478                  pData[8] = last_phys_frame>>24;
479                  pData[9] = (last_phys_frame>>16)&0xff;
480                  pData[10] = (last_phys_frame>>8)&0xff;
481                  pData[11] = last_phys_frame&0xff;
481                  data[8] = last_phys_frame>>24;
482                  data[9] = (last_phys_frame>>16)&0xff;
483                  data[10] = (last_phys_frame>>8)&0xff;
484                  data[11] = last_phys_frame&0xff;
482485               }
483486
484               last_phys_frame -= cdrom_get_track_start(cdrom, pData[6] - 1);
487               last_phys_frame -= cdrom_get_track_start(cdrom, data[6] - 1);
485488
486489               if (msf)
487490               {
488491                  int m,s,f;
489492                  phys_frame_to_msf(last_phys_frame, &m, &s, &f);
490                  pData[12] = 0;
491                  pData[13] = m;
492                  pData[14] = s;
493                  pData[15] = f;
493                  data[12] = 0;
494                  data[13] = m;
495                  data[14] = s;
496                  data[15] = f;
494497               }
495498               else
496499               {
497                  pData[12] = last_phys_frame>>24;
498                  pData[13] = (last_phys_frame>>16)&0xff;
499                  pData[14] = (last_phys_frame>>8)&0xff;
500                  pData[15] = last_phys_frame&0xff;
500                  data[12] = last_phys_frame>>24;
501                  data[13] = (last_phys_frame>>16)&0xff;
502                  data[14] = (last_phys_frame>>8)&0xff;
503                  data[15] = last_phys_frame&0xff;
501504               }
502505               break;
503506            }
504507            default:
505               logerror("SCSICD: Unknown subchannel type %d requested\n", fifo[3]);
508               logerror("SCSICD: Unknown subchannel type %d requested\n", command[3]);
506509         }
507510         break;
508511
509      case 0x43:   // READ TOC
512      case 0x43: // READ TOC
510513         /*
511514                Track numbers are problematic here: 0 = lead-in, 0xaa = lead-out.
512515                That makes sense in terms of how real-world CDs are referred to, but
513516                our internal routines for tracks use "0" as track 1.  That probably
514517                should be fixed...
515518            */
516         logerror("SCSICD: READ TOC, format = %d time=%d\n", fifo[2]&0xf,(fifo[1]>>1)&1);
517         switch (fifo[2] & 0x0f)
519         logerror("SCSICD: READ TOC, format = %d time=%d\n", command[2]&0xf,(command[1]>>1)&1);
520         switch (command[2] & 0x0f)
518521         {
519522            case 0:      // normal
520523               {
r1215r1216
525528                  int dptr;
526529                  UINT32 tstart;
527530
528                  start_trk = fifo[6];
531                  start_trk = command[6];
529532                  if( start_trk == 0 )
530533                  {
531534                     start_trk = 1;
r1215r1216
537540                  // the returned TOC DATA LENGTH must be the full amount,
538541                  // regardless of how much we're able to pass back due to in_len
539542                  dptr = 0;
540                  pData[dptr++] = (len>>8) & 0xff;
541                  pData[dptr++] = (len & 0xff);
542                  pData[dptr++] = 1;
543                  pData[dptr++] = end_trk;
543                  data[dptr++] = (len>>8) & 0xff;
544                  data[dptr++] = (len & 0xff);
545                  data[dptr++] = 1;
546                  data[dptr++] = end_trk;
544547
545548                  if( start_trk == 0xaa )
546549                  {
547550                     end_trk = 0xaa;
548551                  }
549552
550                  in_len = fifo[7]<<8 | fifo[8];
553                  in_len = command[7]<<8 | command[8];
551554
552555                  for (i = start_trk; i <= end_trk; i++)
553556                  {
r1215r1216
562565                        break;
563566                     }
564567
565                     pData[dptr++] = 0;
566                     pData[dptr++] = cdrom_get_adr_control(cdrom, cdrom_track);
567                     pData[dptr++] = i;
568                     pData[dptr++] = 0;
568                     data[dptr++] = 0;
569                     data[dptr++] = cdrom_get_adr_control(cdrom, cdrom_track);
570                     data[dptr++] = i;
571                     data[dptr++] = 0;
569572
570573                     tstart = cdrom_get_track_start(cdrom, cdrom_track);
571                     if ((fifo[1]&2)>>1)
574                     if ((command[1]&2)>>1)
572575                        tstart = lba_to_msf(tstart);
573                     pData[dptr++] = (tstart>>24) & 0xff;
574                     pData[dptr++] = (tstart>>16) & 0xff;
575                     pData[dptr++] = (tstart>>8) & 0xff;
576                     pData[dptr++] = (tstart & 0xff);
576                     data[dptr++] = (tstart>>24) & 0xff;
577                     data[dptr++] = (tstart>>16) & 0xff;
578                     data[dptr++] = (tstart>>8) & 0xff;
579                     data[dptr++] = (tstart & 0xff);
577580                  }
578581               }
579582               break;
580583            default:
581               logerror("SCSICD: Unhandled READ TOC format %d\n", fifo[2]&0xf);
584               logerror("SCSICD: Unhandled READ TOC format %d\n", command[2]&0xf);
582585               break;
583586         }
584587         break;
585588
586      case 0x48:   // PLAY AUDIO TRACK/INDEX
587         break;
589      case 0x1a: // MODE SENSE(6)
590      case 0x5a: // MODE SENSE(10)
591         logerror("SCSICD: MODE SENSE page code = %x, PC = %x\n", command[2] & 0x3f, (command[2]&0xc0)>>6);
588592
589      case 0x5a:   // MODE SENSE
590         logerror("SCSICD: MODE SENSE page code = %x, PC = %x\n", fifo[2] & 0x3f, (fifo[2]&0xc0)>>6);
591
592         switch (fifo[2] & 0x3f)
593         switch (command[2] & 0x3f)
593594         {
594595            case 0xe:   // CD Audio control page
595               pData[0] = 0x8e;   // page E, parameter is savable
596               pData[1] = 0x0e;   // page length
597               pData[2] = 0x04;   // IMMED = 1, SOTC = 0
598               pData[3] = pData[4] = pData[5] = pData[6] = pData[7] = 0; // reserved
596               data[0] = 0x8e;   // page E, parameter is savable
597               data[1] = 0x0e;   // page length
598               data[2] = 0x04;   // IMMED = 1, SOTC = 0
599               data[3] = data[4] = data[5] = data[6] = data[7] = 0; // reserved
599600
600601               // connect each audio channel to 1 output port
601               pData[8] = 1;
602               pData[10] = 2;
603               pData[12] = 4;
604               pData[14] = 8;
602               data[8] = 1;
603               data[10] = 2;
604               data[12] = 4;
605               data[14] = 8;
605606
606607               // indicate max volume
607               pData[9] = pData[11] = pData[13] = pData[15] = 0xff;
608               data[9] = data[11] = data[13] = data[15] = 0xff;
608609               break;
609610
610611            default:
611               logerror("SCSICD: MODE SENSE unknown page %x\n", fifo[2] & 0x3f);
612               logerror("SCSICD: MODE SENSE unknown page %x\n", command[2] & 0x3f);
612613               break;
613614         }
614615         break;
616
617      default:
618         SCSIBase( &SCSIClassCDROM, SCSIOP_READ_DATA, scsiInstance, dataLength, data );
619         break;
615620   }
616621}
617622
r1215r1216
619624//
620625// Write data to the CD-ROM device as part of the execution of a command
621626
622void scsicd_write_data(SCSICd *our_this, int bytes, UINT8 *pData)
627static void scsicd_write_data( SCSIInstance *scsiInstance, UINT8 *data, int dataLength )
623628{
624   switch (our_this->last_command)
629   UINT8 *command;
630   int commandLength;
631   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
632   SCSIGetCommand( scsiInstance, &command, &commandLength );
633
634   switch (command[ 0 ])
625635   {
626      case 0x15:   // MODE SELECT (6)
627      case 0x55:   // MODE SELECT
628         logerror("SCSICD: MODE SELECT page %x\n", pData[0] & 0x3f);
636      case 0x15: // MODE SELECT(6)
637      case 0x55: // MODE SELECT(10)
638         logerror("SCSICD: MODE SELECT page %x\n", data[0] & 0x3f);
629639
630         switch (pData[0] & 0x3f)
640         switch (data[0] & 0x3f)
631641         {
632642            case 0x0:   // vendor-specific
633643               // check for SGI extension to force 512-byte blocks
634               if ((pData[3] == 8) && (pData[10] == 2))
644               if ((data[3] == 8) && (data[10] == 2))
635645               {
636646                  logerror("SCSICD: Experimental SGI 512-byte block extension enabled\n");
637647
r1215r1216
645655               break;
646656
647657            case 0xe:   // audio page
648               logerror("Ch 0 route: %x vol: %x\n", pData[8], pData[9]);
649               logerror("Ch 1 route: %x vol: %x\n", pData[10], pData[11]);
650               logerror("Ch 2 route: %x vol: %x\n", pData[12], pData[13]);
651               logerror("Ch 3 route: %x vol: %x\n", pData[14], pData[15]);
658               logerror("Ch 0 route: %x vol: %x\n", data[8], data[9]);
659               logerror("Ch 1 route: %x vol: %x\n", data[10], data[11]);
660               logerror("Ch 2 route: %x vol: %x\n", data[12], data[13]);
661               logerror("Ch 3 route: %x vol: %x\n", data[14], data[15]);
652662               break;
653663         }
654664         break;
665
666      default:
667         SCSIBase( &SCSIClassCDROM, SCSIOP_WRITE_DATA, scsiInstance, dataLength, data );
668         break;
655669   }
656670}
657671
658int scsicd_dispatch(int operation, void *file, INT64 intparm, UINT8 *ptrparm)
672static void scsicd_alloc_instance( SCSIInstance *scsiInstance, int diskId )
659673{
660   SCSICd *instance;
661   void **ptrresult;
674   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
662675
676   our_this->lba = 0;
677   our_this->blocks = 0;
678   our_this->last_lba = 0;
679   our_this->bytes_per_sector = 2048;
680   our_this->num_subblocks = 1;
681   our_this->cur_subblock = 0;
682   our_this->play_err_flag = 0;
683
684   state_save_register_item( "scsicd", diskId, our_this->lba );
685   state_save_register_item( "scsicd", diskId, our_this->blocks );
686   state_save_register_item( "scsicd", diskId, our_this->last_lba );
687   state_save_register_item( "scsicd", diskId, our_this->bytes_per_sector );
688   state_save_register_item( "scsicd", diskId, our_this->num_subblocks );
689   state_save_register_item( "scsicd", diskId, our_this->cur_subblock );
690   state_save_register_item( "scsicd", diskId, our_this->play_err_flag );
691
692#ifdef MESS
693   our_this->cdrom = mess_cd_get_cdrom_file_by_number( diskId );
694#else
695   our_this->cdrom = cdrom_open(get_disk_handle( diskId ));
696
697   if (!our_this->cdrom)
698   {
699      logerror("SCSICD: no CD found!\n");
700   }
701#endif
702}
703
704static void scsicd_delete_instance( SCSIInstance *scsiInstance )
705{
706#ifndef MESS
707   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
708   if( our_this->cdrom )
709   {
710      cdrom_close( our_this->cdrom );
711   }
712#endif
713}
714
715static void scsicd_get_device( SCSIInstance *scsiInstance, cdrom_file **cdrom )
716{
717   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
718   *cdrom = our_this->cdrom;
719}
720
721static void scsicd_set_device( SCSIInstance *scsiInstance, cdrom_file *cdrom )
722{
723   SCSICd *our_this = SCSIThis( &SCSIClassCDROM, scsiInstance );
724   our_this->cdrom = cdrom;
725}
726
727static int scsicd_dispatch(int operation, void *file, INT64 intparm, void *ptrparm)
728{
663729   switch (operation)
664730   {
665731      case SCSIOP_EXEC_COMMAND:
666         return scsicd_exec_command((SCSICd *)file, ptrparm);
667         break;
732         return scsicd_exec_command( file, ptrparm );
668733
669734      case SCSIOP_READ_DATA:
670         scsicd_read_data((SCSICd *)file, intparm, ptrparm);
671         break;
735         scsicd_read_data( file, ptrparm, intparm );
736         return 0;
672737
673738      case SCSIOP_WRITE_DATA:
674         scsicd_write_data((SCSICd *)file, intparm, ptrparm);
675         break;
739         scsicd_write_data( file, ptrparm, intparm );
740         return 0;
676741
677742      case SCSIOP_ALLOC_INSTANCE:
678         instance = (SCSICd *)malloc_or_die(sizeof(SCSICd));
743         SCSIBase( &SCSIClassCDROM, operation, file, intparm, ptrparm );
744         scsicd_alloc_instance( *((SCSIInstance **) ptrparm), intparm );
745         return 0;
679746
680         instance->lba = 0;
681         instance->blocks = 0;
682         instance->bytes_per_sector = 2048;
683         instance->num_subblocks = 1;
684          instance->cur_subblock = 0;
685         instance->play_err_flag = 0;
686
687         memset(instance->inquiry_buffer, 0, sizeof(instance->inquiry_buffer));
688         instance->inquiry_buffer[0] = 0x05; // device is present, device is CD/DVD (MMC-3)
689         instance->inquiry_buffer[1] = 0x80; // media is removable
690         instance->inquiry_buffer[2] = 0x05; // device complies with SPC-3 standard
691         instance->inquiry_buffer[3] = 0x02; // response data format = SPC-3 standard
692         // some Konami games freak out if this isn't "Sony", so we'll lie
693         // this is the actual drive on my Nagano '98 board
694         strcpy((char *)&instance->inquiry_buffer[8], "Sony");
695         strcpy((char *)&instance->inquiry_buffer[16], "CDU-76S");
696         strcpy((char *)&instance->inquiry_buffer[32], "1.0");
697
698         #ifdef MESS
699         instance->cdrom = mess_cd_get_cdrom_file_by_number(intparm);
700         #else
701         instance->cdrom = cdrom_open(get_disk_handle(intparm));
702
703         if (!instance->cdrom)
704         {
705            logerror("SCSICD: no CD found!\n");
706         }
707         #endif
708
709         ptrresult = file;
710         *ptrresult = instance;
711         break;
712
713747      case SCSIOP_DELETE_INSTANCE:
714         instance = (SCSICd *)file;
715         if( instance->cdrom )
716         {
717         #ifndef MESS
718            cdrom_close(instance->cdrom);
719         #endif
720            instance->cdrom = (cdrom_file *)NULL;
721         }
722         free(file);
748         scsicd_delete_instance( file );
723749         break;
724750
725751      case SCSIOP_GET_DEVICE:
726         ptrresult = (void **)ptrparm;
727         instance = (SCSICd *)file;
728         *ptrresult = instance->cdrom;
729         break;
752         scsicd_get_device( file, ptrparm );
753         return 0;
730754
731755      case SCSIOP_SET_DEVICE:
732         instance = (SCSICd *)file;
733         instance->cdrom = (cdrom_file *)ptrparm;
734         break;
735
736      case SCSIOP_GET_INQUIRY_BUFFER:
737         ptrresult = (void **)ptrparm;
738         instance = (SCSICd *)file;
739
740         if( intparm > sizeof( instance->inquiry_buffer ) )
741         {
742            *ptrresult = NULL;
743         }
744         else
745         {
746            *ptrresult = instance->inquiry_buffer;
747         }
748         break;
756         scsicd_set_device( file, ptrparm );
757         return 0;
749758   }
750759
751   return 0;
760   return SCSIBase( &SCSIClassCDROM, operation, file, intparm, ptrparm );
752761}
762
763SCSIClass SCSIClassCDROM =
764{
765   &SCSIClassDevice,
766   scsicd_dispatch,
767   sizeof( SCSICd )
768};
src/emu/machine/scsicd.h
r0r1216
1/***************************************************************************
2
3 scsicd.h
4
5***************************************************************************/
6
7#ifndef _SCSICD_H_
8#define _SCSICD_H_
9
10#include "machine/scsi.h"
11
12// CD-ROM handler
13extern SCSIClass SCSIClassCDROM;
14#define SCSI_DEVICE_CDROM &SCSIClassCDROM
15
16#endif
17
src/emu/machine/am53cf96.c
r1215r1216
1515static UINT8 scsi_regs[32], fifo[16], fptr = 0, xfer_state, last_id;
1616static struct AM53CF96interface *intf;
1717
18typedef struct
19{
20   void *data;      // device's "this" pointer
21   pSCSIDispatch handler;   // device's handler routine
22} SCSIDev;
18static SCSIInstance *devices[8];   // SCSI IDs 0-7
2319
24static SCSIDev devices[8];   // SCSI IDs 0-7
25
2620// 53CF96 register set
2721enum
2822{
r1215r1216
147141            scsi_regs[REG_IRQSTATE] = 8;   // indicate success
148142            xfer_state = 0;
149143            break;
144         case 2: // reset device
145            scsi_regs[REG_IRQSTATE] = 8;   // indicate success
146
147            logerror("53cf96: reset  target ID = %d (PC = %x)\n", last_id, activecpu_get_pc());
148            if (devices[last_id])
149            {
150               SCSIReset( devices[last_id] );
151            }
152            else
153            {
154               logerror("53cf96: reset request for unknown device SCSI ID %d\n", last_id);
155            }
156
157            xfer_state = 0;
158            break;
150159         case 3:   // reset SCSI bus
151160            scsi_regs[REG_INTSTATE] = 4;   // command sent OK
152161            xfer_state = 0;
r1215r1216
164173            }
165174
166175            logerror("53cf96: command %x exec.  target ID = %d (PC = %x)\n", fifo[1], last_id, activecpu_get_pc());
167            if (devices[last_id].handler)
176            if (devices[last_id])
168177            {
169               devices[last_id].handler(SCSIOP_EXEC_COMMAND, devices[last_id].data, 0, &fifo[1]);
178               int length;
179
180               SCSISetCommand( devices[last_id], &fifo[1], 12 );
181               SCSIExecCommand( devices[last_id], &length );
170182            }
171183            else
172184            {
r1215r1216
183195            mame_timer_set( MAME_TIME_IN_HZ( 16384 ), 0, am53cf96_irq );
184196            scsi_regs[REG_INTSTATE] = 6;   // command sent OK
185197            break;
198         default:
199            printf( "unsupported command %02x\n", val );
200            break;
186201      }
187202   }
188203
r1215r1216
206221   // try to open the devices
207222   for (i = 0; i < interface->scsidevs->devs_present; i++)
208223   {
209      devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler;
210      interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL);
224      SCSIAllocInstance( interface->scsidevs->devices[i].scsiClass, &devices[interface->scsidevs->devices[i].scsiID], interface->scsidevs->devices[i].diskID );
211225   }
212226
213227   state_save_register_global_array(scsi_regs);
r1215r1216
222236{
223237   scsi_regs[REG_STATUS] |= 0x10;   // indicate DMA finished
224238
225   if (devices[last_id].handler)
239   if (devices[last_id])
226240   {
227      devices[last_id].handler(SCSIOP_READ_DATA, devices[last_id].data, bytes, pData);
241      SCSIReadData( devices[last_id], pData, bytes );
228242   }
229243   else
230244   {
r1215r1216
239253
240254   scsi_regs[REG_STATUS] |= 0x10;   // indicate DMA finished
241255
242   if (devices[last_id].handler)
256   if (devices[last_id])
243257   {
244      devices[last_id].handler(SCSIOP_WRITE_DATA, devices[last_id].data, bytes, pData);
258      SCSIWriteData( devices[last_id], pData, bytes );
245259   }
246260   else
247261   {
r1215r1216
254268{
255269   void *ret;
256270
257   if (devices[id].handler)
271   if (devices[id])
258272   {
259273      logerror("53cf96: fetching dev pointer for SCSI ID %d\n", id);
260      devices[id].handler(SCSIOP_GET_DEVICE, devices[id].data, 0, (UINT8 *)&ret);
261
274      SCSIGetDevice( devices[id], &ret );
262275      return ret;
263276   }
264277
src/emu/machine/scsi.c
r0r1216
1#include "scsi.h"
2
3void SCSIAllocInstance( SCSIClass *scsiClass, SCSIInstance **instance, int diskId )
4{
5   scsiClass->dispatch( SCSIOP_ALLOC_INSTANCE, scsiClass, diskId, instance );
6}
7
8void SCSIDeleteInstance( SCSIInstance *instance )
9{
10   instance->scsiClass->dispatch( SCSIOP_DELETE_INSTANCE, instance, 0, NULL );
11}
12
13void SCSISetDevice( SCSIInstance *instance, void *device )
14{
15   instance->scsiClass->dispatch( SCSIOP_SET_DEVICE, instance, 0, device );
16}
17
18void SCSIGetDevice( SCSIInstance *instance, void **device )
19{
20   instance->scsiClass->dispatch( SCSIOP_GET_DEVICE, instance, 0, device );
21}
22
23void SCSIReset( SCSIInstance *instance )
24{
25   instance->scsiClass->dispatch( SCSIOP_RESET_DEVICE, instance, 0, NULL );
26}
27
28void SCSIExecCommand( SCSIInstance *instance, int *resultLength )
29{
30   *resultLength = instance->scsiClass->dispatch( SCSIOP_EXEC_COMMAND, instance, 0, NULL );
31}
32
33void SCSISetCommand( SCSIInstance *instance, UINT8 *command, int commandLength )
34{
35   instance->scsiClass->dispatch( SCSIOP_SET_COMMAND, instance, commandLength, command );
36}
37
38void SCSIGetCommand( SCSIInstance *instance, UINT8 **command, int *commandLength )
39{
40   *commandLength = instance->scsiClass->dispatch( SCSIOP_GET_COMMAND, instance, 0, command );
41}
42
43void SCSIWriteData( SCSIInstance *instance, void *data, int dataLength )
44{
45   instance->scsiClass->dispatch( SCSIOP_WRITE_DATA, instance, dataLength, data );
46}
47
48void SCSIReadData( SCSIInstance *instance, void *data, int dataLength )
49{
50   instance->scsiClass->dispatch( SCSIOP_READ_DATA, instance, dataLength, data );
51}
52
53void SCSISetPhase( SCSIInstance *instance, int phase )
54{
55   instance->scsiClass->dispatch( SCSIOP_SET_PHASE, instance, phase, NULL );
56}
57
58void SCSIGetPhase( SCSIInstance *instance, int *phase )
59{
60   *phase = instance->scsiClass->dispatch( SCSIOP_GET_PHASE, instance, 0, NULL );
61}
62
63int SCSIBase( SCSIClass *scsiClass, int operation, void *file, INT64 intparm, UINT8 *ptrparm )
64{
65   return scsiClass->baseClass->dispatch( operation, file, intparm, ptrparm );
66}
67
68SCSIInstance *SCSIMalloc( SCSIClass *scsiClass )
69{
70   SCSIInstance *scsiInstance = (SCSIInstance *) malloc_or_die( SCSISizeof( scsiClass ) );
71   scsiInstance->scsiClass = scsiClass;
72   return scsiInstance;
73}
74
75void *SCSIThis( SCSIClass *scsiClass, SCSIInstance *instance )
76{
77   if( instance != NULL )
78   {
79      int sizeofBase = sizeof( SCSIInstance );
80
81      while( scsiClass->baseClass != NULL )
82      {
83         scsiClass = scsiClass->baseClass;
84         sizeofBase += scsiClass->sizeofData;
85      }
86
87      return ( (UINT8*)instance ) + sizeofBase;
88   }
89
90   return NULL;
91}
92
93int SCSISizeof( SCSIClass *scsiClass )
94{
95   int sizeofData = sizeof( SCSIInstance );
96
97   while( scsiClass != NULL )
98   {
99      sizeofData += scsiClass->sizeofData;
100      scsiClass = scsiClass->baseClass;
101   }
102
103   return sizeofData;
104}
105
106int SCSILengthFromUINT8( UINT8 *length )
107{
108   if( *length == 0 )
109   {
110      return 256;
111   }
112
113   return *length;
114}
115
116int SCSILengthFromUINT16( UINT8 *length )
117{
118   return ( *(length) << 8 ) | *(length + 1 );
119}
src/emu/machine/am53cf96.h
r1215r1216
66#ifndef _AM53CF96_H_
77#define _AM53CF96_H_
88
9#include "scsidev.h"
9#include "scsi.h"
1010
1111struct AM53CF96interface
1212{
src/emu/machine/scsi.h
r0r1216
1/***************************************************************************
2
3 scsi.h - Header which defines the interface between SCSI device handlers
4          and SCSI interfaces.
5
6***************************************************************************/
7
8#ifndef _SCSI_H_
9#define _SCSI_H_
10
11#include "driver.h"
12
13typedef int (*pSCSIDispatch)( int operation, void *file, INT64 intparm, void *ptrparm );
14
15typedef struct _SCSIClass
16{
17   struct _SCSIClass *baseClass;
18   pSCSIDispatch dispatch;
19   int sizeofData;
20} SCSIClass;
21
22typedef struct
23{
24   SCSIClass *scsiClass;
25} SCSIInstance;
26
27// commands accepted by a SCSI device's dispatch handler
28enum
29{
30   SCSIOP_EXEC_COMMAND = 0,   // execute a command packet
31   SCSIOP_SET_COMMAND,         // set a command packet
32   SCSIOP_GET_COMMAND,         // get a command packet
33   SCSIOP_READ_DATA,         // data transfer from the device
34   SCSIOP_WRITE_DATA,         // data transfer to the device
35   SCSIOP_ALLOC_INSTANCE,      // allocate an instance of the device
36   SCSIOP_DELETE_INSTANCE,      // delete an instance of the device
37   SCSIOP_GET_DEVICE,         // get the device's internal device (CDROM or HDD pointer)
38   SCSIOP_SET_DEVICE,         // set the device's internal device (CDROM or HDD pointer)
39   SCSIOP_RESET_DEVICE,      // reset the device
40   SCSIOP_SET_PHASE,
41   SCSIOP_GET_PHASE,
42};
43
44typedef struct scsiconfigitem
45{
46   int scsiID;
47   int diskID;
48   SCSIClass *scsiClass;
49} SCSIConfigItem;
50
51#define SCSI_MAX_DEVICES   (16)
52
53typedef struct scsiconfigtable
54{
55   int devs_present;
56   SCSIConfigItem devices[SCSI_MAX_DEVICES];
57} SCSIConfigTable;
58
59// SCSI IDs
60enum
61{
62   SCSI_ID_0 = 0,
63   SCSI_ID_1,
64   SCSI_ID_2,
65   SCSI_ID_3,
66   SCSI_ID_4,
67   SCSI_ID_5,
68   SCSI_ID_6,
69   SCSI_ID_7
70};
71
72
73#define SCSI_PHASE_DATAOUT ( 0 )
74#define SCSI_PHASE_DATAIN ( 1 )
75#define SCSI_PHASE_COMMAND ( 2 )
76#define SCSI_PHASE_STATUS ( 3 )
77#define SCSI_PHASE_MESSAGE_OUT ( 6 )
78#define SCSI_PHASE_MESSAGE_IN ( 7 )
79
80extern void SCSIAllocInstance( SCSIClass *scsiClass, SCSIInstance **instance, int diskId );
81extern void SCSIDeleteInstance( SCSIInstance *instance );
82extern void SCSISetDevice( SCSIInstance *instance, void *device );
83extern void SCSIGetDevice( SCSIInstance *instance, void **device );
84extern void SCSIReset( SCSIInstance *instance );
85extern void SCSISetCommand( SCSIInstance *instance, UINT8 *command, int commandLength );
86extern void SCSIGetCommand( SCSIInstance *instance, UINT8 **command, int *commandLength );
87extern void SCSIExecCommand( SCSIInstance *instance, int *resultLength );
88extern void SCSIWriteData( SCSIInstance *instance, void *data, int dataLength );
89extern void SCSIReadData( SCSIInstance *instance, void *data, int dataLength );
90extern void SCSISetPhase( SCSIInstance *instance, int phase );
91extern void SCSIGetPhase( SCSIInstance *instance, int *phase );
92
93extern SCSIInstance *SCSIMalloc( SCSIClass *scsiClass );
94extern int SCSIBase( SCSIClass *scsiClass, int operation, void *file, INT64 intparm, UINT8 *ptrparm );
95extern void *SCSIThis( SCSIClass *scsiClass, SCSIInstance *instance );
96extern int SCSISizeof( SCSIClass *scsiClass );
97extern int SCSILengthFromUINT8( UINT8 *length );
98extern int SCSILengthFromUINT16( UINT8 *length );
99
100#endif
101
102// include these here to avoid changing the drivers.
103#include "machine/scsicd.h"
104#include "machine/scsihd.h"
src/emu/machine/i2cmem.c
r0r1216
1/*
2
3I2C Memory
4
5Generic ram/rom/eeprom/flash on an i2c bus. Supports specifying the slave address,
6the data size & the page size for writing.
7
8inputs:
9 e0,e1,e2  lower 3 bits of the slave address
10 sda       serial data
11 scl       serial clock
12 wc        write protect
13
14outputs:
15 sda       serial data
16
17The memory address is only 8 bits, devices larger than this have multiple slave addresses.
18The top five address bits are set at manufacture time, two values are standard.
19Up to 4096 bytes can be addressed.
20
21*/
22
23#include <driver.h>
24#include "machine/i2cmem.h"
25
26#define VERBOSE_LEVEL ( 0 )
27
28INLINE void verboselog( int n_level, const char *s_fmt, ... )
29{
30   if( VERBOSE_LEVEL >= n_level )
31   {
32      va_list v;
33      char buf[ 32768 ];
34      va_start( v, s_fmt );
35      vsprintf( buf, s_fmt, v );
36      va_end( v );
37      if( cpu_getactivecpu() != -1 )
38      {
39         logerror( "%08x: %s", activecpu_get_pc(), buf );
40      }
41      else
42      {
43         logerror( "(timer) : %s", buf );
44      }
45   }
46}
47
48struct i2cmem_chip
49{
50   int slave_address;
51   int scl;
52   int sdaw;
53   int e0;
54   int e1;
55   int e2;
56   int wc;
57   int sdar;
58   int state;
59   int bits;
60   int shift;
61   int devsel;
62   int byteaddr;
63   unsigned char *data;
64   int data_size;
65   unsigned char *page;
66   int page_offset;
67   int page_size;
68};
69
70#define STATE_IDLE ( 0 )
71#define STATE_DEVSEL ( 1 )
72#define STATE_BYTEADDR ( 2 )
73#define STATE_DATAIN ( 3 )
74#define STATE_DATAOUT ( 4 )
75
76#define DEVSEL_RW ( 1 )
77#define DEVSEL_ADDRESS ( 0xfe )
78
79struct i2cmem_chip i2cmem[ I2CMEM_MAXCHIP ];
80
81void i2cmem_init( int chip, int slave_address, int page_size, int data_size, unsigned char *data )
82{
83   struct i2cmem_chip *c;
84   unsigned char *page = NULL;
85
86   if( chip >= I2CMEM_MAXCHIP )
87   {
88      verboselog( 0, "i2cmem_init( %d ) invalid chip\n", chip );
89      return;
90   }
91
92   c = &i2cmem[ chip ];
93
94   if( data == NULL )
95   {
96      data = auto_malloc( data_size );
97   }
98
99   if( page_size > 0 )
100   {
101      page = auto_malloc( page_size );
102   }
103
104   c->slave_address = slave_address;
105   c->data_size = data_size;
106   c->page_size = page_size;
107
108   c->scl = 0;
109   c->sdaw = 0;
110   c->e0 = 0;
111   c->e1 = 0;
112   c->e2 = 0;
113   c->wc = 0;
114   c->sdar = 1;
115   c->state = STATE_IDLE;
116   c->bits = 0;
117   c->shift = 0;
118   c->devsel = 0;
119   c->byteaddr = 0;
120   c->data = data;
121   c->page = page;
122
123   state_save_register_item( "i2cmem", chip, c->scl );
124   state_save_register_item( "i2cmem", chip, c->sdaw );
125   state_save_register_item( "i2cmem", chip, c->e0 );
126   state_save_register_item( "i2cmem", chip, c->e1 );
127   state_save_register_item( "i2cmem", chip, c->e2 );
128   state_save_register_item( "i2cmem", chip, c->wc );
129   state_save_register_item( "i2cmem", chip, c->sdar );
130   state_save_register_item( "i2cmem", chip, c->state );
131   state_save_register_item( "i2cmem", chip, c->bits );
132   state_save_register_item( "i2cmem", chip, c->shift );
133   state_save_register_item( "i2cmem", chip, c->devsel );
134   state_save_register_item( "i2cmem", chip, c->byteaddr );
135   state_save_register_item_pointer( "i2cmem", chip, c->data, c->data_size );
136}
137
138static int select_device( struct i2cmem_chip *c )
139{
140   int device = ( c->slave_address & 0xf0 ) | ( c->e2 << 3 ) | ( c->e1 << 2 ) | ( c->e0 << 1 );
141   int mask = DEVSEL_ADDRESS & ~( ( c->data_size - 1 ) >> 7 );
142
143   if( ( c->devsel & mask ) == ( device & mask ) )
144   {
145      return 1;
146   }
147
148   return 0;
149}
150
151static int data_offset( struct i2cmem_chip *c )
152{
153   return ( ( ( c->devsel << 7 ) & 0xff00 ) | ( c->byteaddr & 0xff ) ) & ( c->data_size - 1 );
154}
155
156void i2cmem_write( int chip, int line, int data )
157{
158   struct i2cmem_chip *c;
159
160   if( chip >= I2CMEM_MAXCHIP )
161   {
162      verboselog( 0, "i2cmem_write( %d, %d, %d ) invalid chip\n", chip, line, data );
163      return;
164   }
165
166   c = &i2cmem[ chip ];
167
168   data &= 1;
169
170   switch( line )
171   {
172   case I2CMEM_E0:
173      if( c->e0 != data )
174      {
175         c->e0 = data;
176         verboselog( 2, "i2cmem_write( %d, I2CMEM_E0, %d )\n", chip, c->e0 );
177      }
178      break;
179
180   case I2CMEM_E1:
181      if( c->e1 != data )
182      {
183         c->e1 = data;
184         verboselog( 2, "i2cmem_write( %d, I2CMEM_E1, %d )\n", chip, c->e1 );
185      }
186      break;
187
188   case I2CMEM_E2:
189      if( c->e2 != data )
190      {
191         c->e2 = data;
192         verboselog( 2, "i2cmem_write( %d, I2CMEM_E2, %d )\n", chip, c->e2 );
193      }
194      break;
195
196   case I2CMEM_SDA:
197      if( c->sdaw != data )
198      {
199         c->sdaw = data;
200         verboselog( 2, "i2cmem_write( %d, I2CMEM_SDA, %d )\n", chip, c->sdaw );
201
202         if( c->scl )
203         {
204            if( c->sdaw )
205            {
206               verboselog( 1, "i2cmem(%d) stop\n", chip );
207               c->state = STATE_IDLE;
208               c->byteaddr = 0;
209            }
210            else
211            {
212               verboselog( 2, "i2cmem(%d) start\n", chip );
213               c->state = STATE_DEVSEL;
214               c->bits = 0;
215            }
216
217            c->sdar = 1;
218         }
219      }
220      break;
221
222   case I2CMEM_SCL:
223      if( c->scl != data )
224      {
225         c->scl = data;
226         verboselog( 2, "i2cmem_write( %d, I2CMEM_SCL, %d )\n", chip, c->scl );
227
228         switch( c->state )
229         {
230         case STATE_DEVSEL:
231         case STATE_BYTEADDR:
232         case STATE_DATAIN:
233            if( c->bits < 8 )
234            {
235               if( c->scl )
236               {
237                  c->shift = ( ( c->shift << 1 ) | c->sdaw ) & 0xff;
238                  c->bits++;
239               }
240            }
241            else
242            {
243               if( c->scl )
244               {
245                  switch( c->state )
246                  {
247                  case STATE_DEVSEL:
248                     c->devsel = c->shift;
249
250                     if( !select_device( c ) )
251                     {
252                        verboselog( 1, "i2cmem(%d) devsel %02x: not this device\n", chip, c->devsel );
253                        c->state = STATE_IDLE;
254                     }
255                     else if( ( c->devsel & DEVSEL_RW ) == 0 )
256                     {
257                        verboselog( 1, "i2cmem(%d) devsel %02x: write\n", chip, c->devsel );
258                        c->state = STATE_BYTEADDR;
259                     }
260                     else
261                     {
262                        verboselog( 1, "i2cmem(%d) devsel %02x: read\n", chip, c->devsel );
263                        c->state = STATE_DATAOUT;
264                     }
265                     break;
266
267                  case STATE_BYTEADDR:
268                     c->byteaddr = c->shift;
269                     c->page_offset = 0;
270
271                     verboselog( 1, "i2cmem(%d) byteaddr %02x\n", chip, c->byteaddr );
272
273                     c->state = STATE_DATAIN;
274                     break;
275
276                  case STATE_DATAIN:
277                     if( c->wc )
278                     {
279                        verboselog( 0, "i2cmem(%d) write not enabled\n", chip );
280                        c->state = STATE_IDLE;
281                     }
282                     else if( c->page_size > 0 )
283                     {
284                        c->page[ c->page_offset ] = c->shift;
285                        verboselog( 1, "i2cmem(%d) page[ %04x ] <- %02x\n", chip, c->page_offset, c->page[ c->page_offset ] );
286
287                        c->page_offset++;
288                        if( c->page_offset == c->page_size )
289                        {
290                           int offset = data_offset( c ) & ~( c->page_size - 1 );
291
292                           memcpy( &c->data[ offset ], c->page, c->page_size );
293                           verboselog( 1, "i2cmem(%d) data[ %04x to %04x ] = page\n", chip, offset, offset + c->page_size - 1 );
294
295                           c->page_offset = 0;
296                        }
297                     }
298                     else
299                     {
300                        int offset = data_offset( c );
301
302                        c->data[ offset ] = c->shift;
303                        verboselog( 1, "i2cmem(%d) data[ %04x ] <- %02x\n", chip, offset, c->data[ offset ] );
304
305                        c->byteaddr++;
306                     }
307                     break;
308                  }
309
310                  c->bits++;
311               }
312               else
313               {
314                  if( c->bits == 8 )
315                  {
316                     c->sdar = 0;
317                  }
318                  else
319                  {
320                     c->bits = 0;
321                     c->sdar = 1;
322                  }
323               }
324            }
325            break;
326
327         case STATE_DATAOUT:
328            if( c->bits < 8 )
329            {
330               if( c->scl )
331               {
332                  if( c->bits == 0 )
333                  {
334                     int offset = data_offset( c );
335
336                     c->shift = c->data[ offset ];
337                     verboselog( 1, "i2cmem(%d) data[ %04x ] -> %02x\n", chip, offset, c->data[ offset ] );
338                     c->byteaddr++;
339                  }
340
341                  c->sdar = ( c->shift >> 7 ) & 1;
342
343                  c->shift = ( c->shift << 1 ) & 0xff;
344                  c->bits++;
345               }
346            }
347            else
348            {
349               if( c->scl )
350               {
351                  if( c->sdaw )
352                  {
353                     verboselog( 1, "i2cmem(%d) sleep\n", chip );
354                     c->state = STATE_IDLE;
355                  }
356
357                  c->bits++;
358               }
359               else
360               {
361                  if( c->bits == 8 )
362                  {
363                     c->sdar = 1;
364                  }
365                  else
366                  {
367                     c->bits = 0;
368                  }
369               }
370            }
371            break;
372         }
373      }
374      break;
375
376   case I2CMEM_WC:
377      if( c->wc != data )
378      {
379         c->wc = data;
380         verboselog( 2, "i2cmem_write( %d, I2CMEM_WC, %d )\n", chip, c->wc );
381      }
382      break;
383
384   default:
385      verboselog( 0, "i2cmem_write( %d, %d, %d ) invalid line\n", chip, line, data );
386      break;
387   }
388}
389
390int i2cmem_read( int chip, int line )
391{
392   struct i2cmem_chip *c;
393
394   if( chip >= I2CMEM_MAXCHIP )
395   {
396      verboselog( 0, "i2cmem_read( %d, %d ) invalid chip\n", chip, line );
397      return 0;
398   }
399
400   c = &i2cmem[ chip ];
401
402   switch( line )
403   {
404   case I2CMEM_SDA:
405      verboselog( 2, "i2cmem_read( %d, I2CMEM_SDA ) %d\n", chip, c->sdar & c->sdaw );
406      return c->sdar & c->sdaw;
407
408   default:
409      verboselog( 0, "i2cmem_read( %d, %d ) invalid line\n", chip, line );
410      break;
411   }
412
413   return 0;
414}
415
416static void nvram_handler_i2cmem( int chip, running_machine *machine, mame_file *file, int read_or_write )
417{
418   struct i2cmem_chip *c;
419
420   if( chip >= I2CMEM_MAXCHIP )
421   {
422      verboselog( 0, "nvram_handler_i2cmem( %d ) invalid chip\n", chip );
423      return;
424   }
425
426   c = &i2cmem[ chip ];
427
428   if( read_or_write )
429   {
430      mame_fwrite( file, c->data, c->data_size );
431   }
432   else if( file )
433   {
434      mame_fread( file, c->data, c->data_size );
435   }
436}
437
438NVRAM_HANDLER( i2cmem_0 ) { nvram_handler_i2cmem( 0, machine, file, read_or_write ); }
src/emu/machine/i2cmem.h
r0r1216
1/*
2
3I2C Memory
4
5*/
6
7#if !defined( I2CMEM_H )
8#define I2CMEM_H ( 1 )
9
10#define I2CMEM_E0 ( 1 )
11#define I2CMEM_E1 ( 2 )
12#define I2CMEM_E2 ( 3 )
13#define I2CMEM_SDA ( 5 )
14#define I2CMEM_SCL ( 6 )
15#define I2CMEM_WC ( 7 )
16
17#define I2CMEM_MAXCHIP ( 1 )
18
19#define I2CMEM_SLAVE_ADDRESS ( 0xa0 )
20#define I2CMEM_SLAVE_ADDRESS_ALT ( 0xb0 )
21
22extern void i2cmem_init( int chip, int slave_address, int page_size, int data_size, unsigned char *data );
23extern void i2cmem_write( int chip, int line, int data );
24extern int i2cmem_read( int chip, int line );
25extern NVRAM_HANDLER( i2cmem_0 );
26
27#endif
src/emu/rendersw.c
r1215r1216
5252#define FIRST_TIME
5353
5454#include "mamecore.h"
55#include "osinline.h"
55#include "eminline.h"
5656#include "render.h"
5757#include <math.h>
5858
r1215r1216
146146   return MAKE_RGB(r, g, b);
147147}
148148
149
150#ifndef vec_mult
151INLINE int vec_mult(int parm1, int parm2)
152{
153   int temp,result;
154
155   temp     = abs(parm1);
156   result   = (temp&0x0000ffff) * (parm2&0x0000ffff);
157   result >>= 16;
158   result  += (temp&0x0000ffff) * (parm2>>16       );
159   result  += (temp>>16       ) * (parm2&0x0000ffff);
160   result >>= 16;
161   result  += (temp>>16       ) * (parm2>>16       );
162
163   if( parm1 < 0 )
164      return(-result);
165   else
166      return( result);
167}
168149#endif
169150
170/* can be be replaced by an assembly routine in osinline.h */
171#ifndef vec_div
172INLINE int vec_div(int parm1, int parm2)
173{
174   if( (parm2>>12) )
175   {
176      parm1 = (parm1<<4) / (parm2>>12);
177      if( parm1 > 0x00010000 )
178         return( 0x00010000 );
179      if( parm1 < -0x00010000 )
180         return( -0x00010000 );
181      return( parm1 );
182   }
183   return( 0x00010000 );
184}
185#endif
186151
187
188#endif
189
190
191
192152/***************************************************************************
193153    MACROS
194154***************************************************************************/
r1215r1216
304264      if (dx >= dy)
305265      {
306266         sx = ((x1 <= x2) ? 1 : -1);
307         sy = vec_div(y2 - y1, dx);
267         sy = (dy == 0) ? 0 : div_32x32_shift(y2 - y1, dx, 16);
308268         if (sy < 0)
309269            dy--;
310270         x1 >>= 16;
311271         xx = x2 >> 16;
312         bwidth = vec_mult(beam << 4, cosine_table[abs(sy) >> 5]);
272         bwidth = mul_32x32_hi(beam << 4, cosine_table[abs(sy) >> 5]);
313273         y1 -= bwidth >> 1; /* start back half the diameter */
314274         for (;;)
315275         {
r1215r1216
340300      else
341301      {
342302         sy = ((y1 <= y2) ? 1: -1);
343         sx = vec_div(x2 - x1, dy);
303         sx = (dx == 0) ? 0 : div_32x32_shift(x2 - x1, dy, 16);
344304         if (sx < 0)
345305            dx--;
346306         y1 >>= 16;
347307         yy = y2 >> 16;
348         bwidth = vec_mult(beam << 4,cosine_table[abs(sx) >> 5]);
308         bwidth = mul_32x32_hi(beam << 4,cosine_table[abs(sx) >> 5]);
349309         x1 -= bwidth >> 1; /* start back half the width */
350310         for (;;)
351311         {
src/emu/mamecore.h
r1215r1216
347347   return u.vv;
348348}
349349
350
351
352/***************************************************************************
353    INLINE MATH HELPERS
354***************************************************************************/
355
356/* If the OSD layer wants to override these in osd_cpu.h, they can by #defining */
357/* the function name to itself or to point to something else */
358
359
360/* return the number of leading zero bits in a 32-bt value */
361#ifndef count_leading_zeros
362INLINE UINT32 count_leading_zeros(UINT32 val)
363{
364   UINT32 count;
365   for (count = 0; (INT32)val >= 0; count++) val <<= 1;
366   return count;
367}
368#endif
369
370
371/* return the number of leading one bits in a 32-bt value */
372#ifndef count_leading_ones
373INLINE UINT32 count_leading_ones(UINT32 val)
374{
375   UINT32 count;
376   for (count = 0; (INT32)val < 0; count++) val <<= 1;
377   return count;
378}
379#endif
380
381
382/* perform a 32x32 multiply to 64-bit precision and then shift */
383#ifndef fixed_mul_shift
384INLINE INT32 fixed_mul_shift(INT32 val1, INT32 val2, UINT8 shift)
385{
386   return (INT32)(((INT64)val1 * (INT64)val2) >> shift);
387}
388#endif
389
390
391350#endif   /* __MAMECORE_H__ */
src/emu/profiler.c
r1215r1216
1111
1212#include "osdepend.h"
1313#include "driver.h"
14#include "osinline.h"
1514#include "profiler.h"
1615
1716
src/emu/validity.c
r1215r1216
1010***************************************************************************/
1111
1212#include "osdepend.h"
13#include "eminline.h"
1314#include "driver.h"
1415#include "hash.h"
1516#include <ctype.h>
r1215r1216
208209
209210/*************************************
210211 *
212 *  Validate inline functions
213 *
214 *************************************/
215
216static int validate_inlines(void)
217{
218#undef rand
219   int test1 = rand() | (rand() << 15);
220   int test2 = rand() | (rand() << 15);
221   int error = FALSE;
222
223   if (mul_32x32(test1, test2) != (INT64)test1 * (INT64)test2) { mame_printf_error("Error testing mul_32x32\n"); error = TRUE; }
224   if (mulu_32x32(test1, test2) != (UINT64)test1 * (UINT64)test2) { mame_printf_error("Error testing mulu_32x32\n"); error = TRUE; }
225   if (mul_32x32_hi(test1, test2) != ((INT64)test1 * (INT64)test2) >> 32) { mame_printf_error("Error testing mul_32x32_hi\n"); error = TRUE; }
226   if (mulu_32x32_hi(test1, test2) != ((UINT64)test1 * (UINT64)test2) >> 32) { mame_printf_error("Error testing mulu_32x32_hi\n"); error = TRUE; }
227   if (mul_32x32_shift(test1, test2, 7) != (INT32)(((INT64)test1 * (INT64)test2) >> 7)) { mame_printf_error("Error testing mul_32x32_shift\n"); error = TRUE; }
228   if (mulu_32x32_shift(test1, test2, 7) != (UINT32)(((UINT64)test1 * (UINT64)test2) >> 7)) { mame_printf_error("Error testing mulu_32x32_shift\n"); error = TRUE; }
229   if (fabs(recip_approx(100.0) - 0.01) > 0.0001) { mame_printf_error("Error testing recip_approx\n"); error = TRUE; }
230   test1 = (test1 & 0x0000ffff) | 0x400000;
231   if (count_leading_zeros(test1) != 9) { mame_printf_error("Error testing count_leading_zeros\n"); error = TRUE; }
232   test1 = (test1 | 0xffff0000) & ~0x400000;
233   if (count_leading_ones(test1) != 9) { mame_printf_error("Error testing count_leading_ones\n"); error = TRUE; }
234   test2 = test1;
235   if (compare_exchange32(&test1, test2, 1000) != test2) { mame_printf_error("Error testing compare_exchange32\n"); error = TRUE; }
236   if (atomic_exchange32(&test1, test2) != 1000) { mame_printf_error("Error testing atomic_exchange32\n"); error = TRUE; }
237   if (atomic_add32(&test1, 45) != test2 + 45) { mame_printf_error("Error testing atomic_add32\n"); error = TRUE; }
238
239   return error;
240}
241
242
243
244/*************************************
245 *
211246 *  Validate basic driver info
212247 *
213248 *************************************/
r1215r1216
12081243   if (lsbtest == 0x00ff)      { mame_printf_error("LSB_FIRST not specified, but running on a little-endian machine\n"); error = TRUE; }
12091244#endif
12101245
1246   /* validate inline function behavior */
1247   error = validate_inlines() || error;
1248
12111249   /* make sure the CPU and sound interfaces are up and running */
12121250   cpuintrf_init(NULL);
12131251   sndintrf_init(NULL);
src/mess/machine/ncr5380.c
r1215r1216
347347   // try to open the devices
348348   for (i = 0; i < interface->scsidevs->devs_present; i++)
349349   {
350      devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler;
351      interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL);
350      /* compilation error */
351      /* devices[interface->scsidevs->devices[i].scsiID].handler = interface->scsidevs->devices[i].handler; */
352      /* interface->scsidevs->devices[i].handler(SCSIOP_ALLOC_INSTANCE, &devices[interface->scsidevs->devices[i].scsiID].data, interface->scsidevs->devices[i].diskID, (UINT8 *)NULL); */
352353   }   
353354
354355   state_save_register_item_array("ncr5380", 0, n5380_Registers);
docs/messnew.txt
r1215r1216
4141
4242Source Changes:
4343----------------
44- The core is based on MAME 0.120u1.  This incorporates all features of the
44- The core is based on MAME 0.120u2.  This incorporates all features of the
4545  update to this core.  [MAME team]
4646
4747

Previous 15994 Revisions Next


© 1998-2018 The MESS Team