Previous 15994 Revisions Next

r4374 Tuesday 3rd March, 2009 at 07:25:48 UTC by Robbbert
[CPSCHNGR] Removed dependence from cps1, many cleanups as a result.
[src/mess]mess.mak messdriv.c
[src/mess/drivers]cpschngr.c
[src/mess/includes]cps1.h*
[src/mess/video]cpschngr.c*

src/mess/video/cpschngr.c
r0r4374
1/***************************************************************************
2 
3   CPS Changer
4 
5***************************************************************************/
6 
7#include "driver.h"
8#include "cps1.h"
9 
10/********************************************************************
11 
12            Configuration table:
13 
14********************************************************************/
15 
16/* Game specific data */
17 
18#define GFXTYPE_SPRITES   (1<<0)
19#define GFXTYPE_SCROLL1   (1<<1)
20#define GFXTYPE_SCROLL2   (1<<2)
21#define GFXTYPE_SCROLL3   (1<<3)
22#define GFXTYPE_STARS     (1<<4)
23 
24 
25struct gfx_range
26{
27   // start and end are as passed by the game (shift adjusted to be all
28   // in the same scale a 8x8 tiles): they don't necessarily match the
29   // position in ROM.
30   int type;
31   int start;
32   int end;
33   int bank;
34};
35 
36struct CPS1config
37{
38   const char *name;             /* game driver name */
39 
40   /* Some games interrogate a couple of registers on bootup. */
41   /* These are CPS1 board B self test checks. They wander from game to */
42   /* game. */
43   int cpsb_addr;        /* CPS board B test register address */
44   int cpsb_value;       /* CPS board B test register expected value */
45 
46   /* some games use as a protection check the ability to do 16-bit multiplies */
47   /* with a 32-bit result, by writing the factors to two ports and reading the */
48   /* result from two other ports. */
49   /* It looks like this feature was introduced with 3wonders (CPSB ID = 08xx) */
50   int mult_factor1;
51   int mult_factor2;
52   int mult_result_lo;
53   int mult_result_hi;
54 
55   /* unknown registers which might be related to the multiply protection */
56   int unknown1;
57   int unknown2;
58   int unknown3;
59 
60   int layer_control;
61   int priority[4];
62   int palette_control;
63 
64   /* ideally, the layer enable masks should consist of only one bit, */
65   /* but in many cases it is unknown which bit is which. */
66   int layer_enable_mask[5];
67 
68   /* these depend on the B-board model and PAL */
69   int bank_sizes[4];
70   const struct gfx_range *bank_mapper;
71 
72   /* some C-boards have additional I/O for extra buttons/extra players */
73   int in2_addr;
74   int in3_addr;
75   int out2_addr;
76 
77   int bootleg_kludge;
78};
79 
80static const struct CPS1config *cps1_game_config;
81 
82 
83#define __not_applicable__   -1,-1,-1,-1,-1,-1,-1
84 
85/*                     CPSB ID    multiply protection      unknown      ctrl     priority masks   palctrl    layer enable masks  */
86#define CPS_B_21_DEF 0x32,  -1,   0x00,0x02,0x04,0x06, 0x08, -1,  -1,   0x26,{0x28,0x2a,0x2c,0x2e},0x30, {0x02,0x04,0x08,0x30,0x30}   // pang3 sets layer enable to 0x26 on startup
87 
88#define mapper_sfzch   { 0x20000, 0, 0, 0 }, mapper_sfzch_table
89static const struct gfx_range mapper_sfzch_table[] =
90{
91   /* type                                                                  start    end      bank */
92   { GFXTYPE_SPRITES | GFXTYPE_SCROLL1 | GFXTYPE_SCROLL2 | GFXTYPE_SCROLL3, 0x00000, 0x1ffff, 0 },
93   { 0 }
94};
95 
96static const struct CPS1config cps1_config_table[]=
97{
98   /* name       CPSB         gfx mapper   in2  in3  out2   kludge */
99   {"sfach",    CPS_B_21_DEF, mapper_sfzch },
100   {"sfzbch",   CPS_B_21_DEF, mapper_sfzch },
101   {"sfzch",    CPS_B_21_DEF, mapper_sfzch },
102   {"wofch",    CPS_B_21_DEF, mapper_sfzch },
103   {0}      /* End of table */
104};
105 
106 
107 
108/* Public variables */
109UINT16 *cps1_gfxram;
110UINT16 *cps1_cps_a_regs;
111UINT16 *cps1_cps_b_regs;
112 
113size_t cps1_gfxram_size;
114 
115/* Offset of each palette entry */
116#define cps1_palette_entries (32*6)  /* Number colour schemes in palette */
117 
118static const int cps1_scroll_size =0x4000;   /* scroll1, scroll2, scroll3 */
119static const int cps1_obj_size    =0x0800;
120static const int cps1_other_size  =0x0800;
121static const int cps1_palette_align=0x0400;   /* minimum alignment is a single palette page (512 colors). Verified on pcb. */
122static const int cps1_palette_size=cps1_palette_entries*32; /* Size of palette RAM */
123 
124static UINT16 *cps1_scroll1;
125static UINT16 *cps1_scroll2;
126static UINT16 *cps1_scroll3;
127static UINT16 *cps1_obj;
128static UINT16 *cps1_buffered_obj;
129static UINT16 *cps1_other;
130 
131/* Working variables */
132static int cps1_last_sprite_offset;     /* Offset of the last sprite */
133static int cps1_stars_enabled[2];          /* Layer enabled [Y/N] */
134 
135static tilemap *cps1_bg_tilemap[3];
136 
137 
138static int cps1_scroll1x, cps1_scroll1y;
139static int cps1_scroll2x, cps1_scroll2y;
140static int cps1_scroll3x, cps1_scroll3y;
141static int stars1x, stars1y, stars2x, stars2y;
142 
143 
144/* CPS-A registers */
145#define CPS1_OBJ_BASE           (0x00/2)    /* Base address of objects */
146#define CPS1_SCROLL1_BASE       (0x02/2)    /* Base address of scroll 1 */
147#define CPS1_SCROLL2_BASE       (0x04/2)    /* Base address of scroll 2 */
148#define CPS1_SCROLL3_BASE       (0x06/2)    /* Base address of scroll 3 */
149#define CPS1_OTHER_BASE         (0x08/2)    /* Base address of other video */
150#define CPS1_PALETTE_BASE       (0x0a/2)    /* Base address of palette */
151#define CPS1_SCROLL1_SCROLLX    (0x0c/2)    /* Scroll 1 X */
152#define CPS1_SCROLL1_SCROLLY    (0x0e/2)    /* Scroll 1 Y */
153#define CPS1_SCROLL2_SCROLLX    (0x10/2)    /* Scroll 2 X */
154#define CPS1_SCROLL2_SCROLLY    (0x12/2)    /* Scroll 2 Y */
155#define CPS1_SCROLL3_SCROLLX    (0x14/2)    /* Scroll 3 X */
156#define CPS1_SCROLL3_SCROLLY    (0x16/2)    /* Scroll 3 Y */
157#define CPS1_STARS1_SCROLLX     (0x18/2)    /* Stars 1 X */
158#define CPS1_STARS1_SCROLLY     (0x1a/2)    /* Stars 1 Y */
159#define CPS1_STARS2_SCROLLX     (0x1c/2)    /* Stars 2 X */
160#define CPS1_STARS2_SCROLLY     (0x1e/2)    /* Stars 2 Y */
161#define CPS1_ROWSCROLL_OFFS     (0x20/2)    /* base of row scroll offsets in other RAM */
162#define CPS1_VIDEOCONTROL       (0x22/2)    /* flip screen, rowscroll enable */
163 
164 
165/* first 0x4000 of gfx ROM are used, but 0x0000-0x1fff is == 0x2000-0x3fff */
166static const int stars_rom_size = 0x2000;
167 
168static void cps1_build_palette(running_machine *machine, const UINT16* const palette_base);
169 
170 
171static MACHINE_RESET( cps )
172{
173   const char *gamename = machine->gamedrv->name;
174   const struct CPS1config *pCFG=&cps1_config_table[0];
175 
176   while(pCFG->name)
177   {
178      if (strcmp(pCFG->name, gamename) == 0)
179      {
180         break;
181      }
182      pCFG++;
183   }
184   cps1_game_config=pCFG;
185}
186 
187 
188INLINE UINT16 *cps1_base(int offset,int boundary)
189{
190   int base = cps1_cps_a_regs[offset]*256;
191   base &= ~(boundary-1);
192    return &cps1_gfxram[(base&0x3ffff)/2];
193}
194 
195 
196 
197WRITE16_HANDLER( cps1_cps_a_w )
198{
199   data = COMBINE_DATA(&cps1_cps_a_regs[offset]);
200 
201   if (offset == CPS1_PALETTE_BASE)
202      cps1_build_palette(space->machine, cps1_base(CPS1_PALETTE_BASE,cps1_palette_align));
203}
204 
205 
206READ16_HANDLER( cps1_cps_b_r )
207{
208   /* Some games interrogate a couple of registers on bootup. */
209   /* These are CPS1 board B self test checks. They wander from game to */
210   /* game. */
211   if (offset == cps1_game_config->cpsb_addr/2)
212      return cps1_game_config->cpsb_value;
213 
214   /* some games use as a protection check the ability to do 16-bit multiplications */
215   /* with a 32-bit result, by writing the factors to two ports and reading the */
216   /* result from two other ports. */
217   if (offset == cps1_game_config->mult_result_lo/2)
218      return (cps1_cps_b_regs[cps1_game_config->mult_factor1/2] *
219            cps1_cps_b_regs[cps1_game_config->mult_factor2/2]) & 0xffff;
220   if (offset == cps1_game_config->mult_result_hi/2)
221      return (cps1_cps_b_regs[cps1_game_config->mult_factor1/2] *
222            cps1_cps_b_regs[cps1_game_config->mult_factor2/2]) >> 16;
223 
224   if (offset == cps1_game_config->in2_addr/2)   /* Extra input ports (on C-board) */
225      return input_port_read(space->machine, "IN2");
226 
227   if (offset == cps1_game_config->in3_addr/2)   /* Player 4 controls (on C-board) ("Captain Commando") */
228      return input_port_read(space->machine, "IN3");
229 
230   return 0xffff;
231}
232 
233 
234WRITE16_HANDLER( cps1_cps_b_w )
235{
236   data = COMBINE_DATA(&cps1_cps_b_regs[offset]);
237 
238   // additional outputs on C-board
239   if (offset == cps1_game_config->out2_addr/2)
240   {
241      if (ACCESSING_BITS_0_7)
242      {
243         if (cps1_game_config->cpsb_value == 0x0402)   // Mercs (CN2 connector)
244         {
245            coin_lockout_w(2,~data & 0x01);
246            set_led_status(0,data & 0x02);
247            set_led_status(1,data & 0x04);
248            set_led_status(2,data & 0x08);
249         }
250         else   // kod, captcomm, knights
251         {
252            coin_lockout_w(2,~data & 0x02);
253            coin_lockout_w(3,~data & 0x08);
254         }
255      }
256   }
257}
258 
259 
260 
261static void cps1_gfx_decode(running_machine *machine)
262{
263   int size=memory_region_length(machine, "gfx");
264   int i,j,gfxsize;
265   UINT8 *cps1_gfx = memory_region(machine, "gfx");
266 
267 
268   gfxsize=size/4;
269 
270   for (i = 0;i < gfxsize;i++)
271   {
272      UINT32 src = cps1_gfx[4*i] + (cps1_gfx[4*i+1]<<8) + (cps1_gfx[4*i+2]<<16) + (cps1_gfx[4*i+3]<<24);
273      UINT32 dwval = 0;
274 
275      for (j = 0;j < 8;j++)
276      {
277         int n = 0;
278         UINT32 mask = (0x80808080 >> j) & src;
279 
280         if (mask & 0x000000ff) n |= 1;
281         if (mask & 0x0000ff00) n |= 2;
282         if (mask & 0x00ff0000) n |= 4;
283         if (mask & 0xff000000) n |= 8;
284 
285         dwval |= n << (j * 4);
286      }
287      cps1_gfx[4*i  ] = dwval>>0;
288      cps1_gfx[4*i+1] = dwval>>8;
289      cps1_gfx[4*i+2] = dwval>>16;
290      cps1_gfx[4*i+3] = dwval>>24;
291   }
292}
293 
294static void unshuffle(UINT64 *buf,int len)
295{
296   int i;
297   UINT64 t;
298 
299   if (len == 2) return;
300 
301   assert(len % 4 == 0);   /* must not happen */
302 
303   len /= 2;
304 
305   unshuffle(buf,len);
306   unshuffle(buf + len,len);
307 
308   for (i = 0;i < len/2;i++)
309   {
310      t = buf[len/2 + i];
311      buf[len/2 + i] = buf[len + i];
312      buf[len + i] = t;
313   }
314}
315 
316 
317DRIVER_INIT( cps1 )
318{
319   cps1_gfx_decode(machine);
320}
321 
322 
323static void cps1_get_video_base(void )
324{
325   int layercontrol, videocontrol, scroll1xoff, scroll2xoff, scroll3xoff;
326 
327   /* Re-calculate the VIDEO RAM base */
328   if (cps1_scroll1 != cps1_base(CPS1_SCROLL1_BASE,cps1_scroll_size))
329   {
330      cps1_scroll1 = cps1_base(CPS1_SCROLL1_BASE,cps1_scroll_size);
331      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[0]);
332   }
333   if (cps1_scroll2 != cps1_base(CPS1_SCROLL2_BASE,cps1_scroll_size))
334   {
335      cps1_scroll2 = cps1_base(CPS1_SCROLL2_BASE,cps1_scroll_size);
336      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[1]);
337   }
338   if (cps1_scroll3 != cps1_base(CPS1_SCROLL3_BASE,cps1_scroll_size))
339   {
340      cps1_scroll3 = cps1_base(CPS1_SCROLL3_BASE,cps1_scroll_size);
341      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[2]);
342   }
343 
344   /* Some of the sf2 hacks use only sprite port 0x9100 and the scroll layers are offset */
345   if (cps1_game_config->bootleg_kludge == 1)
346   {
347      cps1_cps_a_regs[CPS1_OBJ_BASE] = 0x9100;
348      cps1_obj = cps1_base(CPS1_OBJ_BASE, cps1_obj_size);
349      scroll1xoff = -0x0c;
350      scroll2xoff = -0x0e;
351      scroll3xoff = -0x10;
352   }
353   else
354   {
355      cps1_obj = cps1_base(CPS1_OBJ_BASE, cps1_obj_size);
356      scroll1xoff = 0;
357      scroll2xoff = 0;
358      scroll3xoff = 0;
359   }
360   cps1_other = cps1_base(CPS1_OTHER_BASE,cps1_other_size);
361 
362   /* Get scroll values */
363   cps1_scroll1x = cps1_cps_a_regs[CPS1_SCROLL1_SCROLLX] + scroll1xoff;
364   cps1_scroll1y = cps1_cps_a_regs[CPS1_SCROLL1_SCROLLY];
365   cps1_scroll2x = cps1_cps_a_regs[CPS1_SCROLL2_SCROLLX] + scroll2xoff;
366   cps1_scroll2y = cps1_cps_a_regs[CPS1_SCROLL2_SCROLLY];
367   cps1_scroll3x = cps1_cps_a_regs[CPS1_SCROLL3_SCROLLX] + scroll3xoff;
368   cps1_scroll3y = cps1_cps_a_regs[CPS1_SCROLL3_SCROLLY];
369   stars1x = cps1_cps_a_regs[CPS1_STARS1_SCROLLX];
370   stars1y = cps1_cps_a_regs[CPS1_STARS1_SCROLLY];
371   stars2x = cps1_cps_a_regs[CPS1_STARS2_SCROLLX];
372   stars2y = cps1_cps_a_regs[CPS1_STARS2_SCROLLY];
373 
374   /* Get layer enable bits */
375   layercontrol = cps1_cps_b_regs[cps1_game_config->layer_control/2];
376   videocontrol = cps1_cps_a_regs[CPS1_VIDEOCONTROL];
377   tilemap_set_enable(cps1_bg_tilemap[0],layercontrol & cps1_game_config->layer_enable_mask[0]);
378   tilemap_set_enable(cps1_bg_tilemap[1],(layercontrol & cps1_game_config->layer_enable_mask[1]) && (videocontrol & 4));
379   tilemap_set_enable(cps1_bg_tilemap[2],(layercontrol & cps1_game_config->layer_enable_mask[2]) && (videocontrol & 8));
380   cps1_stars_enabled[0] = layercontrol & cps1_game_config->layer_enable_mask[3];
381   cps1_stars_enabled[1] = layercontrol & cps1_game_config->layer_enable_mask[4];
382}
383 
384 
385WRITE16_HANDLER( cps1_gfxram_w )
386{
387   int page = (offset >> 7) & 0x3c0;
388   COMBINE_DATA(&cps1_gfxram[offset]);
389 
390   if (page == (cps1_cps_a_regs[CPS1_SCROLL1_BASE] & 0x3c0))
391      tilemap_mark_tile_dirty(cps1_bg_tilemap[0],offset/2 & 0x0fff);
392   if (page == (cps1_cps_a_regs[CPS1_SCROLL2_BASE] & 0x3c0))
393      tilemap_mark_tile_dirty(cps1_bg_tilemap[1],offset/2 & 0x0fff);
394   if (page == (cps1_cps_a_regs[CPS1_SCROLL3_BASE] & 0x3c0))
395      tilemap_mark_tile_dirty(cps1_bg_tilemap[2],offset/2 & 0x0fff);
396}
397 
398 
399 
400static int gfxrom_bank_mapper(running_machine *machine, int type, int code)
401{
402   const struct gfx_range *range = cps1_game_config->bank_mapper;
403   int shift = 0;
404 
405   assert(range);
406 
407   switch (type)
408   {
409      case GFXTYPE_SPRITES: shift = 1; break;
410      case GFXTYPE_SCROLL1: shift = 0; break;
411      case GFXTYPE_SCROLL2: shift = 1; break;
412      case GFXTYPE_SCROLL3: shift = 3; break;
413   }
414 
415   code <<= shift;
416 
417   while (range->type)
418   {
419      if (code >= range->start && code <= range->end)
420      {
421         if (range->type & type)
422         {
423            int base = 0;
424            int i;
425 
426            for (i = 0; i < range->bank; ++i)
427               base += cps1_game_config->bank_sizes[i];
428 
429            return (base + (code & (cps1_game_config->bank_sizes[range->bank] - 1))) >> shift;
430         }
431      }
432 
433      ++range;
434   }
435 
436   return -1;
437}
438 
439 
440/***************************************************************************
441 
442  Start the video hardware emulation.
443 
444***************************************************************************/
445 
446static TILEMAP_MAPPER( tilemap0_scan )
447{
448   /* logical (col,row) -> memory offset */
449   return (row & 0x1f) + ((col & 0x3f) << 5) + ((row & 0x20) << 6);
450}
451 
452static TILEMAP_MAPPER( tilemap1_scan )
453{
454   /* logical (col,row) -> memory offset */
455   return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x30) << 6);
456}
457 
458static TILEMAP_MAPPER( tilemap2_scan )
459{
460   /* logical (col,row) -> memory offset */
461   return (row & 0x07) + ((col & 0x3f) << 3) + ((row & 0x38) << 6);
462}
463 
464static UINT8 empty_tile8x8[8*8];
465static UINT8 empty_tile[32*32/2];
466 
467static TILE_GET_INFO( get_tile0_info )
468{
469   int code = cps1_scroll1[2*tile_index];
470   int attr = cps1_scroll1[2*tile_index+1];
471   int gfxset;
472 
473   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL1, code);
474 
475   /* allows us to reproduce a problem seen with a ffight board where USA and Japanese
476         roms have been mixed to be reproduced (ffightua) -- it looks like each column
477         should alternate between the left and right side of the 16x16 tiles */
478   gfxset = (tile_index & 0x20) >> 5;
479 
480   SET_TILE_INFO(
481         gfxset,
482         code,
483         (attr & 0x1f) + 0x20,
484         TILE_FLIPYX((attr & 0x60) >> 5));
485   tileinfo->group = (attr & 0x0180) >> 7;
486 
487   // for out of range tiles, switch to fully transparent data
488   // (but still call SET_TILE_INFO, otherwise problems might occur on boot e.g. unsquad)
489   if (code == -1)
490      tileinfo->pen_data = empty_tile8x8;
491}
492 
493static TILE_GET_INFO( get_tile1_info )
494{
495   int code = cps1_scroll2[2*tile_index];
496   int attr = cps1_scroll2[2*tile_index+1];
497 
498   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL2, code);
499 
500   SET_TILE_INFO(
501         2,
502         code,
503         (attr & 0x1f) + 0x40,
504         TILE_FLIPYX((attr & 0x60) >> 5));
505   tileinfo->group = (attr & 0x0180) >> 7;
506 
507   // for out of range tiles, switch to fully transparent data
508   if (code == -1)
509      tileinfo->pen_data = empty_tile;
510}
511 
512static TILE_GET_INFO( get_tile2_info )
513{
514   int code = cps1_scroll3[2*tile_index] & 0x3fff;
515   int attr = cps1_scroll3[2*tile_index+1];
516 
517   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL3, code);
518 
519   SET_TILE_INFO(
520         3,
521         code,
522         (attr & 0x1f) + 0x60,
523         TILE_FLIPYX((attr & 0x60) >> 5));
524   tileinfo->group = (attr & 0x0180) >> 7;
525 
526   // for out of range tiles, switch to fully transparent data
527   // (but still call SET_TILE_INFO, otherwise problems might occur on boot e.g. unsquad)
528   if (code == -1)
529      tileinfo->pen_data = empty_tile;
530}
531 
532 
533 
534static void cps1_update_transmasks(void)
535{
536   int i;
537 
538   for (i = 0;i < 4;i++)
539   {
540      int mask;
541 
542      /* Get transparency registers */
543      if (cps1_game_config->priority[i] != -1)
544         mask = cps1_cps_b_regs[cps1_game_config->priority[i]/2] ^ 0xffff;
545      else mask = 0xffff;   /* completely transparent if priority masks not defined (qad) */
546 
547      tilemap_set_transmask(cps1_bg_tilemap[0],i,mask,0x8000);
548      tilemap_set_transmask(cps1_bg_tilemap[1],i,mask,0x8000);
549      tilemap_set_transmask(cps1_bg_tilemap[2],i,mask,0x8000);
550   }
551}
552 
553VIDEO_START( cps1 )
554{
555   int i;
556 
557   MACHINE_RESET_CALL(cps);
558 
559   cps1_bg_tilemap[0] = tilemap_create(machine, get_tile0_info,tilemap0_scan, 8, 8,64,64);
560   cps1_bg_tilemap[1] = tilemap_create(machine, get_tile1_info,tilemap1_scan,16,16,64,64);
561   cps1_bg_tilemap[2] = tilemap_create(machine, get_tile2_info,tilemap2_scan,32,32,64,64);
562 
563   /* front masks will change at runtime to handle sprite occluding */
564   cps1_update_transmasks();
565 
566   memset(empty_tile8x8,0x0f,sizeof(empty_tile8x8));
567   memset(empty_tile,0xff,sizeof(empty_tile));   // 16x16 and 32x32 use packed graphics, 8x8 does not
568 
569   for (i = 0;i < cps1_palette_entries*16;i++)
570   {
571      palette_set_color(machine,i,MAKE_RGB(0,0,0));
572   }
573 
574   cps1_buffered_obj = auto_malloc (cps1_obj_size);
575   memset(cps1_buffered_obj, 0x00, cps1_obj_size);
576 
577   memset(cps1_gfxram, 0, cps1_gfxram_size);   /* Clear GFX RAM */
578   memset(cps1_cps_a_regs, 0, 0x40);   /* Clear CPS-A registers */
579   memset(cps1_cps_b_regs, 0, 0x40);   /* Clear CPS-B registers */
580 
581   /* Put in some defaults */
582   cps1_cps_a_regs[CPS1_OBJ_BASE]     = 0x9200;
583   cps1_cps_a_regs[CPS1_SCROLL1_BASE] = 0x9000;
584   cps1_cps_a_regs[CPS1_SCROLL2_BASE] = 0x9040;
585   cps1_cps_a_regs[CPS1_SCROLL3_BASE] = 0x9080;
586   cps1_cps_a_regs[CPS1_OTHER_BASE]   = 0x9100;
587 
588   assert_always(cps1_game_config, "cps1_game_config hasn't been set up yet");
589 
590   /* Set up old base */
591   cps1_get_video_base();   /* Calculate base pointers */
592   cps1_get_video_base();   /* Calculate old base pointers */
593}
594 
595 
596 
597/***************************************************************************
598 
599  Build palette from palette RAM
600 
601  12 bit RGB with a 4 bit brightness value.
602 
603***************************************************************************/
604 
605static void cps1_build_palette(running_machine *machine, const UINT16* const palette_base)
606{
607   int offset, page;
608   const UINT16 *palette_ram = palette_base;
609 
610   int ctrl = cps1_cps_b_regs[cps1_game_config->palette_control/2];
611 
612   for (page = 0; page < 6; ++page)
613   {
614      if (BIT(ctrl,page))
615      {
616         for (offset = 0; offset < 0x200; ++offset)
617         {
618            int palette = *(palette_ram++);
619            int r, g, b, bright;
620 
621            // from my understanding of the schematics, when the 'brightness'
622            // component is set to 0 it should reduce brightness to 1/3
623 
624            bright = 0x0f + ((palette>>12)<<1);
625 
626            r = ((palette>>8)&0x0f) * 0x11 * bright / 0x2d;
627            g = ((palette>>4)&0x0f) * 0x11 * bright / 0x2d;
628            b = ((palette>>0)&0x0f) * 0x11 * bright / 0x2d;
629 
630            palette_set_color (machine, 0x200*page + offset, MAKE_RGB(r, g, b));
631         }
632      }
633      else
634      {
635         // skip page in gfxram, but only if we have already copied at least one page
636         if (palette_ram != palette_base)
637            palette_ram += 0x200;
638      }
639   }
640}
641 
642static void cps1_find_last_sprite(void)    /* Find the offset of last sprite */
643{
644   int offset=0;
645   /* Locate the end of table marker */
646   while (offset < cps1_obj_size/2)
647   {
648        int colour=cps1_buffered_obj[offset+3];
649      if ((colour & 0xff00) == 0xff00)
650      {
651         /* Marker found. This is the last sprite. */
652         cps1_last_sprite_offset=offset-4;
653         return;
654      }
655        offset+=4;
656   }
657   /* Sprites must use full sprite RAM */
658   cps1_last_sprite_offset=cps1_obj_size/2-4;
659}
660 
661 
662static void cps1_render_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
663{
664#define DRAWSPRITE(CODE,COLOR,FLIPX,FLIPY,SX,SY)               \
665{                                                   \
666   if (flip_screen_get(machine))                                 \
667      pdrawgfx(bitmap,machine->gfx[2],                     \
668            CODE,                                    \
669            COLOR,                                    \
670            !(FLIPX),!(FLIPY),                           \
671            511-16-(SX),255-16-(SY),                     \
672            cliprect,TRANSPARENCY_PEN,15,0x02);               \
673   else                                             \
674      pdrawgfx(bitmap,machine->gfx[2],                     \
675            CODE,                                    \
676            COLOR,                                    \
677            FLIPX,FLIPY,                              \
678            SX,SY,                                    \
679            cliprect,TRANSPARENCY_PEN,15,0x02);               \
680}
681 
682 
683   int i, baseadd;
684   UINT16 *base=cps1_buffered_obj;
685 
686   /* some sf2 hacks draw the sprites in reverse order */
687   if (cps1_game_config->bootleg_kludge == 1)
688   {
689      base += cps1_last_sprite_offset;
690      baseadd = -4;
691   }
692   else
693   {
694      baseadd = 4;
695   }
696 
697   for (i=cps1_last_sprite_offset; i>=0; i-=4)
698   {
699      int x=*(base+0);
700      int y=*(base+1);
701      int code  =*(base+2);
702      int colour=*(base+3);
703      int col=colour&0x1f;
704 
705      code = gfxrom_bank_mapper(machine, GFXTYPE_SPRITES, code);
706 
707      if (code != -1)
708      {
709         if (colour & 0xff00 )
710         {
711            /* handle blocked sprites */
712            int nx=(colour & 0x0f00) >> 8;
713            int ny=(colour & 0xf000) >> 12;
714            int nxs,nys,sx,sy;
715            nx++;
716            ny++;
717 
718            if (colour & 0x40)
719            {
720               /* Y flip */
721               if (colour &0x20)
722               {
723                  for (nys=0; nys<ny; nys++)
724                  {
725                     for (nxs=0; nxs<nx; nxs++)
726                     {
727                        sx = (x+nxs*16) & 0x1ff;
728                        sy = (y+nys*16) & 0x1ff;
729 
730                        DRAWSPRITE(
731                              (code & ~0xf) + ((code + (nx-1) - nxs) & 0xf) + 0x10*(ny-1-nys),
732                              (col&0x1f),
733                              1,1,
734                              sx,sy);
735                     }
736                  }
737               }
738               else
739               {
740                  for (nys=0; nys<ny; nys++)
741                  {
742                     for (nxs=0; nxs<nx; nxs++)
743                     {
744                        sx = (x+nxs*16) & 0x1ff;
745                        sy = (y+nys*16) & 0x1ff;
746 
747                        DRAWSPRITE(
748                              (code & ~0xf) + ((code + nxs) & 0xf) + 0x10*(ny-1-nys),
749                              (col&0x1f),
750                              0,1,
751                              sx,sy);
752                     }
753                  }
754               }
755            }
756            else
757            {
758               if (colour &0x20)
759               {
760                  for (nys=0; nys<ny; nys++)
761                  {
762                     for (nxs=0; nxs<nx; nxs++)
763                     {
764                        sx = (x+nxs*16) & 0x1ff;
765                        sy = (y+nys*16) & 0x1ff;
766 
767                        DRAWSPRITE(
768                              (code & ~0xf) + ((code + (nx-1) - nxs) & 0xf) + 0x10*nys,
769                              (col&0x1f),
770                              1,0,
771                              sx,sy);
772                     }
773                  }
774               }
775               else
776               {
777                  for (nys=0; nys<ny; nys++)
778                  {
779                     for (nxs=0; nxs<nx; nxs++)
780                     {
781                        sx = (x+nxs*16) & 0x1ff;
782                        sy = (y+nys*16) & 0x1ff;
783 
784                        DRAWSPRITE(
785                              (code & ~0xf) + ((code + nxs) & 0xf) + 0x10*nys,   // fix 00406: qadj: When playing as the ninja, there is one broekn frame in his animation loop when walking.
786                              (col&0x1f),
787                              0,0,
788                              sx,sy);
789                     }
790                  }
791               }
792            }
793         }
794         else
795         {
796            /* Simple case... 1 sprite */
797                  DRAWSPRITE(
798                  code,
799                  (col&0x1f),
800                  colour&0x20,colour&0x40,
801                  x & 0x1ff,y & 0x1ff);
802         }
803      }
804      base += baseadd;
805   }
806#undef DRAWSPRITE
807}
808 
809 
810static void cps1_render_stars(const device_config *screen, bitmap_t *bitmap,const rectangle *cliprect)
811{
812   int offs;
813   UINT8 *stars_rom = memory_region(screen->machine, "stars");
814 
815   if (!stars_rom && (cps1_stars_enabled[0] || cps1_stars_enabled[1]))
816   {
817      return;
818   }
819 
820   if (cps1_stars_enabled[0])
821   {
822      for (offs = 0;offs < stars_rom_size/2;offs++)
823      {
824         int col = stars_rom[8*offs+4];
825         if (col != 0x0f)
826         {
827            int sx = (offs / 256) * 32;
828            int sy = (offs % 256);
829            sx = (sx - stars2x + (col & 0x1f)) & 0x1ff;
830            sy = (sy - stars2y) & 0xff;
831            if (flip_screen_get(screen->machine))
832            {
833               sx = 511 - sx;
834               sy = 255 - sy;
835            }
836 
837            col = ((col & 0xe0) >> 1) + (video_screen_get_frame_number(screen)/16 & 0x0f);
838 
839            if (sx >= cliprect->min_x && sx <= cliprect->max_x &&
840               sy >= cliprect->min_y && sy <= cliprect->max_y)
841               *BITMAP_ADDR16(bitmap, sy, sx) = 0xa00 + col;
842         }
843      }
844   }
845 
846   if (cps1_stars_enabled[1])
847   {
848      for (offs = 0;offs < stars_rom_size/2;offs++)
849      {
850         int col = stars_rom[8*offs];
851         if (col != 0x0f)
852         {
853            int sx = (offs / 256) * 32;
854            int sy = (offs % 256);
855            sx = (sx - stars1x + (col & 0x1f)) & 0x1ff;
856            sy = (sy - stars1y) & 0xff;
857            if (flip_screen_get(screen->machine))
858            {
859               sx = 511 - sx;
860               sy = 255 - sy;
861            }
862 
863            col = ((col & 0xe0) >> 1) + (video_screen_get_frame_number(screen)/16 & 0x0f);
864 
865            if (sx >= cliprect->min_x && sx <= cliprect->max_x &&
866               sy >= cliprect->min_y && sy <= cliprect->max_y)
867               *BITMAP_ADDR16(bitmap, sy, sx) = 0x800 + col;
868         }
869      }
870   }
871}
872 
873 
874static void cps1_render_layer(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int layer,int primask)
875{
876   switch (layer)
877   {
878      case 0:
879         cps1_render_sprites(machine,bitmap,cliprect);
880         break;
881      case 1:
882      case 2:
883      case 3:
884         tilemap_draw(bitmap,cliprect,cps1_bg_tilemap[layer-1],TILEMAP_DRAW_LAYER1,primask);
885         break;
886   }
887}
888 
889static void cps1_render_high_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer)
890{
891   switch (layer)
892   {
893      case 0:
894         /* there are no high priority sprites */
895         break;
896      case 1:
897      case 2:
898      case 3:
899         tilemap_draw(NULL,cliprect,cps1_bg_tilemap[layer-1],TILEMAP_DRAW_LAYER0,1);
900         break;
901   }
902}
903 
904 
905/***************************************************************************
906 
907    Refresh screen
908 
909***************************************************************************/
910 
911VIDEO_UPDATE( cps1 )
912{
913   int layercontrol,l0,l1,l2,l3;
914   int videocontrol = cps1_cps_a_regs[CPS1_VIDEOCONTROL];
915 
916 
917   flip_screen_set(screen->machine, videocontrol & 0x8000);
918 
919   layercontrol = cps1_cps_b_regs[cps1_game_config->layer_control/2];
920 
921   /* Get video memory base registers */
922   cps1_get_video_base();
923 
924   /* Find the offset of the last sprite in the sprite table */
925   cps1_find_last_sprite();
926   cps1_update_transmasks();
927 
928   tilemap_set_scrollx(cps1_bg_tilemap[0],0,cps1_scroll1x);
929   tilemap_set_scrolly(cps1_bg_tilemap[0],0,cps1_scroll1y);
930   if (videocontrol & 0x01)   /* linescroll enable */
931   {
932      int scrly=-cps1_scroll2y;
933      int i;
934      int otheroffs;
935 
936      tilemap_set_scroll_rows(cps1_bg_tilemap[1],1024);
937 
938      otheroffs = cps1_cps_a_regs[CPS1_ROWSCROLL_OFFS];
939 
940      for (i = 0;i < 256;i++)
941         tilemap_set_scrollx(cps1_bg_tilemap[1],(i - scrly) & 0x3ff,cps1_scroll2x + cps1_other[(i + otheroffs) & 0x3ff]);
942   }
943   else
944   {
945      tilemap_set_scroll_rows(cps1_bg_tilemap[1],1);
946      tilemap_set_scrollx(cps1_bg_tilemap[1],0,cps1_scroll2x);
947   }
948   tilemap_set_scrolly(cps1_bg_tilemap[1],0,cps1_scroll2y);
949   tilemap_set_scrollx(cps1_bg_tilemap[2],0,cps1_scroll3x);
950   tilemap_set_scrolly(cps1_bg_tilemap[2],0,cps1_scroll3y);
951 
952 
953   /* Blank screen */
954   bitmap_fill(bitmap,cliprect,0xbff);
955 
956   cps1_render_stars(screen, bitmap,cliprect);
957 
958   /* Draw layers (0 = sprites, 1-3 = tilemaps) */
959   l0 = (layercontrol >> 0x06) & 03;
960   l1 = (layercontrol >> 0x08) & 03;
961   l2 = (layercontrol >> 0x0a) & 03;
962   l3 = (layercontrol >> 0x0c) & 03;
963   bitmap_fill(priority_bitmap,cliprect,0);
964 
965   cps1_render_layer(screen->machine,bitmap,cliprect,l0,0);
966   if (l1 == 0) cps1_render_high_layer(bitmap,cliprect,l0); /* prepare mask for sprites */
967   cps1_render_layer(screen->machine,bitmap,cliprect,l1,0);
968   if (l2 == 0) cps1_render_high_layer(bitmap,cliprect,l1); /* prepare mask for sprites */
969   cps1_render_layer(screen->machine,bitmap,cliprect,l2,0);
970   if (l3 == 0) cps1_render_high_layer(bitmap,cliprect,l2); /* prepare mask for sprites */
971   cps1_render_layer(screen->machine,bitmap,cliprect,l3,0);
972 
973   return 0;
974}
975 
976VIDEO_EOF( cps1 )
977{
978   /* Get video memory base registers */
979   cps1_get_video_base();
980 
981   /* CPS1 sprites have to be delayed one frame */
982   memcpy(cps1_buffered_obj, cps1_obj, cps1_obj_size);
983}
src/mess/includes/cps1.h
r0r4374
1/* This must be called cps1.h, because kabuki.c includes it */
2 
3 
4 
5#ifndef _CPS1_H_
6#define _CPS1_H_
7 
8 
9/*----------- defined in machine/kabuki.c -----------*/
10 
11 
12void wof_decode(running_machine *machine);
13 
14 
15/*----------- defined in video/cps1.c -----------*/
16 
17 
18extern UINT16 *cps1_gfxram;     /* Video RAM */
19extern UINT16 *cps1_cps_a_regs;
20extern UINT16 *cps1_cps_b_regs;
21extern size_t cps1_gfxram_size;
22 
23WRITE16_HANDLER( cps1_cps_a_w );
24WRITE16_HANDLER( cps1_cps_b_w );
25READ16_HANDLER( cps1_cps_b_r );
26WRITE16_HANDLER( cps1_gfxram_w );
27 
28DRIVER_INIT( cps1 );
29 
30VIDEO_START( cps1 );
31VIDEO_UPDATE( cps1 );
32VIDEO_EOF( cps1 );
33 
34#endif
src/mess/messdriv.c
r4373r4374
175175   DRIVER( sfach )      /* CPS Changer (Street Fighter Alpha)            */
176176   DRIVER( sfzbch )   /* CPS Changer (Street Fighter ZERO Brazil)            */
177177   DRIVER( sfzch )      /* CPS Changer (Street Fighter ZERO)            */
178   DRIVER( wofch )      /* CPS Changer (Tenchi Wo Kurau II)            */
178179
179180   /* MAGNAVOX */
180181   DRIVER( odyssey2 )   /* Magnavox Odyssey 2 - 1978-1983               */
src/mess/mess.mak
r4373r4374
985985
986986$(MESSOBJ)/cpschngr.a: \
987987   $(MESS_DRIVERS)/cpschngr.o \
988   $(MAME_VIDEO)/cps1.o \
988   $(MESS_VIDEO)/cpschngr.o \
989989   $(MAME_MACHINE)/kabuki.o \
990990
991991$(MESSOBJ)/memotech.a:      \
src/mess/drivers/cpschngr.c
r4373r4374
11/***************************************************************************
22
3  Capcom System 1
4  ===============
3   CPS Changer
54
6  Driver provided by:
7  Paul Leaman (paul@vortexcomputing.demon.co.uk)
5   Although this is split off from MAME, it still uses machine/kabuki.c
6   This in turn includes cps1.h.
7   Therefore we must call our include by the same name, in order to
8   override the mame include, and thereby remove any compilation errors.
9   It also means we can get rid of the varios bodges of the past, and
10   no more ifdefs are needed in the mame code.
811
9  M680000 for game, Z80, YM-2151 and OKIM6295 for sound.
10
11  68000 clock speeds are unknown for all games (except where commented)
12
13merged Street Fighter Zero for MESS
14
1512***************************************************************************/
1613
1714#include "driver.h"
15#include "cpu/z80/z80.h"
1816#include "cpu/m68000/m68000.h"
19#include "cpu/z80/z80.h"
17#include "machine/eeprom.h"
18#include "sound/2151intf.h"
19#include "sound/okim6295.h"
20#include "sound/qsound.h"
21#include "cps1.h"
2022
21#ifdef GAME
22#undef GAME
23#endif
23static READ16_HANDLER( cps1_dsw_r )
24{
25   static const char *const dswname[] = { "IN0", "DSWA", "DSWB", "DSWC" };
26   int in = input_port_read(space->machine, dswname[offset]);
27   return (in << 8) | 0xff;
28}
2429
25#define GAME(YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME,FLAGS)
30static WRITE8_HANDLER( cps1_snd_bankswitch_w )
31{
32   UINT8 *RAM = memory_region(space->machine, "audiocpu");
33   int bankaddr;
2634
27#include "drivers/cps1.c"
35   bankaddr = ((data & 1) * 0x4000);
36   memory_set_bankptr(space->machine, 1,&RAM[0x10000 + bankaddr]);
37}
2838
39static WRITE8_DEVICE_HANDLER( cps1_oki_pin7_w )
40{
41   okim6295_set_pin7(device, (data & 1));
42}
2943
30void forogttn_dummy_function(running_machine *machine)
44static WRITE16_HANDLER( cps1_soundlatch_w )
3145{
32   /* Forgotten Worlds has extra inputs on the B-board CN-MOWS connector for the dial controls. */
33   memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x800040, 0x800041, 0, 0, forgottn_dial_0_reset_w);
34   memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x800048, 0x800049, 0, 0, forgottn_dial_1_reset_w);
35   memory_install_read16_handler (cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x800052, 0x800055, 0, 0, forgottn_dial_0_r);
36   memory_install_read16_handler (cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x80005a, 0x80005d, 0, 0, forgottn_dial_1_r);
37   cps1_hack_dsw_r(cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), 0, 0);
38   driver_init_sf2mdt(machine);
46   if (ACCESSING_BITS_0_7)
47      soundlatch_w(space,0,data & 0xff);
3948}
4049
41/***************************************************************************
50static WRITE16_HANDLER( cps1_soundlatch2_w )
51{
52   if (ACCESSING_BITS_0_7)
53      soundlatch2_w(space,0,data & 0xff);
54}
4255
43  Game driver(s)
56static WRITE16_HANDLER( cps1_coinctrl_w )
57{
58   if (ACCESSING_BITS_8_15)
59   {
60      coin_counter_w(0,data & 0x0100);
61      coin_counter_w(1,data & 0x0200);
62      coin_lockout_w(0,~data & 0x0400);
63      coin_lockout_w(1,~data & 0x0800);
64   }
65}
4466
45***************************************************************************/
67static WRITE16_HANDLER( cpsq_coinctrl2_w )
68{
69   if (ACCESSING_BITS_0_7)
70   {
71      coin_counter_w(2,data & 0x01);
72      coin_lockout_w(2,~data & 0x02);
73      coin_counter_w(3,data & 0x04);
74      coin_lockout_w(3,~data & 0x08);
75   }
76}
4677
47#define CODE_SIZE 0x400000
78static INTERRUPT_GEN( cps1_interrupt )
79{
80   /* Strider also has a IRQ4 handler. It is input port related, but the game */
81   /* works without it. It is the *only* CPS1 game to have that. */
82   cpu_set_input_line(device, 2, HOLD_LINE);
83}
4884
85/********************************************************************
86*
87*  Q Sound
88*  =======
89*
90********************************************************************/
91
92static UINT8 *qsound_sharedram1,*qsound_sharedram2;
93
94static INTERRUPT_GEN( cps1_qsound_interrupt )
95{
96   cpu_set_input_line(device, 2, HOLD_LINE);
97}
98
99
100static READ16_HANDLER( qsound_rom_r )
101{
102   UINT8 *rom = memory_region(space->machine, "user1");
103
104   if (rom) return rom[offset] | 0xff00;
105   else
106   {
107      popmessage("%06x: read sound ROM byte %04x",cpu_get_pc(space->cpu),offset);
108      return 0;
109   }
110}
111
112static READ16_HANDLER( qsound_sharedram1_r )
113{
114   return qsound_sharedram1[offset] | 0xff00;
115}
116
117static WRITE16_HANDLER( qsound_sharedram1_w )
118{
119   if (ACCESSING_BITS_0_7)
120      qsound_sharedram1[offset] = data;
121}
122
123static READ16_HANDLER( qsound_sharedram2_r )
124{
125   return qsound_sharedram2[offset] | 0xff00;
126}
127
128static WRITE16_HANDLER( qsound_sharedram2_w )
129{
130   if (ACCESSING_BITS_0_7)
131      qsound_sharedram2[offset] = data;
132}
133
134static WRITE8_HANDLER( qsound_banksw_w )
135{
136   UINT8 *RAM = memory_region(space->machine, "audiocpu");
137   int bankaddress=0x10000+((data&0x0f)*0x4000);
138   if (bankaddress >= memory_region_length(space->machine, "audiocpu"))
139   {
140      logerror("WARNING: Q sound bank overflow (%02x)\n", data);
141      bankaddress=0x10000;
142   }
143   memory_set_bankptr(space->machine, 1, &RAM[bankaddress]);
144}
145
146
147/********************************************************************
148*
149*  EEPROM
150*  ======
151*
152*   The EEPROM is accessed by a serial protocol using the register
153*   0xf1c006
154*
155********************************************************************/
156
157static const eeprom_interface qsound_eeprom_interface =
158{
159   7,      /* address bits */
160   8,      /* data bits */
161   "0110",   /*  read command */
162   "0101",   /* write command */
163   "0111"   /* erase command */
164};
165
166static NVRAM_HANDLER( qsound )
167{
168   if (read_or_write)
169      eeprom_save(file);
170   else
171   {
172      eeprom_init(machine, &qsound_eeprom_interface);
173
174      if (file)
175         eeprom_load(file);
176   }
177}
178
179static READ16_HANDLER( cps1_eeprom_port_r )
180{
181   return eeprom_read_bit();
182}
183
184static WRITE16_HANDLER( cps1_eeprom_port_w )
185{
186   if (ACCESSING_BITS_0_7)
187   {
188      /*
189        bit 0 = data
190        bit 6 = clock
191        bit 7 = cs
192        */
193      eeprom_write_bit(data & 0x01);
194      eeprom_set_cs_line((data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
195      eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
196   }
197}
198
199
200/***************************************
201
202   Address Maps
203
204****************************************/
205
206static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 16 )
207   AM_RANGE(0x000000, 0x3fffff) AM_ROM
208   AM_RANGE(0x800000, 0x800007) AM_READ_PORT("IN1")         /* Player input ports */
209   AM_RANGE(0x800018, 0x80001f) AM_READ(cps1_dsw_r)         /* System input ports / Dip Switches */
210   AM_RANGE(0x800020, 0x800021) AM_READNOP
211   AM_RANGE(0x800030, 0x800037) AM_WRITE(cps1_coinctrl_w)
212   AM_RANGE(0x800100, 0x80013f) AM_WRITE(cps1_cps_a_w) AM_BASE(&cps1_cps_a_regs)   /* CPS-A custom */
213   AM_RANGE(0x800140, 0x80017f) AM_READWRITE(cps1_cps_b_r, cps1_cps_b_w) AM_BASE(&cps1_cps_b_regs)
214   AM_RANGE(0x800180, 0x800187) AM_WRITE(cps1_soundlatch_w)   /* Sound command */
215   AM_RANGE(0x800188, 0x80018f) AM_WRITE(cps1_soundlatch2_w)   /* Sound timer fade */
216   AM_RANGE(0x900000, 0x92ffff) AM_RAM_WRITE(cps1_gfxram_w) AM_BASE(&cps1_gfxram) AM_SIZE(&cps1_gfxram_size)   /* SF2CE executes code from here */
217   AM_RANGE(0xff0000, 0xffffff) AM_RAM
218ADDRESS_MAP_END
219
220static ADDRESS_MAP_START( sub_map, ADDRESS_SPACE_PROGRAM, 8 )
221   AM_RANGE(0x0000, 0x7fff) AM_ROM
222   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK(1)
223   AM_RANGE(0xd000, 0xd7ff) AM_RAM
224   AM_RANGE(0xf000, 0xf001) AM_DEVREADWRITE(SOUND, "2151", ym2151_r, ym2151_w)
225   AM_RANGE(0xf002, 0xf002) AM_DEVREADWRITE(SOUND, "oki", okim6295_r, okim6295_w)
226   AM_RANGE(0xf004, 0xf004) AM_WRITE(cps1_snd_bankswitch_w)
227   AM_RANGE(0xf006, 0xf006) AM_DEVWRITE(SOUND, "oki", cps1_oki_pin7_w) /* controls pin 7 of OKI chip */
228   AM_RANGE(0xf008, 0xf008) AM_READ(soundlatch_r)   /* Sound command */
229   AM_RANGE(0xf00a, 0xf00a) AM_READ(soundlatch2_r) /* Sound timer fade */
230ADDRESS_MAP_END
231
232static ADDRESS_MAP_START( qsound_main_map, ADDRESS_SPACE_PROGRAM, 16 )
233   AM_RANGE(0x000000, 0x1fffff) AM_ROM
234   AM_RANGE(0x800000, 0x800007) AM_READ_PORT("IN1")         /* Player input ports */
235   AM_RANGE(0x800018, 0x80001f) AM_READ(cps1_dsw_r)         /* System input ports / Dip Switches */
236   AM_RANGE(0x800030, 0x800037) AM_WRITE(cps1_coinctrl_w)
237   AM_RANGE(0x800100, 0x80013f) AM_WRITE(cps1_cps_a_w) AM_BASE(&cps1_cps_a_regs)   /* CPS-A custom */
238   AM_RANGE(0x800140, 0x80017f) AM_READWRITE(cps1_cps_b_r, cps1_cps_b_w) AM_BASE(&cps1_cps_b_regs)   /* CPS-B custom (mapped by LWIO/IOB1 PAL on B-board) */
239   AM_RANGE(0x900000, 0x92ffff) AM_RAM_WRITE(cps1_gfxram_w) AM_BASE(&cps1_gfxram) AM_SIZE(&cps1_gfxram_size)   /* SF2CE executes code from here */
240   AM_RANGE(0xf00000, 0xf0ffff) AM_READ(qsound_rom_r)         /* Slammasters protection */
241   AM_RANGE(0xf18000, 0xf19fff) AM_READWRITE(qsound_sharedram1_r, qsound_sharedram1_w)  /* Q RAM */
242   AM_RANGE(0xf1c000, 0xf1c001) AM_READ_PORT("IN2")         /* Player 3 controls (later games) */
243   AM_RANGE(0xf1c002, 0xf1c003) AM_READ_PORT("IN3")         /* Player 4 controls ("Muscle Bombers") */
244   AM_RANGE(0xf1c004, 0xf1c005) AM_WRITE(cpsq_coinctrl2_w)      /* Coin control2 (later games) */
245   AM_RANGE(0xf1c006, 0xf1c007) AM_READWRITE(cps1_eeprom_port_r, cps1_eeprom_port_w)
246   AM_RANGE(0xf1e000, 0xf1ffff) AM_READWRITE(qsound_sharedram2_r, qsound_sharedram2_w)  /* Q RAM */
247   AM_RANGE(0xff0000, 0xffffff) AM_RAM
248ADDRESS_MAP_END
249
250static ADDRESS_MAP_START( qsound_sub_map, ADDRESS_SPACE_PROGRAM, 8 )   // used by cps2.c too
251   AM_RANGE(0x0000, 0x7fff) AM_ROM
252   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK(1)   /* banked (contains music data) */
253   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE(&qsound_sharedram1)
254   AM_RANGE(0xd000, 0xd002) AM_DEVWRITE(SOUND, "qsound", qsound_w)
255   AM_RANGE(0xd003, 0xd003) AM_WRITE(qsound_banksw_w)
256   AM_RANGE(0xd007, 0xd007) AM_DEVREAD(SOUND, "qsound", qsound_r)
257   AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE(&qsound_sharedram2)
258ADDRESS_MAP_END
259
260/***********************************************************
261
262   Inputs and Dips
263
264***********************************************************/
265
49266static INPUT_PORTS_START( sfzch )
50267   PORT_START("IN0")     /* IN0 */
51268   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_PLAYER(1)
r4373r4374
98315
99316/***************************************
100317
318   Graphics Decode
319
320****************************************/
321
322static const gfx_layout cps1_layout8x8 =
323{
324   8,8,
325   RGN_FRAC(1,1),
326   4,
327   { 0, 1, 2, 3 },
328   { 1*4, 0*4, 3*4, 2*4, 5*4, 4*4, 7*4, 6*4 },
329   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64 },
330   64*8
331};
332
333static const gfx_layout cps1_layout8x8_2 =
334{
335   8,8,
336   RGN_FRAC(1,1),
337   4,
338   { 0, 1, 2, 3 },
339   { 9*4, 8*4, 11*4, 10*4, 13*4, 12*4, 15*4, 14*4 },
340   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64 },
341   64*8
342};
343
344static GFXLAYOUT_RAW( cps1_layout16x16, 4, 16, 16, 8*8, 128*8 )
345static GFXLAYOUT_RAW( cps1_layout32x32, 4, 32, 32, 16*8, 512*8 )
346
347static GFXDECODE_START( cps1 )
348   GFXDECODE_ENTRY( "gfx", 0, cps1_layout8x8,   0, 0x100 )
349   GFXDECODE_ENTRY( "gfx", 0, cps1_layout8x8_2, 0, 0x100 )
350   GFXDECODE_ENTRY( "gfx", 0, cps1_layout16x16, 0, 0x100 )
351   GFXDECODE_ENTRY( "gfx", 0, cps1_layout32x32, 0, 0x100 )
352GFXDECODE_END
353
354
355
356static void cps1_irq_handler_mus(const device_config *device, int irq)
357{
358   cpu_set_input_line(device->machine->cpu[1],0,irq ? ASSERT_LINE : CLEAR_LINE);
359}
360
361static const ym2151_interface ym2151_config =
362{
363   cps1_irq_handler_mus
364};
365
366
367/********************************************************************
368*
369*  Machine Driver macro
370*  ====================
371*
372********************************************************************/
373
374static MACHINE_DRIVER_START( cps1_10MHz )
375
376   /* basic machine hardware */
377   MDRV_CPU_ADD("maincpu", M68000, 10000000)
378   MDRV_CPU_PROGRAM_MAP(main_map,0)
379   MDRV_CPU_VBLANK_INT("screen", cps1_interrupt)
380
381   MDRV_CPU_ADD("audiocpu", Z80, 3579545)
382   MDRV_CPU_PROGRAM_MAP(sub_map,0)
383
384   /* video hardware */
385   MDRV_SCREEN_ADD("screen", RASTER)
386   MDRV_SCREEN_REFRESH_RATE(59.61) /* verified on one of the input gates of the 74ls08@4J on GNG romboard 88620-b-2 */
387   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
388   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
389   MDRV_SCREEN_SIZE(64*8, 32*8)
390   MDRV_SCREEN_VISIBLE_AREA(8*8, (64-8)*8-1, 2*8, 30*8-1 )
391
392   MDRV_GFXDECODE(cps1)
393   MDRV_PALETTE_LENGTH(0xc00)
394
395   MDRV_VIDEO_START(cps1)
396   MDRV_VIDEO_EOF(cps1)
397   MDRV_VIDEO_UPDATE(cps1)
398
399   /* sound hardware */
400   MDRV_SPEAKER_STANDARD_MONO("mono")
401
402   MDRV_SOUND_ADD("2151", YM2151, 3579545)
403   MDRV_SOUND_CONFIG(ym2151_config)
404   MDRV_SOUND_ROUTE(0, "mono", 0.35)
405   MDRV_SOUND_ROUTE(1, "mono", 0.35)
406
407   MDRV_SOUND_ADD("oki", OKIM6295, 1000000)
408   MDRV_SOUND_CONFIG(okim6295_interface_pin7high) // pin 7 can be changed by the game code, see f006 on z80
409   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
410MACHINE_DRIVER_END
411
412static MACHINE_DRIVER_START( cps1_12MHz )
413
414   /* basic machine hardware */
415   MDRV_IMPORT_FROM(cps1_10MHz)
416
417   MDRV_CPU_REPLACE("maincpu", M68000, 12000000)
418MACHINE_DRIVER_END
419
420static MACHINE_DRIVER_START( qsound )
421
422   /* basic machine hardware */
423   MDRV_IMPORT_FROM(cps1_12MHz)
424
425   MDRV_CPU_REPLACE("maincpu", M68000, 12000000)   // 12MHz verified
426   MDRV_CPU_PROGRAM_MAP(qsound_main_map,0)
427   MDRV_CPU_VBLANK_INT("screen", cps1_qsound_interrupt)  /* ??? interrupts per frame */
428
429   MDRV_CPU_REPLACE("audiocpu", Z80, 8000000)
430   MDRV_CPU_PROGRAM_MAP(qsound_sub_map,0)
431   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 250)   /* ?? */
432
433   MDRV_NVRAM_HANDLER(qsound)
434
435   /* sound hardware */
436   MDRV_SPEAKER_REMOVE("mono")
437   MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
438
439   MDRV_SOUND_REMOVE("2151")
440   MDRV_SOUND_REMOVE("oki")
441
442   MDRV_SOUND_ADD("qsound", QSOUND, QSOUND_CLOCK)
443   MDRV_SOUND_ROUTE(0, "lspeaker", 1.0)
444   MDRV_SOUND_ROUTE(1, "rspeaker", 1.0)
445MACHINE_DRIVER_END
446
447/***************************************
448
449   Driver Initialisation
450
451****************************************/
452
453
454static DRIVER_INIT( wof )
455{
456   wof_decode(machine);
457   DRIVER_INIT_CALL(cps1);
458}
459
460/***************************************
461
101462   Roms
102463
103464***************************************/
104465
466#define CODE_SIZE 0x400000
105467
106468ROM_START( sfach )
107469   ROM_REGION( CODE_SIZE, "maincpu", 0 )      /* 68000 code */
r4373r4374
242604
243605/***************************************************************************
244606
245  Game driver(s)
607   Game driver(s)
246608
247609***************************************************************************/
248610
r4373r4374
250612CONS( 1995, sfach,    sfzch,    0,   cps1_10MHz, sfzch,    cps1,     NULL,   "Capcom", "CPS Changer - Street Fighter Alpha - Warriors' Dreams (Publicity US 950727)", 0 )
251613CONS( 1995, sfzch,    0,        0,   cps1_10MHz, sfzch,    cps1,     NULL,   "Capcom", "CPS Changer - Street Fighter Zero (Japan 951020)", 0 )
252614CONS( 1995, sfzbch,   sfzch,    0,   cps1_10MHz, sfzch,    cps1,     NULL,   "Hack",   "CPS Changer - Street Fighter Alpha (Brazil 950727)", 0 )
615CONS( 1995, wofch,    0,        0,   qsound,     sfzch,    wof,      NULL,   "Capcom", "CPS Changer - Tenchi Wo Kurau II (Japan 921031)", 0 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team