Previous 199869 Revisions Next

r20744 Tuesday 5th February, 2013 at 11:40:08 UTC by Robbbert
cps modernisation part 3
[src/mame/drivers]fcrash.c
[src/mame/includes]cps1.h

trunk/src/mame/includes/cps1.h
r20743r20744
256256   DECLARE_WRITE16_MEMBER(cawingbl_soundlatch_w);
257257   DECLARE_WRITE16_MEMBER(sf2mdt_layer_w);
258258   DECLARE_WRITE16_MEMBER(sf2mdta_layer_w);
259   DECLARE_WRITE16_MEMBER(fcrash_soundlatch_w);
260   DECLARE_WRITE8_MEMBER(fcrash_snd_bankswitch_w);
261   DECLARE_WRITE8_MEMBER(sf2mdt_snd_bankswitch_w);
262   DECLARE_WRITE8_MEMBER(fcrash_msm5205_0_data_w);
263   DECLARE_WRITE8_MEMBER(fcrash_msm5205_1_data_w);
259264   UINT32 screen_update_fcrash(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
265   void fcrash_update_transmasks();
266   void fcrash_render_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
267   void fcrash_render_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int primask);
268   void fcrash_render_high_layer(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer);
269   void fcrash_build_palette();
260270
261271
262272   /* cps video */
trunk/src/mame/drivers/fcrash.c
r20743r20744
6565#include "sound/okim6295.h"
6666
6767
68static WRITE16_HANDLER( fcrash_soundlatch_w )
68WRITE16_MEMBER( cps_state::fcrash_soundlatch_w )
6969{
70   cps_state *state = space.machine().driver_data<cps_state>();
71
7270   if (ACCESSING_BITS_0_7)
7371   {
74      state->soundlatch_byte_w(space, 0, data & 0xff);
75      state->m_audiocpu->set_input_line(0, HOLD_LINE);
72      soundlatch_byte_w(space, 0, data & 0xff);
73      m_audiocpu->set_input_line(0, HOLD_LINE);
7674   }
7775}
7876
7977WRITE16_MEMBER(cps_state::cawingbl_soundlatch_w)
8078{
81   cps_state *state = space.machine().driver_data<cps_state>();
82
8379   if (ACCESSING_BITS_8_15)
8480   {
85      state->soundlatch_byte_w(space, 0, data  >> 8);
86      state->m_audiocpu->set_input_line(0, HOLD_LINE);
81      soundlatch_byte_w(space, 0, data  >> 8);
82      m_audiocpu->set_input_line(0, HOLD_LINE);
8783      machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(50)); /* boost the interleave or some voices get dropped */
8884   }
8985}
9086
91static WRITE8_HANDLER( fcrash_snd_bankswitch_w )
87WRITE8_MEMBER( cps_state::fcrash_snd_bankswitch_w )
9288{
93   cps_state *state = space.machine().driver_data<cps_state>();
89   m_msm_1->set_output_gain(0, (data & 0x08) ? 0.0 : 1.0);
90   m_msm_2->set_output_gain(0, (data & 0x10) ? 0.0 : 1.0);
9491
95   state->m_msm_1->set_output_gain(0, (data & 0x08) ? 0.0 : 1.0);
96   state->m_msm_2->set_output_gain(0, (data & 0x10) ? 0.0 : 1.0);
97
98   state->membank("bank1")->set_entry(data & 0x07);
92   membank("bank1")->set_entry(data & 0x07);
9993}
10094
101static WRITE8_HANDLER( sf2mdt_snd_bankswitch_w )
95WRITE8_MEMBER( cps_state::sf2mdt_snd_bankswitch_w )
10296{
103   cps_state *state = space.machine().driver_data<cps_state>();
97   m_msm_1->set_output_gain(0, (data & 0x20) ? 0.0 : 1.0);
98   m_msm_2->set_output_gain(0, (data & 0x10) ? 0.0 : 1.0);
10499
105   state->m_msm_1->set_output_gain(0, (data & 0x20) ? 0.0 : 1.0);
106   state->m_msm_2->set_output_gain(0, (data & 0x10) ? 0.0 : 1.0);
107
108   state->membank("bank1")->set_entry(data & 0x07);
100   membank("bank1")->set_entry(data & 0x07);
109101}
110102
111103static void m5205_int1( device_t *device )
r20743r20744
129121}
130122
131123
132static WRITE8_HANDLER( fcrash_msm5205_0_data_w )
124
125WRITE8_MEMBER( cps_state::fcrash_msm5205_0_data_w )
133126{
134   cps_state *state = space.machine().driver_data<cps_state>();
135   state->m_sample_buffer1 = data;
127   m_sample_buffer1 = data;
136128}
137129
138static WRITE8_HANDLER( fcrash_msm5205_1_data_w )
130WRITE8_MEMBER( cps_state::fcrash_msm5205_1_data_w )
139131{
140   cps_state *state = space.machine().driver_data<cps_state>();
141   state->m_sample_buffer2 = data;
132   m_sample_buffer2 = data;
142133}
143134
144135/* not verified */
r20743r20744
146137
147138WRITE16_MEMBER(cps_state::kodb_layer_w)
148139{
149   cps_state *state = space.machine().driver_data<cps_state>();
150
151140   /* layer enable and mask 1&2 registers are written here - passing them to m_cps_b_regs for now for drawing routines */
152141   if (offset == 0x06)
153      state->m_cps_b_regs[m_layer_enable_reg / 2] = data;
142      m_cps_b_regs[m_layer_enable_reg / 2] = data;
154143   else
155144   if (offset == 0x10)
156      state->m_cps_b_regs[state->m_layer_mask_reg[1] / 2] = data;
145      m_cps_b_regs[m_layer_mask_reg[1] / 2] = data;
157146   else
158147   if (offset == 0x11)
159      state->m_cps_b_regs[state->m_layer_mask_reg[2] / 2] = data;
148      m_cps_b_regs[m_layer_mask_reg[2] / 2] = data;
160149}
161150
162151WRITE16_MEMBER(cps_state::sf2mdt_layer_w)
163152{
164   cps_state *state = space.machine().driver_data<cps_state>();
165
166153   /* layer enable and scroll registers are written here - passing them to m_cps_b_regs and m_cps_a_regs for now for drawing routines
167154   the scroll layers aren't buttery smooth, due to the lack of using the row scroll address tables in the rendering code, this is also
168155   supported by the fact that the game doesn't write the table address anywhere */
169156
170157   if (offset == 0x0086)
171      state->m_cps_a_regs[0x14 / 2] = data + 0xffce; /* scroll 3x */
158      m_cps_a_regs[0x14 / 2] = data + 0xffce; /* scroll 3x */
172159   else
173160   if (offset == 0x0087)
174      state->m_cps_a_regs[0x16 / 2] = data; /* scroll 3y */
161      m_cps_a_regs[0x16 / 2] = data; /* scroll 3y */
175162   else
176163   if (offset == 0x0088)
177      state->m_cps_a_regs[0x10 / 2] = data + 0xffce; /* scroll 2x */
164      m_cps_a_regs[0x10 / 2] = data + 0xffce; /* scroll 2x */
178165   else
179166   if (offset == 0x0089)
180      state->m_cps_a_regs[0x0c / 2] = data + 0xffca; /* scroll 1x */
167      m_cps_a_regs[0x0c / 2] = data + 0xffca; /* scroll 1x */
181168   else
182   if (offset == 0x008a) {
183      state->m_cps_a_regs[0x12 / 2] = data; /* scroll 2y */
184      state->m_cps_a_regs[CPS1_ROWSCROLL_OFFS] = data; /* row scroll start */
185   } else
169   if (offset == 0x008a)
170   {
171      m_cps_a_regs[0x12 / 2] = data; /* scroll 2y */
172      m_cps_a_regs[CPS1_ROWSCROLL_OFFS] = data; /* row scroll start */
173   }
174   else
186175   if (offset == 0x008b)
187      state->m_cps_a_regs[0x0e / 2] = data; /* scroll 1y */
176      m_cps_a_regs[0x0e / 2] = data; /* scroll 1y */
188177   else
189178   if (offset == 0x00a6)
190      state->m_cps_b_regs[m_layer_enable_reg / 2] = data;
179      m_cps_b_regs[m_layer_enable_reg / 2] = data;
191180}
192181
193182WRITE16_MEMBER(cps_state::sf2mdta_layer_w)
194183{
195   cps_state *state = space.machine().driver_data<cps_state>();
196
197184   /* layer enable and scroll registers are written here - passing them to m_cps_b_regs and m_cps_a_regs for now for drawing routines
198185   the scroll layers aren't buttery smooth, due to the lack of using the row scroll address tables in the rendering code, this is also
199186   supported by the fact that the game doesn't write the table address anywhere */
200187
201188   if (offset == 0x0086)
202      state->m_cps_a_regs[0x0c / 2] = data + 0xffbe; /* scroll 1x */
189      m_cps_a_regs[0x0c / 2] = data + 0xffbe; /* scroll 1x */
203190   else
204191   if (offset == 0x0087)
205      state->m_cps_a_regs[0x0e / 2] = data; /* scroll 1y */
192      m_cps_a_regs[0x0e / 2] = data; /* scroll 1y */
206193   else
207194   if (offset == 0x0088)
208      state->m_cps_a_regs[0x14 / 2] = data + 0xffce; /* scroll 3x */
195      m_cps_a_regs[0x14 / 2] = data + 0xffce; /* scroll 3x */
209196   else
210   if (offset == 0x0089) {
211      state->m_cps_a_regs[0x12 / 2] = data; /* scroll 2y */
212      state->m_cps_a_regs[CPS1_ROWSCROLL_OFFS] = data; /* row scroll start */
213   } else
197   if (offset == 0x0089)
198   {
199      m_cps_a_regs[0x12 / 2] = data; /* scroll 2y */
200      m_cps_a_regs[CPS1_ROWSCROLL_OFFS] = data; /* row scroll start */
201   }
202   else
214203   if (offset == 0x008a)
215      state->m_cps_a_regs[0x10 / 2] = data + 0xffce; /* scroll 2x */
204      m_cps_a_regs[0x10 / 2] = data + 0xffce; /* scroll 2x */
216205   else
217206   if (offset == 0x008b)
218      state->m_cps_a_regs[0x16 / 2] = data; /* scroll 3y */
207      m_cps_a_regs[0x16 / 2] = data; /* scroll 3y */
219208   else
220209   if (offset == 0x00a6)
221      state->m_cps_b_regs[m_layer_enable_reg / 2] = data;
210      m_cps_b_regs[m_layer_enable_reg / 2] = data;
222211}
223212
224213
225static void fcrash_update_transmasks( running_machine &machine )
214void cps_state::fcrash_update_transmasks()
226215{
227   cps_state *state = machine.driver_data<cps_state>();
228216   int i;
229217
230218   for (i = 0; i < 4; i++)
r20743r20744
232220      int mask;
233221
234222      /* Get transparency registers */
235      if (state->m_layer_mask_reg[i])
236         mask = state->m_cps_b_regs[state->m_layer_mask_reg[i] / 2] ^ 0xffff;
223      if (m_layer_mask_reg[i])
224         mask = m_cps_b_regs[m_layer_mask_reg[i] / 2] ^ 0xffff;
237225      else
238226         mask = 0xffff;  /* completely transparent if priority masks not defined (mercs, qad) */
239227
240      state->m_bg_tilemap[0]->set_transmask(i, mask, 0x8000);
241      state->m_bg_tilemap[1]->set_transmask(i, mask, 0x8000);
242      state->m_bg_tilemap[2]->set_transmask(i, mask, 0x8000);
228      m_bg_tilemap[0]->set_transmask(i, mask, 0x8000);
229      m_bg_tilemap[1]->set_transmask(i, mask, 0x8000);
230      m_bg_tilemap[2]->set_transmask(i, mask, 0x8000);
243231   }
244232}
245233
246static void fcrash_render_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
234void cps_state::fcrash_render_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
247235{
248   cps_state *state = machine.driver_data<cps_state>();
249236   int pos;
250   int base = state->m_sprite_base / 2;
251   int num_sprites = machine.gfx[2]->elements();
237   int base = m_sprite_base / 2;
238   int num_sprites = machine().gfx[2]->elements();
252239   int last_sprite_offset = 0x1ffc;
253   UINT16 *sprite_ram = state->m_gfxram;
240   UINT16 *sprite_ram = m_gfxram;
254241
255242   // sprite base registers need hooking up properly.. on fcrash it is NOT cps1_cps_a_regs[0]
256243   //  on kodb, it might still be, unless that's just a leftover and it writes somewhere else too
257//  if (state->m_cps_a_regs[0] & 0x00ff) base = 0x10c8/2;
258//  printf("cps1_cps_a_regs %04x\n", state->m_cps_a_regs[0]);
244//  if (m_cps_a_regs[0] & 0x00ff) base = 0x10c8/2;
245//  printf("cps1_cps_a_regs %04x\n", m_cps_a_regs[0]);
259246
260247   /* if we have separate sprite ram, use it */
261   if (state->m_bootleg_sprite_ram) sprite_ram = state->m_bootleg_sprite_ram;
248   if (m_bootleg_sprite_ram) sprite_ram = m_bootleg_sprite_ram;
262249
263250   /* get end of sprite list marker */
264251   for (pos = 0x1ffc - base; pos >= 0x0000; pos -= 4)
265   {
266      if (sprite_ram[base + pos - 1] == state->m_sprite_list_end_marker) last_sprite_offset = pos;
267   }
252      if (sprite_ram[base + pos - 1] == m_sprite_list_end_marker) last_sprite_offset = pos;
268253
269254   for (pos = last_sprite_offset; pos >= 0x0000; pos -= 4)
270255   {
r20743r20744
282267      flipy  = sprite_ram[base + pos + 1] & 0x40;
283268      colour = sprite_ram[base + pos + 1] & 0x1f;
284269      ypos   = 256 - ypos;
285      xpos  += state->m_sprite_x_offset;
270      xpos  += m_sprite_x_offset;
286271
287      pdrawgfx_transpen(bitmap, cliprect, machine.gfx[2], tileno, colour, flipx, flipy, xpos + 49, ypos - 16, machine.priority_bitmap, 0x02, 15);
288
272      pdrawgfx_transpen(bitmap, cliprect, machine().gfx[2], tileno, colour, flipx, flipy, xpos + 49, ypos - 16, machine().priority_bitmap, 0x02, 15);
289273   }
290
291274}
292275
293static void fcrash_render_layer( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int primask )
276void cps_state::fcrash_render_layer( bitmap_ind16 &bitmap, const rectangle &cliprect, int layer, int primask )
294277{
295   cps_state *state = machine.driver_data<cps_state>();
296
297278   switch (layer)
298279   {
299280      case 0:
300         fcrash_render_sprites(machine, bitmap, cliprect);
281         fcrash_render_sprites(bitmap, cliprect);
301282         break;
302283      case 1:
303284      case 2:
304285      case 3:
305         state->m_bg_tilemap[layer - 1]->draw(bitmap, cliprect, TILEMAP_DRAW_LAYER1, primask);
286         m_bg_tilemap[layer - 1]->draw(bitmap, cliprect, TILEMAP_DRAW_LAYER1, primask);
306287         break;
307288   }
308289}
309290
310static void fcrash_render_high_layer( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int layer )
291void cps_state::fcrash_render_high_layer( bitmap_ind16 &bitmap, const rectangle &cliprect, int layer )
311292{
312   cps_state *state = machine.driver_data<cps_state>();
313293   bitmap_ind16 dummy_bitmap;
314294
315295   switch (layer)
r20743r20744
320300      case 1:
321301      case 2:
322302      case 3:
323         state->m_bg_tilemap[layer - 1]->draw(dummy_bitmap, cliprect, TILEMAP_DRAW_LAYER0, 1);
303         m_bg_tilemap[layer - 1]->draw(dummy_bitmap, cliprect, TILEMAP_DRAW_LAYER0, 1);
324304         break;
325305   }
326306}
327307
328static void fcrash_build_palette( running_machine &machine )
308void cps_state::fcrash_build_palette()
329309{
330   cps_state *state = machine.driver_data<cps_state>();
331310   int offset;
332311
333312   // all the bootlegs seem to write the palette offset as usual
334   int palettebase = (state->m_cps_a_regs[0x0a / 2] << 8) & 0x1ffff;
313   int palettebase = (m_cps_a_regs[0x0a / 2] << 8) & 0x1ffff;
335314
336315   for (offset = 0; offset < 32 * 6 * 16; offset++)
337316   {
338      int palette = state->m_gfxram[palettebase / 2 + offset];
317      int palette = m_gfxram[palettebase / 2 + offset];
339318      int r, g, b, bright;
340319
341320      // from my understanding of the schematics, when the 'brightness'
r20743r20744
347326      g = ((palette >> 4) & 0x0f) * 0x11 * bright / 0x2d;
348327      b = ((palette >> 0) & 0x0f) * 0x11 * bright / 0x2d;
349328
350      palette_set_color (machine, offset, MAKE_RGB(r, g, b));
329      palette_set_color (machine(), offset, MAKE_RGB(r, g, b));
351330   }
352331}
353332
r20743r20744
364343   cps1_get_video_base();
365344
366345   /* Build palette */
367   fcrash_build_palette(machine());
346   fcrash_build_palette();
368347
369   fcrash_update_transmasks(machine());
348   fcrash_update_transmasks();
370349
371350   m_bg_tilemap[0]->set_scrollx(0, m_scroll1x - m_layer_scroll1x_offset);
372351   m_bg_tilemap[0]->set_scrolly(0, m_scroll1y);
r20743r20744
409388   l2 = (layercontrol >> 0x0a) & 03;
410389   l3 = (layercontrol >> 0x0c) & 03;
411390
412   fcrash_render_layer(machine(), bitmap, cliprect, l0, 0);
391   fcrash_render_layer(bitmap, cliprect, l0, 0);
413392
414393   if (l1 == 0)
415      fcrash_render_high_layer(machine(), bitmap, cliprect, l0);
394      fcrash_render_high_layer(bitmap, cliprect, l0);
416395
417   fcrash_render_layer(machine(), bitmap, cliprect, l1, 0);
396   fcrash_render_layer(bitmap, cliprect, l1, 0);
418397
419398   if (l2 == 0)
420      fcrash_render_high_layer(machine(), bitmap, cliprect, l1);
399      fcrash_render_high_layer(bitmap, cliprect, l1);
421400
422   fcrash_render_layer(machine(), bitmap, cliprect, l2, 0);
401   fcrash_render_layer(bitmap, cliprect, l2, 0);
423402
424403   if (l3 == 0)
425      fcrash_render_high_layer(machine(), bitmap, cliprect, l2);
404      fcrash_render_high_layer(bitmap, cliprect, l2);
426405
427   fcrash_render_layer(machine(), bitmap, cliprect, l3, 0);
406   fcrash_render_layer(bitmap, cliprect, l3, 0);
428407
429408   return 0;
430409}
r20743r20744
436415   AM_RANGE(0x800100, 0x80013f) AM_RAM AM_SHARE("cps_a_regs")  /* CPS-A custom */
437416   AM_RANGE(0x800140, 0x80017f) AM_RAM AM_SHARE("cps_b_regs")  /* CPS-B custom */
438417   AM_RANGE(0x880000, 0x880001) AM_READ_PORT("IN1")                /* Player input ports */
439   AM_RANGE(0x880006, 0x880007) AM_WRITE_LEGACY(fcrash_soundlatch_w)       /* Sound command */
418   AM_RANGE(0x880006, 0x880007) AM_WRITE(fcrash_soundlatch_w)       /* Sound command */
440419   AM_RANGE(0x880008, 0x88000f) AM_READ(cps1_dsw_r)                /* System input ports / Dip Switches */
441420   AM_RANGE(0x890000, 0x890001) AM_WRITENOP    // palette related?
442421   AM_RANGE(0x900000, 0x92ffff) AM_RAM_WRITE(cps1_gfxram_w) AM_SHARE("gfxram")
r20743r20744
449428   AM_RANGE(0xd000, 0xd7ff) AM_RAM
450429   AM_RANGE(0xd800, 0xd801) AM_DEVREADWRITE_LEGACY("ym1", ym2203_r, ym2203_w)
451430   AM_RANGE(0xdc00, 0xdc01) AM_DEVREADWRITE_LEGACY("ym2", ym2203_r, ym2203_w)
452   AM_RANGE(0xe000, 0xe000) AM_WRITE_LEGACY(fcrash_snd_bankswitch_w)
431   AM_RANGE(0xe000, 0xe000) AM_WRITE(fcrash_snd_bankswitch_w)
453432   AM_RANGE(0xe400, 0xe400) AM_READ(soundlatch_byte_r)
454   AM_RANGE(0xe800, 0xe800) AM_WRITE_LEGACY(fcrash_msm5205_0_data_w)
455   AM_RANGE(0xec00, 0xec00) AM_WRITE_LEGACY(fcrash_msm5205_1_data_w)
433   AM_RANGE(0xe800, 0xe800) AM_WRITE(fcrash_msm5205_0_data_w)
434   AM_RANGE(0xec00, 0xec00) AM_WRITE(fcrash_msm5205_1_data_w)
456435ADDRESS_MAP_END
457436
458437static ADDRESS_MAP_START( kodb_sound_map, AS_PROGRAM, 8, cps_state )
r20743r20744
470449   AM_RANGE(0xd000, 0xd7ff) AM_RAM
471450   AM_RANGE(0xd800, 0xd801) AM_DEVREADWRITE("2151", ym2151_device, read, write)
472451   AM_RANGE(0xdc00, 0xdc00) AM_READ(soundlatch_byte_r)
473   AM_RANGE(0xe000, 0xe000) AM_WRITE_LEGACY(sf2mdt_snd_bankswitch_w)
474   AM_RANGE(0xe400, 0xe400) AM_WRITE_LEGACY(fcrash_msm5205_0_data_w)
475   AM_RANGE(0xe800, 0xe800) AM_WRITE_LEGACY(fcrash_msm5205_1_data_w)
452   AM_RANGE(0xe000, 0xe000) AM_WRITE(sf2mdt_snd_bankswitch_w)
453   AM_RANGE(0xe400, 0xe400) AM_WRITE(fcrash_msm5205_0_data_w)
454   AM_RANGE(0xe800, 0xe800) AM_WRITE(fcrash_msm5205_1_data_w)
476455ADDRESS_MAP_END
477456
478457

Previous 199869 Revisions Next


© 1997-2024 The MAME Team