Previous 15994 Revisions Next

r4408 Tuesday 10th March, 2009 at 04:54:17 UTC by Nathan Woods
Cleanups [Atari Ace]
[src/mess/audio]spchroms.c spchroms.h
[src/mess/drivers]pdp1.c pentagon.c scorpion.c
[src/mess/includes]adam.h b2m.h dai.h irisha.h special.h spectrum.h vectrex.h
[src/mess/machine]coco.c irisha.c mz700.c z80dart.c
[src/mess/tools/imgtool/modules]vzdos.c
[src/mess/video]aim65.c cpschngr.c irisha.c ted7360.h

src/mess/tools/imgtool/modules/vzdos.c
r4407r4408
361361static imgtoolerr_t vzdos_write_formatted_sector(imgtool_image *img, int track, int sector)
362362{
363363   int ret;
364   UINT8 sector_data[DATA_SIZE + 4];
364   UINT8 sector_data[DATA_SIZE + 4 + 24];
365365
366   static UINT8 sector_header[24] = {
366   static const UINT8 sector_header[24] = {
367367      0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFE, 0xE7,
368368      0x18, 0xC3, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
369369      0x80, 0x80, 0x80, 0x00, 0xC3, 0x18, 0xE7, 0xFE
370370   };
371371
372372   memset(sector_data, 0x00, sizeof(sector_data));
373   memcpy(sector_data, sector_header, sizeof(sector_header));
373374
374   sector_header[10] = (UINT8) track;         /* current track */
375   sector_header[11] = (UINT8) sector;         /* current sector */
376   sector_header[12] = (UINT8) track + sector;   /* checksum-8 */
375   sector_data[10] = (UINT8) track;         /* current track */
376   sector_data[11] = (UINT8) sector;         /* current sector */
377   sector_data[12] = (UINT8) track + sector;   /* checksum-8 */
377378
378   ret = floppy_write_sector(imgtool_floppy(img), 0, track, sector_order[sector], 0, sector_header, sizeof(sector_header));
379   ret = floppy_write_sector(imgtool_floppy(img), 0, track, sector_order[sector], 0, sector_data, sizeof(sector_data));
379380   if (ret) return ret;
380381
381   ret = floppy_write_sector(imgtool_floppy(img), 0, track, sector_order[sector], sizeof(sector_header), sector_data, sizeof(sector_data));
382   if (ret) return ret;
383
384382   return IMGTOOLERR_SUCCESS;
385383}
386384
src/mess/audio/spchroms.c
r4407r4408
1111   Interfacing it with the tms5110 would make sense, too.
1212*/
1313
14#include "driver.h"
1415#include "spchroms.h"
15#include "driver.h"
1616
1717static UINT8 *speechrom_data = NULL;   /* pointer to speech ROM data */
1818static unsigned long speechROMlen = 0;   /* length of data pointed by speechrom_data, from 0 to 2^18 */
src/mess/audio/spchroms.h
r4407r4408
1#include "mame.h"
1#ifndef __SPCHROMS_H
2#define __SPCHROMS_H
23
34typedef struct spchroms_interface
45{
r4407r4408
1011int spchroms_read(const device_config *device, int count);
1112void spchroms_load_address(const device_config *device, int data);
1213void spchroms_read_and_branch(const device_config *device);
14
15#endif
src/mess/video/cpschngr.c
r4407r4408
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}
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
294#ifdef UNUSED_FUNCTION
295static void unshuffle(UINT64 *buf,int len)
296{
297   int i;
298   UINT64 t;
299
300   if (len == 2) return;
301
302   assert(len % 4 == 0);   /* must not happen */
303
304   len /= 2;
305
306   unshuffle(buf,len);
307   unshuffle(buf + len,len);
308
309   for (i = 0;i < len/2;i++)
310   {
311      t = buf[len/2 + i];
312      buf[len/2 + i] = buf[len + i];
313      buf[len + i] = t;
314   }
315}
316#endif
317
318
319DRIVER_INIT( cps1 )
320{
321   cps1_gfx_decode(machine);
322}
323
324
325static void cps1_get_video_base(void )
326{
327   int layercontrol, videocontrol, scroll1xoff, scroll2xoff, scroll3xoff;
328
329   /* Re-calculate the VIDEO RAM base */
330   if (cps1_scroll1 != cps1_base(CPS1_SCROLL1_BASE,cps1_scroll_size))
331   {
332      cps1_scroll1 = cps1_base(CPS1_SCROLL1_BASE,cps1_scroll_size);
333      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[0]);
334   }
335   if (cps1_scroll2 != cps1_base(CPS1_SCROLL2_BASE,cps1_scroll_size))
336   {
337      cps1_scroll2 = cps1_base(CPS1_SCROLL2_BASE,cps1_scroll_size);
338      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[1]);
339   }
340   if (cps1_scroll3 != cps1_base(CPS1_SCROLL3_BASE,cps1_scroll_size))
341   {
342      cps1_scroll3 = cps1_base(CPS1_SCROLL3_BASE,cps1_scroll_size);
343      tilemap_mark_all_tiles_dirty(cps1_bg_tilemap[2]);
344   }
345
346   /* Some of the sf2 hacks use only sprite port 0x9100 and the scroll layers are offset */
347   if (cps1_game_config->bootleg_kludge == 1)
348   {
349      cps1_cps_a_regs[CPS1_OBJ_BASE] = 0x9100;
350      cps1_obj = cps1_base(CPS1_OBJ_BASE, cps1_obj_size);
351      scroll1xoff = -0x0c;
352      scroll2xoff = -0x0e;
353      scroll3xoff = -0x10;
354   }
355   else
356   {
357      cps1_obj = cps1_base(CPS1_OBJ_BASE, cps1_obj_size);
358      scroll1xoff = 0;
359      scroll2xoff = 0;
360      scroll3xoff = 0;
361   }
362   cps1_other = cps1_base(CPS1_OTHER_BASE,cps1_other_size);
363
364   /* Get scroll values */
365   cps1_scroll1x = cps1_cps_a_regs[CPS1_SCROLL1_SCROLLX] + scroll1xoff;
366   cps1_scroll1y = cps1_cps_a_regs[CPS1_SCROLL1_SCROLLY];
367   cps1_scroll2x = cps1_cps_a_regs[CPS1_SCROLL2_SCROLLX] + scroll2xoff;
368   cps1_scroll2y = cps1_cps_a_regs[CPS1_SCROLL2_SCROLLY];
369   cps1_scroll3x = cps1_cps_a_regs[CPS1_SCROLL3_SCROLLX] + scroll3xoff;
370   cps1_scroll3y = cps1_cps_a_regs[CPS1_SCROLL3_SCROLLY];
371   stars1x = cps1_cps_a_regs[CPS1_STARS1_SCROLLX];
372   stars1y = cps1_cps_a_regs[CPS1_STARS1_SCROLLY];
373   stars2x = cps1_cps_a_regs[CPS1_STARS2_SCROLLX];
374   stars2y = cps1_cps_a_regs[CPS1_STARS2_SCROLLY];
375
376   /* Get layer enable bits */
377   layercontrol = cps1_cps_b_regs[cps1_game_config->layer_control/2];
378   videocontrol = cps1_cps_a_regs[CPS1_VIDEOCONTROL];
379   tilemap_set_enable(cps1_bg_tilemap[0],layercontrol & cps1_game_config->layer_enable_mask[0]);
380   tilemap_set_enable(cps1_bg_tilemap[1],(layercontrol & cps1_game_config->layer_enable_mask[1]) && (videocontrol & 4));
381   tilemap_set_enable(cps1_bg_tilemap[2],(layercontrol & cps1_game_config->layer_enable_mask[2]) && (videocontrol & 8));
382   cps1_stars_enabled[0] = layercontrol & cps1_game_config->layer_enable_mask[3];
383   cps1_stars_enabled[1] = layercontrol & cps1_game_config->layer_enable_mask[4];
384}
385
386
387WRITE16_HANDLER( cps1_gfxram_w )
388{
389   int page = (offset >> 7) & 0x3c0;
390   COMBINE_DATA(&cps1_gfxram[offset]);
391
392   if (page == (cps1_cps_a_regs[CPS1_SCROLL1_BASE] & 0x3c0))
393      tilemap_mark_tile_dirty(cps1_bg_tilemap[0],offset/2 & 0x0fff);
394   if (page == (cps1_cps_a_regs[CPS1_SCROLL2_BASE] & 0x3c0))
395      tilemap_mark_tile_dirty(cps1_bg_tilemap[1],offset/2 & 0x0fff);
396   if (page == (cps1_cps_a_regs[CPS1_SCROLL3_BASE] & 0x3c0))
397      tilemap_mark_tile_dirty(cps1_bg_tilemap[2],offset/2 & 0x0fff);
398}
399
400
401
402static int gfxrom_bank_mapper(running_machine *machine, int type, int code)
403{
404   const struct gfx_range *range = cps1_game_config->bank_mapper;
405   int shift = 0;
406
407   assert(range);
408
409   switch (type)
410   {
411      case GFXTYPE_SPRITES: shift = 1; break;
412      case GFXTYPE_SCROLL1: shift = 0; break;
413      case GFXTYPE_SCROLL2: shift = 1; break;
414      case GFXTYPE_SCROLL3: shift = 3; break;
415   }
416
417   code <<= shift;
418
419   while (range->type)
420   {
421      if (code >= range->start && code <= range->end)
422      {
423         if (range->type & type)
424         {
425            int base = 0;
426            int i;
427
428            for (i = 0; i < range->bank; ++i)
429               base += cps1_game_config->bank_sizes[i];
430
431            return (base + (code & (cps1_game_config->bank_sizes[range->bank] - 1))) >> shift;
432         }
433      }
434
435      ++range;
436   }
437
438   return -1;
439}
440
441
442/***************************************************************************
443
444  Start the video hardware emulation.
445
446***************************************************************************/
447
448static TILEMAP_MAPPER( tilemap0_scan )
449{
450   /* logical (col,row) -> memory offset */
451   return (row & 0x1f) + ((col & 0x3f) << 5) + ((row & 0x20) << 6);
452}
453
454static TILEMAP_MAPPER( tilemap1_scan )
455{
456   /* logical (col,row) -> memory offset */
457   return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x30) << 6);
458}
459
460static TILEMAP_MAPPER( tilemap2_scan )
461{
462   /* logical (col,row) -> memory offset */
463   return (row & 0x07) + ((col & 0x3f) << 3) + ((row & 0x38) << 6);
464}
465
466static UINT8 empty_tile8x8[8*8];
467static UINT8 empty_tile[32*32/2];
468
469static TILE_GET_INFO( get_tile0_info )
470{
471   int code = cps1_scroll1[2*tile_index];
472   int attr = cps1_scroll1[2*tile_index+1];
473   int gfxset;
474
475   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL1, code);
476
477   /* allows us to reproduce a problem seen with a ffight board where USA and Japanese
478         roms have been mixed to be reproduced (ffightua) -- it looks like each column
479         should alternate between the left and right side of the 16x16 tiles */
480   gfxset = (tile_index & 0x20) >> 5;
481
482   SET_TILE_INFO(
483         gfxset,
484         code,
485         (attr & 0x1f) + 0x20,
486         TILE_FLIPYX((attr & 0x60) >> 5));
487   tileinfo->group = (attr & 0x0180) >> 7;
488
489   // for out of range tiles, switch to fully transparent data
490   // (but still call SET_TILE_INFO, otherwise problems might occur on boot e.g. unsquad)
491   if (code == -1)
492      tileinfo->pen_data = empty_tile8x8;
493}
494
495static TILE_GET_INFO( get_tile1_info )
496{
497   int code = cps1_scroll2[2*tile_index];
498   int attr = cps1_scroll2[2*tile_index+1];
499
500   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL2, code);
501
502   SET_TILE_INFO(
503         2,
504         code,
505         (attr & 0x1f) + 0x40,
506         TILE_FLIPYX((attr & 0x60) >> 5));
507   tileinfo->group = (attr & 0x0180) >> 7;
508
509   // for out of range tiles, switch to fully transparent data
510   if (code == -1)
511      tileinfo->pen_data = empty_tile;
512}
513
514static TILE_GET_INFO( get_tile2_info )
515{
516   int code = cps1_scroll3[2*tile_index] & 0x3fff;
517   int attr = cps1_scroll3[2*tile_index+1];
518
519   code = gfxrom_bank_mapper(machine, GFXTYPE_SCROLL3, code);
520
521   SET_TILE_INFO(
522         3,
523         code,
524         (attr & 0x1f) + 0x60,
525         TILE_FLIPYX((attr & 0x60) >> 5));
526   tileinfo->group = (attr & 0x0180) >> 7;
527
528   // for out of range tiles, switch to fully transparent data
529   // (but still call SET_TILE_INFO, otherwise problems might occur on boot e.g. unsquad)
530   if (code == -1)
531      tileinfo->pen_data = empty_tile;
532}
533
534
535
536static void cps1_update_transmasks(void)
537{
538   int i;
539
540   for (i = 0;i < 4;i++)
541   {
542      int mask;
543
544      /* Get transparency registers */
545      if (cps1_game_config->priority[i] != -1)
546         mask = cps1_cps_b_regs[cps1_game_config->priority[i]/2] ^ 0xffff;
547      else mask = 0xffff;   /* completely transparent if priority masks not defined (qad) */
548
549      tilemap_set_transmask(cps1_bg_tilemap[0],i,mask,0x8000);
550      tilemap_set_transmask(cps1_bg_tilemap[1],i,mask,0x8000);
551      tilemap_set_transmask(cps1_bg_tilemap[2],i,mask,0x8000);
552   }
553}
554
555VIDEO_START( cps1 )
556{
557   int i;
558
559   MACHINE_RESET_CALL(cps);
560
561   cps1_bg_tilemap[0] = tilemap_create(machine, get_tile0_info,tilemap0_scan, 8, 8,64,64);
562   cps1_bg_tilemap[1] = tilemap_create(machine, get_tile1_info,tilemap1_scan,16,16,64,64);
563   cps1_bg_tilemap[2] = tilemap_create(machine, get_tile2_info,tilemap2_scan,32,32,64,64);
564
565   /* front masks will change at runtime to handle sprite occluding */
566   cps1_update_transmasks();
567
568   memset(empty_tile8x8,0x0f,sizeof(empty_tile8x8));
569   memset(empty_tile,0xff,sizeof(empty_tile));   // 16x16 and 32x32 use packed graphics, 8x8 does not
570
571   for (i = 0;i < cps1_palette_entries*16;i++)
572   {
573      palette_set_color(machine,i,MAKE_RGB(0,0,0));
574   }
575
576   cps1_buffered_obj = auto_malloc (cps1_obj_size);
577   memset(cps1_buffered_obj, 0x00, cps1_obj_size);
578
579   memset(cps1_gfxram, 0, cps1_gfxram_size);   /* Clear GFX RAM */
580   memset(cps1_cps_a_regs, 0, 0x40);   /* Clear CPS-A registers */
581   memset(cps1_cps_b_regs, 0, 0x40);   /* Clear CPS-B registers */
582
583   /* Put in some defaults */
584   cps1_cps_a_regs[CPS1_OBJ_BASE]     = 0x9200;
585   cps1_cps_a_regs[CPS1_SCROLL1_BASE] = 0x9000;
586   cps1_cps_a_regs[CPS1_SCROLL2_BASE] = 0x9040;
587   cps1_cps_a_regs[CPS1_SCROLL3_BASE] = 0x9080;
588   cps1_cps_a_regs[CPS1_OTHER_BASE]   = 0x9100;
589
590   assert_always(cps1_game_config, "cps1_game_config hasn't been set up yet");
591
592   /* Set up old base */
593   cps1_get_video_base();   /* Calculate base pointers */
594   cps1_get_video_base();   /* Calculate old base pointers */
595}
596
597
598
599/***************************************************************************
600
601  Build palette from palette RAM
602
603  12 bit RGB with a 4 bit brightness value.
604
605***************************************************************************/
606
607static void cps1_build_palette(running_machine *machine, const UINT16* const palette_base)
608{
609   int offset, page;
610   const UINT16 *palette_ram = palette_base;
611
612   int ctrl = cps1_cps_b_regs[cps1_game_config->palette_control/2];
613
614   for (page = 0; page < 6; ++page)
615   {
616      if (BIT(ctrl,page))
617      {
618         for (offset = 0; offset < 0x200; ++offset)
619         {
620            int palette = *(palette_ram++);
621            int r, g, b, bright;
622
623            // from my understanding of the schematics, when the 'brightness'
624            // component is set to 0 it should reduce brightness to 1/3
625
626            bright = 0x0f + ((palette>>12)<<1);
627
628            r = ((palette>>8)&0x0f) * 0x11 * bright / 0x2d;
629            g = ((palette>>4)&0x0f) * 0x11 * bright / 0x2d;
630            b = ((palette>>0)&0x0f) * 0x11 * bright / 0x2d;
631
632            palette_set_color (machine, 0x200*page + offset, MAKE_RGB(r, g, b));
633         }
634      }
635      else
636      {
637         // skip page in gfxram, but only if we have already copied at least one page
638         if (palette_ram != palette_base)
639            palette_ram += 0x200;
640      }
641   }
642}
643
644static void cps1_find_last_sprite(void)    /* Find the offset of last sprite */
645{
646   int offset=0;
647   /* Locate the end of table marker */
648   while (offset < cps1_obj_size/2)
649   {
650        int colour=cps1_buffered_obj[offset+3];
651      if ((colour & 0xff00) == 0xff00)
652      {
653         /* Marker found. This is the last sprite. */
654         cps1_last_sprite_offset=offset-4;
655         return;
656      }
657        offset+=4;
658   }
659   /* Sprites must use full sprite RAM */
660   cps1_last_sprite_offset=cps1_obj_size/2-4;
661}
662
663
664static void cps1_render_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
665{
666#define DRAWSPRITE(CODE,COLOR,FLIPX,FLIPY,SX,SY)               \
667{                                                   \
668   if (flip_screen_get(machine))                                 \
669      pdrawgfx(bitmap,machine->gfx[2],                     \
670            CODE,                                    \
671            COLOR,                                    \
672            !(FLIPX),!(FLIPY),                           \
673            511-16-(SX),255-16-(SY),                     \
674            cliprect,TRANSPARENCY_PEN,15,0x02);               \
675   else                                             \
676      pdrawgfx(bitmap,machine->gfx[2],                     \
677            CODE,                                    \
678            COLOR,                                    \
679            FLIPX,FLIPY,                              \
680            SX,SY,                                    \
681            cliprect,TRANSPARENCY_PEN,15,0x02);               \
682}
683
684
685   int i, baseadd;
686   UINT16 *base=cps1_buffered_obj;
687
688   /* some sf2 hacks draw the sprites in reverse order */
689   if (cps1_game_config->bootleg_kludge == 1)
690   {
691      base += cps1_last_sprite_offset;
692      baseadd = -4;
693   }
694   else
695   {
696      baseadd = 4;
697   }
698
699   for (i=cps1_last_sprite_offset; i>=0; i-=4)
700   {
701      int x=*(base+0);
702      int y=*(base+1);
703      int code  =*(base+2);
704      int colour=*(base+3);
705      int col=colour&0x1f;
706
707      code = gfxrom_bank_mapper(machine, GFXTYPE_SPRITES, code);
708
709      if (code != -1)
710      {
711         if (colour & 0xff00 )
712         {
713            /* handle blocked sprites */
714            int nx=(colour & 0x0f00) >> 8;
715            int ny=(colour & 0xf000) >> 12;
716            int nxs,nys,sx,sy;
717            nx++;
718            ny++;
719
720            if (colour & 0x40)
721            {
722               /* Y flip */
723               if (colour &0x20)
724               {
725                  for (nys=0; nys<ny; nys++)
726                  {
727                     for (nxs=0; nxs<nx; nxs++)
728                     {
729                        sx = (x+nxs*16) & 0x1ff;
730                        sy = (y+nys*16) & 0x1ff;
731
732                        DRAWSPRITE(
733                              (code & ~0xf) + ((code + (nx-1) - nxs) & 0xf) + 0x10*(ny-1-nys),
734                              (col&0x1f),
735                              1,1,
736                              sx,sy);
737                     }
738                  }
739               }
740               else
741               {
742                  for (nys=0; nys<ny; nys++)
743                  {
744                     for (nxs=0; nxs<nx; nxs++)
745                     {
746                        sx = (x+nxs*16) & 0x1ff;
747                        sy = (y+nys*16) & 0x1ff;
748
749                        DRAWSPRITE(
750                              (code & ~0xf) + ((code + nxs) & 0xf) + 0x10*(ny-1-nys),
751                              (col&0x1f),
752                              0,1,
753                              sx,sy);
754                     }
755                  }
756               }
757            }
758            else
759            {
760               if (colour &0x20)
761               {
762                  for (nys=0; nys<ny; nys++)
763                  {
764                     for (nxs=0; nxs<nx; nxs++)
765                     {
766                        sx = (x+nxs*16) & 0x1ff;
767                        sy = (y+nys*16) & 0x1ff;
768
769                        DRAWSPRITE(
770                              (code & ~0xf) + ((code + (nx-1) - nxs) & 0xf) + 0x10*nys,
771                              (col&0x1f),
772                              1,0,
773                              sx,sy);
774                     }
775                  }
776               }
777               else
778               {
779                  for (nys=0; nys<ny; nys++)
780                  {
781                     for (nxs=0; nxs<nx; nxs++)
782                     {
783                        sx = (x+nxs*16) & 0x1ff;
784                        sy = (y+nys*16) & 0x1ff;
785
786                        DRAWSPRITE(
787                              (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.
788                              (col&0x1f),
789                              0,0,
790                              sx,sy);
791                     }
792                  }
793               }
794            }
795         }
796         else
797         {
798            /* Simple case... 1 sprite */
799                  DRAWSPRITE(
800                  code,
801                  (col&0x1f),
802                  colour&0x20,colour&0x40,
803                  x & 0x1ff,y & 0x1ff);
804         }
805      }
806      base += baseadd;
807   }
808#undef DRAWSPRITE
809}
810
811
812static void cps1_render_stars(const device_config *screen, bitmap_t *bitmap,const rectangle *cliprect)
813{
814   int offs;
815   UINT8 *stars_rom = memory_region(screen->machine, "stars");
816
817   if (!stars_rom && (cps1_stars_enabled[0] || cps1_stars_enabled[1]))
818   {
819      return;
820   }
821
822   if (cps1_stars_enabled[0])
823   {
824      for (offs = 0;offs < stars_rom_size/2;offs++)
825      {
826         int col = stars_rom[8*offs+4];
827         if (col != 0x0f)
828         {
829            int sx = (offs / 256) * 32;
830            int sy = (offs % 256);
831            sx = (sx - stars2x + (col & 0x1f)) & 0x1ff;
832            sy = (sy - stars2y) & 0xff;
833            if (flip_screen_get(screen->machine))
834            {
835               sx = 511 - sx;
836               sy = 255 - sy;
837            }
838
839            col = ((col & 0xe0) >> 1) + (video_screen_get_frame_number(screen)/16 & 0x0f);
840
841            if (sx >= cliprect->min_x && sx <= cliprect->max_x &&
842               sy >= cliprect->min_y && sy <= cliprect->max_y)
843               *BITMAP_ADDR16(bitmap, sy, sx) = 0xa00 + col;
844         }
845      }
846   }
847
848   if (cps1_stars_enabled[1])
849   {
850      for (offs = 0;offs < stars_rom_size/2;offs++)
851      {
852         int col = stars_rom[8*offs];
853         if (col != 0x0f)
854         {
855            int sx = (offs / 256) * 32;
856            int sy = (offs % 256);
857            sx = (sx - stars1x + (col & 0x1f)) & 0x1ff;
858            sy = (sy - stars1y) & 0xff;
859            if (flip_screen_get(screen->machine))
860            {
861               sx = 511 - sx;
862               sy = 255 - sy;
863            }
864
865            col = ((col & 0xe0) >> 1) + (video_screen_get_frame_number(screen)/16 & 0x0f);
866
867            if (sx >= cliprect->min_x && sx <= cliprect->max_x &&
868               sy >= cliprect->min_y && sy <= cliprect->max_y)
869               *BITMAP_ADDR16(bitmap, sy, sx) = 0x800 + col;
870         }
871      }
872   }
873}
874
875
876static void cps1_render_layer(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int layer,int primask)
877{
878   switch (layer)
879   {
880      case 0:
881         cps1_render_sprites(machine,bitmap,cliprect);
882         break;
883      case 1:
884      case 2:
885      case 3:
886         tilemap_draw(bitmap,cliprect,cps1_bg_tilemap[layer-1],TILEMAP_DRAW_LAYER1,primask);
887         break;
888   }
889}
890
891static void cps1_render_high_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer)
892{
893   switch (layer)
894   {
895      case 0:
896         /* there are no high priority sprites */
897         break;
898      case 1:
899      case 2:
900      case 3:
901         tilemap_draw(NULL,cliprect,cps1_bg_tilemap[layer-1],TILEMAP_DRAW_LAYER0,1);
902         break;
903   }
904}
905
906
907/***************************************************************************
908
909    Refresh screen
910
911***************************************************************************/
912
913VIDEO_UPDATE( cps1 )
914{
915   int layercontrol,l0,l1,l2,l3;
916   int videocontrol = cps1_cps_a_regs[CPS1_VIDEOCONTROL];
917
918
919   flip_screen_set(screen->machine, videocontrol & 0x8000);
920
921   layercontrol = cps1_cps_b_regs[cps1_game_config->layer_control/2];
922
923   /* Get video memory base registers */
924   cps1_get_video_base();
925
926   /* Find the offset of the last sprite in the sprite table */
927   cps1_find_last_sprite();
928   cps1_update_transmasks();
929
930   tilemap_set_scrollx(cps1_bg_tilemap[0],0,cps1_scroll1x);
931   tilemap_set_scrolly(cps1_bg_tilemap[0],0,cps1_scroll1y);
932   if (videocontrol & 0x01)   /* linescroll enable */
933   {
934      int scrly=-cps1_scroll2y;
935      int i;
936      int otheroffs;
937
938      tilemap_set_scroll_rows(cps1_bg_tilemap[1],1024);
939
940      otheroffs = cps1_cps_a_regs[CPS1_ROWSCROLL_OFFS];
941
942      for (i = 0;i < 256;i++)
943         tilemap_set_scrollx(cps1_bg_tilemap[1],(i - scrly) & 0x3ff,cps1_scroll2x + cps1_other[(i + otheroffs) & 0x3ff]);
944   }
945   else
946   {
947      tilemap_set_scroll_rows(cps1_bg_tilemap[1],1);
948      tilemap_set_scrollx(cps1_bg_tilemap[1],0,cps1_scroll2x);
949   }
950   tilemap_set_scrolly(cps1_bg_tilemap[1],0,cps1_scroll2y);
951   tilemap_set_scrollx(cps1_bg_tilemap[2],0,cps1_scroll3x);
952   tilemap_set_scrolly(cps1_bg_tilemap[2],0,cps1_scroll3y);
953
954
955   /* Blank screen */
956   bitmap_fill(bitmap,cliprect,0xbff);
957
958   cps1_render_stars(screen, bitmap,cliprect);
959
960   /* Draw layers (0 = sprites, 1-3 = tilemaps) */
961   l0 = (layercontrol >> 0x06) & 03;
962   l1 = (layercontrol >> 0x08) & 03;
963   l2 = (layercontrol >> 0x0a) & 03;
964   l3 = (layercontrol >> 0x0c) & 03;
965   bitmap_fill(priority_bitmap,cliprect,0);
966
967   cps1_render_layer(screen->machine,bitmap,cliprect,l0,0);
968   if (l1 == 0) cps1_render_high_layer(bitmap,cliprect,l0); /* prepare mask for sprites */
969   cps1_render_layer(screen->machine,bitmap,cliprect,l1,0);
970   if (l2 == 0) cps1_render_high_layer(bitmap,cliprect,l1); /* prepare mask for sprites */
971   cps1_render_layer(screen->machine,bitmap,cliprect,l2,0);
972   if (l3 == 0) cps1_render_high_layer(bitmap,cliprect,l2); /* prepare mask for sprites */
973   cps1_render_layer(screen->machine,bitmap,cliprect,l3,0);
974
975   return 0;
976}
977
978VIDEO_EOF( cps1 )
979{
980   /* Get video memory base registers */
981   cps1_get_video_base();
982
983   /* CPS1 sprites have to be delayed one frame */
984   memcpy(cps1_buffered_obj, cps1_obj, cps1_obj_size);
985}
src/mess/video/aim65.c
r4407r4408
8282   flag_a=flag_b=0;
8383}
8484
85TIMER_CALLBACK(aim65_printer_timer)
85static TIMER_CALLBACK(aim65_printer_timer)
8686{
8787   const device_config *via_0 = devtag_get_device(machine, "via6522_0");
8888
src/mess/video/irisha.c
r4407r4408
88
99
1010#include "driver.h"
11#include "includes/irisha.h"
1112
1213
1314VIDEO_START( irisha )
src/mess/video/ted7360.h
r4407r4408
1313#ifndef TED7360_H_
1414#define TED7360_H_
1515
16#include "mame.h"
1716
18
1917/*----------- defined in video/ted7360.c -----------*/
2018
2119/* call to init videodriver */
src/mess/includes/dai.h
r4407r4408
77#ifndef DAI_H_
88#define DAI_H_
99
10#include "mame.h"
1110#include "machine/8255ppi.h"
1211#include "machine/tms5501.h"
1312
src/mess/includes/adam.h
r4407r4408
4040READ8_HANDLER ( adam_video_r );
4141WRITE8_HANDLER ( adam_video_w );
4242WRITE8_HANDLER ( adam_common_writes_w );
43READ8_HANDLER  ( adam_master6801_ram_r );
44WRITE8_HANDLER ( adam_master6801_ram_w );
4543
4644
4745#endif /* ADAM_H_ */
src/mess/includes/b2m.h
r4407r4408
77#ifndef b2m_H_
88#define b2m_H_
99
10#include "mame.h"
1110#include "machine/8255ppi.h"
1211#include "machine/pit8253.h"
1312#include "machine/pic8259.h"
r4407r4408
2524extern const ppi8255_interface b2m_ppi8255_interface_2;
2625extern const ppi8255_interface b2m_ppi8255_interface_3;
2726
28extern void b2m_sh_change_clock(double);
29
3027extern DRIVER_INIT( b2m );
3128extern MACHINE_START( b2m );
3229extern MACHINE_RESET( b2m );
src/mess/includes/vectrex.h
r4407r4408
1111
1212/*----------- defined in machine/vectrex.c -----------*/
1313
14extern const via6522_interface vectrex_via6522_interface;
15extern const via6522_interface spectrum1_via6522_interface;
16
1714DEVICE_IMAGE_LOAD( vectrex_cart );
1815
1916extern int vectrex_imager_status;
r4407r4408
3936
4037/*----------- defined in video/vectrex.c -----------*/
4138
39extern const via6522_interface vectrex_via6522_interface;
40extern const via6522_interface spectrum1_via6522_interface;
41
4242VIDEO_START( vectrex );
4343VIDEO_UPDATE( vectrex );
4444
src/mess/includes/spectrum.h
r4407r4408
7373
7474INPUT_PORTS_EXTERN( spectrum );
7575MACHINE_DRIVER_EXTERN( spectrum );
76SYSTEM_CONFIG_EXTERN(spectrum)
7776
7877extern READ8_HANDLER(spectrum_port_1f_r);
7978extern READ8_HANDLER(spectrum_port_7f_r);
r4407r4408
111110
112111extern unsigned char *spectrum_video_ram;
113112
114extern const gfx_layout spectrum_charlayout;
115
116113/*----------- defined in video/timex.c -----------*/
117114extern VIDEO_EOF( ts2068 );
118115extern VIDEO_UPDATE( ts2068 );
src/mess/includes/irisha.h
r4407r4408
77#ifndef IRISHA_H_
88#define IRISHA_H_
99
10#include "machine/8255ppi.h"
1011
1112/*----------- defined in machine/irisha.c -----------*/
1213
src/mess/includes/special.h
r4407r4408
77#ifndef SPECIAL_H_
88#define SPECIAL_H_
99
10#include "mame.h"
1110#include "machine/8255ppi.h"
1211#include "machine/pit8253.h"
1312
src/mess/machine/coco.c
r4407r4408
17961796/* Dragon Alpha onboard FDC */
17971797/********************************************************************************************/
17981798
1799//static
1800WD17XX_CALLBACK( dgnalpha_fdc_callback )
1799static WD17XX_CALLBACK( dgnalpha_fdc_callback )
18011800{
18021801   /* The NMI line on the alphaAlpha is gated through IC16 (early PLD), and is gated by pia2 CA2  */
18031802   /* The DRQ line goes through pia2 cb1, in exactly the same way as DRQ from DragonDos does */
src/mess/machine/irisha.c
r4407r4408
1313#include "machine/pit8253.h"
1414#include "machine/pic8259.h"
1515#include "machine/msm8251.h"
16#include "includes/irisha.h"
1617
1718static int irisha_keyboard_mask;
1819
src/mess/machine/z80dart.c
r4407r4408
10231023    dcd_w - data carrier detected handler
10241024-------------------------------------------------*/
10251025
1026void dcd_w(const device_config *device, int channel, int state)
1026static void dcd_w(const device_config *device, int channel, int state)
10271027{
10281028   z80dart_t *z80dart = get_safe_token(device);
10291029   dart_channel *ch = &z80dart->channel[channel];
src/mess/machine/mz700.c
r4407r4408
123123    MMIO
124124***************************************************************************/
125125
126READ8_HANDLER( mz700_e008_r )
126static READ8_HANDLER( mz700_e008_r )
127127{
128128   mz_state *mz = space->machine->driver_data;
129129   UINT8 data = 0;
src/mess/drivers/pdp1.c
r4407r4408
8181#endif
8282ADDRESS_MAP_END
8383
84static DRIVER_INIT( pdp1 )
85{
86   UINT8 *dst;
87
88   static const unsigned char fontdata6x8[pdp1_fontdata_size] =
89   {   /* ASCII characters */
90      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00,
91      0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0xf8,0x50,0xf8,0x50,0x00,0x00,
92      0x20,0x70,0xc0,0x70,0x18,0xf0,0x20,0x00,0x40,0xa4,0x48,0x10,0x20,0x48,0x94,0x08,
93      0x60,0x90,0xa0,0x40,0xa8,0x90,0x68,0x00,0x10,0x20,0x40,0x00,0x00,0x00,0x00,0x00,
94      0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x00,0x10,0x08,0x08,0x08,0x08,0x08,0x10,0x00,
95      0x20,0xa8,0x70,0xf8,0x70,0xa8,0x20,0x00,0x00,0x20,0x20,0xf8,0x20,0x20,0x00,0x00,
96      0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x60,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,
97      0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
98      0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00,0x10,0x30,0x10,0x10,0x10,0x10,0x10,0x00,
99      0x70,0x88,0x08,0x10,0x20,0x40,0xf8,0x00,0x70,0x88,0x08,0x30,0x08,0x88,0x70,0x00,
100      0x10,0x30,0x50,0x90,0xf8,0x10,0x10,0x00,0xf8,0x80,0xf0,0x08,0x08,0x88,0x70,0x00,
101      0x70,0x80,0xf0,0x88,0x88,0x88,0x70,0x00,0xf8,0x08,0x08,0x10,0x20,0x20,0x20,0x00,
102      0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00,0x70,0x88,0x88,0x88,0x78,0x08,0x70,0x00,
103      0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00,0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x60,
104      0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x00,0x00,0x00,0xf8,0x00,0xf8,0x00,0x00,0x00,
105      0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00,0x70,0x88,0x08,0x10,0x20,0x00,0x20,0x00,
106      0x70,0x88,0xb8,0xa8,0xb8,0x80,0x70,0x00,0x70,0x88,0x88,0xf8,0x88,0x88,0x88,0x00,
107      0xf0,0x88,0x88,0xf0,0x88,0x88,0xf0,0x00,0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00,
108      0xf0,0x88,0x88,0x88,0x88,0x88,0xf0,0x00,0xf8,0x80,0x80,0xf0,0x80,0x80,0xf8,0x00,
109      0xf8,0x80,0x80,0xf0,0x80,0x80,0x80,0x00,0x70,0x88,0x80,0x98,0x88,0x88,0x70,0x00,
110      0x88,0x88,0x88,0xf8,0x88,0x88,0x88,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
111      0x08,0x08,0x08,0x08,0x88,0x88,0x70,0x00,0x88,0x90,0xa0,0xc0,0xa0,0x90,0x88,0x00,
112      0x80,0x80,0x80,0x80,0x80,0x80,0xf8,0x00,0x88,0xd8,0xa8,0x88,0x88,0x88,0x88,0x00,
113      0x88,0xc8,0xa8,0x98,0x88,0x88,0x88,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00,
114      0xf0,0x88,0x88,0xf0,0x80,0x80,0x80,0x00,0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x08,
115      0xf0,0x88,0x88,0xf0,0x88,0x88,0x88,0x00,0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00,
116      0xf8,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00,
117      0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00,0x88,0x88,0x88,0x88,0xa8,0xd8,0x88,0x00,
118      0x88,0x50,0x20,0x20,0x20,0x50,0x88,0x00,0x88,0x88,0x88,0x50,0x20,0x20,0x20,0x00,
119      0xf8,0x08,0x10,0x20,0x40,0x80,0xf8,0x00,0x30,0x20,0x20,0x20,0x20,0x20,0x30,0x00,
120      0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x30,0x10,0x10,0x10,0x10,0x10,0x30,0x00,
121      0x20,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,
122      0x40,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x78,0x88,0x78,0x00,
123      0x80,0x80,0xf0,0x88,0x88,0x88,0xf0,0x00,0x00,0x00,0x70,0x88,0x80,0x80,0x78,0x00,
124      0x08,0x08,0x78,0x88,0x88,0x88,0x78,0x00,0x00,0x00,0x70,0x88,0xf8,0x80,0x78,0x00,
125      0x18,0x20,0x70,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x78,0x88,0x88,0x78,0x08,0x70,
126      0x80,0x80,0xf0,0x88,0x88,0x88,0x88,0x00,0x20,0x00,0x20,0x20,0x20,0x20,0x20,0x00,
127      0x20,0x00,0x20,0x20,0x20,0x20,0x20,0xc0,0x80,0x80,0x90,0xa0,0xe0,0x90,0x88,0x00,
128      0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xf0,0xa8,0xa8,0xa8,0xa8,0x00,
129      0x00,0x00,0xb0,0xc8,0x88,0x88,0x88,0x00,0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00,
130      0x00,0x00,0xf0,0x88,0x88,0xf0,0x80,0x80,0x00,0x00,0x78,0x88,0x88,0x78,0x08,0x08,
131      0x00,0x00,0xb0,0xc8,0x80,0x80,0x80,0x00,0x00,0x00,0x78,0x80,0x70,0x08,0xf0,0x00,
132      0x20,0x20,0x70,0x20,0x20,0x20,0x18,0x00,0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00,
133      0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00,0x00,0x00,0xa8,0xa8,0xa8,0xa8,0x50,0x00,
134      0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00,0x00,0x00,0x88,0x88,0x88,0x78,0x08,0x70,
135      0x00,0x00,0xf8,0x10,0x20,0x40,0xf8,0x00,0x08,0x10,0x10,0x20,0x10,0x10,0x08,0x00,
136      0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00,
137      0x00,0x68,0xb0,0x00,0x00,0x00,0x00,0x00,0x20,0x50,0x20,0x50,0xa8,0x50,0x00,0x00,
138   };
139
140   /* set up our font */
141   dst = memory_region(machine, "gfx1");
142
143   memcpy(dst, fontdata6x8, pdp1_fontdata_size);
144}
145
146
14784static INPUT_PORTS_START( pdp1 )
14885
14986    PORT_START("SPACEWAR")      /* 0: spacewar controllers */
r4407r4408
581518***************************************************************************/
582519
583520/*    YEAR  NAME      PARENT    COMPAT  MACHINE   INPUT     INIT    CONFIG  COMPANY FULLNAME */
584COMP( 1961, pdp1,     0,       0,      pdp1,     pdp1,    pdp1,      pdp1,   "Digital Equipment Corporation",  "PDP-1" , 0)
521COMP( 1961, pdp1,     0,       0,      pdp1,     pdp1,    0,      pdp1,   "Digital Equipment Corporation",  "PDP-1" , 0)
src/mess/drivers/pentagon.c
r4407r4408
135135   ROM_CART_LOAD("cart", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
136136ROM_END
137137
138SYSTEM_CONFIG_EXTERN(spectrum)
139
140138static SYSTEM_CONFIG_START(pentagon)
141139   CONFIG_RAM_DEFAULT(128 * 1024)
142140   CONFIG_DEVICE(beta_floppy_getinfo)
src/mess/drivers/scorpion.c
r4407r4408
344344   ROM_CART_LOAD("cart", 0x0000, 0x4000, ROM_NOCLEAR | ROM_NOMIRROR | ROM_OPTIONAL)
345345ROM_END
346346
347SYSTEM_CONFIG_EXTERN(spectrum)
348
349347static SYSTEM_CONFIG_START(scorpion)
350348   CONFIG_RAM_DEFAULT(256 * 1024)
351349   CONFIG_DEVICE(beta_floppy_getinfo)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team