Skip to content

Commit 3633adc

Browse files
authored
misc/mirax.cpp: Minor cleanups: (#12857)
* Use more appropriate types for some variables. * Simplified graphics ROM decoding. * Reduced literal tags, made some variables const, improved ROM region and variable names.
1 parent e75ddc6 commit 3633adc

File tree

1 file changed

+70
-77
lines changed

1 file changed

+70
-77
lines changed

src/mame/misc/mirax.cpp

Lines changed: 70 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,18 @@ class mirax_state : public driver_device
173173
required_shared_ptr<uint8_t> m_spriteram;
174174
required_shared_ptr<uint8_t> m_colorram;
175175

176-
uint8_t m_nAyCtrl = 0;
177-
uint8_t m_nmi_mask = 0;
178-
uint8_t m_flipscreen_x = 0;
179-
uint8_t m_flipscreen_y = 0;
176+
uint8_t m_ay_addr_latch = 0;
177+
bool m_nmi_mask = false;
178+
bool m_flipscreen_x = false;
179+
bool m_flipscreen_y = false;
180180

181-
void audio_w(offs_t offset, uint8_t data);
181+
void ay_addr_latch_w(offs_t offset, uint8_t data);
182182
void nmi_mask_w(int state);
183183
void sound_cmd_w(uint8_t data);
184-
void coin_counter0_w(int state);
185-
void coin_counter1_w(int state);
184+
template<unsigned Which> void coin_counter_w(int state);
186185
void flip_screen_x_w(int state);
187186
void flip_screen_y_w(int state);
188-
void ay1_sel(uint8_t data);
189-
void ay2_sel(uint8_t data);
187+
template<unsigned Which> void ay_data_w(uint8_t data);
190188

191189
void mirax_palette(palette_device &palette) const;
192190

@@ -238,20 +236,26 @@ void mirax_state::draw_tilemap(bitmap_ind16 &bitmap, const rectangle &cliprect,
238236
{
239237
for (int x = 0; x < 32; x++)
240238
{
241-
int tile = m_videoram[32*y+x];
242-
int color = (m_colorram[x*2]<<8) | (m_colorram[(x*2)+1]);
243-
int x_scroll = (color & 0xff00)>>8;
244-
tile |= ((color & 0xe0)<<3);
239+
uint32_t tile = m_videoram[32 * y + x];
240+
uint32_t color = (m_colorram[x * 2] << 8) | (m_colorram[(x * 2) + 1]);
241+
int const x_scroll = (color & 0xff00) >> 8;
242+
tile |= ((color & 0xe0) << 3);
245243

246-
int const res_x = m_flipscreen_x ? (248 - x*8) : (x*8);
247-
int const res_y = m_flipscreen_y ? (248 - y*8 + x_scroll) : (y*8 - x_scroll);
244+
int const res_x = m_flipscreen_x ? (248 - x * 8) : (x * 8);
245+
int const res_y = m_flipscreen_y ? (248 - y * 8 + x_scroll) : (y * 8 - x_scroll);
248246
int const wrapy = m_flipscreen_y ? -256 : 256;
249247

250248
if ((x <= 1 || x >= 30) ^ draw_flag)
251249
{
252-
gfx->opaque(bitmap,cliprect,tile,color & 7,(m_flipscreen_x),(m_flipscreen_y),res_x,res_y);
250+
gfx->opaque(bitmap, cliprect,
251+
tile, color & 7,
252+
m_flipscreen_x, m_flipscreen_y,
253+
res_x, res_y);
253254
// wrap-around
254-
gfx->opaque(bitmap,cliprect,tile,color & 7,(m_flipscreen_x),(m_flipscreen_y),res_x,res_y+wrapy);
255+
gfx->opaque(bitmap, cliprect,
256+
tile, color & 7,
257+
m_flipscreen_x, m_flipscreen_y,
258+
res_x, res_y + wrapy);
255259
}
256260
}
257261
}
@@ -264,18 +268,21 @@ void mirax_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
264268
if (!m_spriteram[count] || !m_spriteram[count + 3])
265269
continue;
266270

267-
int spr_offs = m_spriteram[count+1] & 0x3f;
268-
spr_offs += (m_spriteram[count+2] & 0xe0)<<1;
269-
spr_offs += (m_spriteram[count+2] & 0x10)<<5;
271+
uint32_t spr_offs = m_spriteram[count + 1] & 0x3f;
272+
spr_offs += (m_spriteram[count + 2] & 0xe0) << 1;
273+
spr_offs += (m_spriteram[count + 2] & 0x10) << 5;
270274

271-
int const color = m_spriteram[count+2] & 0x7;
272-
int const fx = m_flipscreen_x ^ BIT(m_spriteram[count + 1], 6); //<- guess
273-
int const fy = m_flipscreen_y ^ BIT(m_spriteram[count + 1], 7);
275+
uint32_t const color = m_spriteram[count + 2] & 0x7;
276+
bool const fx = m_flipscreen_x ^ BIT(m_spriteram[count + 1], 6); // guess
277+
bool const fy = m_flipscreen_y ^ BIT(m_spriteram[count + 1], 7);
274278

275279
int const y = m_flipscreen_y ? m_spriteram[count] : 0x100 - m_spriteram[count] - 16;
276-
int const x = m_flipscreen_x ? 240 - m_spriteram[count+3] : m_spriteram[count+3];
280+
int const x = m_flipscreen_x ? 240 - m_spriteram[count + 3] : m_spriteram[count + 3];
277281

278-
m_gfxdecode->gfx(1)->transpen(bitmap,cliprect,spr_offs,color,fx,fy,x,y,0);
282+
m_gfxdecode->gfx(1)->transpen(bitmap, cliprect,
283+
spr_offs, color,
284+
fx, fy,
285+
x, y, 0);
279286
}
280287
}
281288

@@ -290,29 +297,22 @@ uint32_t mirax_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap,
290297

291298
void mirax_state::machine_start()
292299
{
293-
m_nAyCtrl = 0x00;
294-
295-
save_item(NAME(m_nAyCtrl));
300+
save_item(NAME(m_ay_addr_latch));
296301
save_item(NAME(m_nmi_mask));
297302
save_item(NAME(m_flipscreen_x));
298303
save_item(NAME(m_flipscreen_y));
299304
}
300305

301-
void mirax_state::audio_w(offs_t offset, uint8_t data)
302-
{
303-
m_nAyCtrl=offset;
304-
}
305-
306-
void mirax_state::ay1_sel(uint8_t data)
306+
void mirax_state::ay_addr_latch_w(offs_t offset, uint8_t data)
307307
{
308-
m_ay[0]->address_w(m_nAyCtrl);
309-
m_ay[0]->data_w(data);
308+
m_ay_addr_latch = offset;
310309
}
311310

312-
void mirax_state::ay2_sel(uint8_t data)
311+
template<unsigned Which>
312+
void mirax_state::ay_data_w(uint8_t data)
313313
{
314-
m_ay[1]->address_w(m_nAyCtrl);
315-
m_ay[1]->data_w(data);
314+
m_ay[Which]->address_w(m_ay_addr_latch);
315+
m_ay[Which]->data_w(data);
316316
}
317317

318318
void mirax_state::nmi_mask_w(int state)
@@ -328,15 +328,10 @@ void mirax_state::sound_cmd_w(uint8_t data)
328328
m_audiocpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero);
329329
}
330330

331-
332-
void mirax_state::coin_counter0_w(int state)
333-
{
334-
machine().bookkeeping().coin_counter_w(0, state);
335-
}
336-
337-
void mirax_state::coin_counter1_w(int state)
331+
template<unsigned Which>
332+
void mirax_state::coin_counter_w(int state)
338333
{
339-
machine().bookkeeping().coin_counter_w(1, state);
334+
machine().bookkeeping().coin_counter_w(Which, state);
340335
}
341336

342337
void mirax_state::flip_screen_x_w(int state)
@@ -353,17 +348,17 @@ void mirax_state::mirax_main_map(address_map &map)
353348
{
354349
map(0x0000, 0xbfff).rom();
355350
map(0xc800, 0xd7ff).ram();
356-
map(0xe000, 0xe3ff).ram().share("videoram");
357-
map(0xe800, 0xe9ff).ram().share("spriteram");
358-
map(0xea00, 0xea3f).ram().share("colorram"); //per-column color + bank bits for the videoram
351+
map(0xe000, 0xe3ff).ram().share(m_videoram);
352+
map(0xe800, 0xe9ff).ram().share(m_spriteram);
353+
map(0xea00, 0xea3f).ram().share(m_colorram); // per-column color + bank bits for the videoram
359354
map(0xf000, 0xf000).portr("P1");
360355
map(0xf100, 0xf100).portr("P2");
361356
map(0xf200, 0xf200).portr("DSW1");
362-
map(0xf300, 0xf300).nopr(); //watchdog? value is always read then discarded
357+
map(0xf300, 0xf300).nopr(); // watchdog? value is always read then discarded
363358
map(0xf400, 0xf400).portr("DSW2");
364359
map(0xf500, 0xf507).w("mainlatch", FUNC(ls259_device::write_d0));
365360
map(0xf800, 0xf800).w(FUNC(mirax_state::sound_cmd_w));
366-
// map(0xf900, 0xf900) //sound cmd mirror? ack?
361+
// map(0xf900, 0xf900) // sound cmd mirror? ack?
367362
}
368363

369364
void mirax_state::mirax_sound_map(address_map &map)
@@ -374,19 +369,19 @@ void mirax_state::mirax_sound_map(address_map &map)
374369

375370
map(0xe000, 0xe000).nopw();
376371
map(0xe001, 0xe001).nopw();
377-
map(0xe003, 0xe003).w(FUNC(mirax_state::ay1_sel)); //1st ay ?
372+
map(0xe003, 0xe003).w(FUNC(mirax_state::ay_data_w<0>)); // 1st ay ?
378373

379374
map(0xe400, 0xe400).nopw();
380375
map(0xe401, 0xe401).nopw();
381-
map(0xe403, 0xe403).w(FUNC(mirax_state::ay2_sel)); //2nd ay ?
376+
map(0xe403, 0xe403).w(FUNC(mirax_state::ay_data_w<1>)); // 2nd ay ?
382377

383-
map(0xf900, 0xf9ff).w(FUNC(mirax_state::audio_w));
378+
map(0xf900, 0xf9ff).w(FUNC(mirax_state::ay_addr_latch_w));
384379
}
385380

386381

387-
/* verified from Z80 code */
382+
// verified from Z80 code
388383
static INPUT_PORTS_START( mirax )
389-
/* up/down directions are trusted according of the continue screen */
384+
// up/down directions are trusted according of the continue screen
390385
PORT_START("P1")
391386
PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )
392387
PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_START1 )
@@ -428,7 +423,7 @@ static INPUT_PORTS_START( mirax )
428423
PORT_DIPUNUSED( 0x80, IP_ACTIVE_HIGH )
429424

430425
PORT_START("DSW2")
431-
PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) /* table at 0x11b5 (2 * 3 * 2 bytes) */
426+
PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) // table at 0x11b5 (2 * 3 * 2 bytes)
432427
PORT_DIPSETTING( 0x00, "30k 80k 150k" )
433428
PORT_DIPSETTING( 0x01, "900k 950k 990k" )
434429
PORT_DIPNAME( 0x02, 0x00, "Flags for Extra Life" )
@@ -440,7 +435,7 @@ static INPUT_PORTS_START( mirax )
440435
PORT_DIPNAME( 0x08, 0x08, DEF_STR( Allow_Continue ) )
441436
PORT_DIPSETTING( 0x00, DEF_STR( No ) )
442437
PORT_DIPSETTING( 0x08, DEF_STR( Yes ) )
443-
/* this dip makes the game to behave like attract mode, even if you insert a coin */
438+
// this dip makes the game to behave like attract mode, even if you insert a coin
444439
PORT_DIPNAME( 0x10, 0x00, "Auto-Play Mode (Debug)" )
445440
PORT_DIPSETTING( 0x00, DEF_STR( No ) )
446441
PORT_DIPSETTING( 0x10, DEF_STR( Yes ) )
@@ -451,7 +446,7 @@ static INPUT_PORTS_START( mirax )
451446
PORT_DIPUNUSED( 0x80, IP_ACTIVE_HIGH )
452447
INPUT_PORTS_END
453448

454-
/* verified from Z80 code */
449+
// verified from Z80 code
455450
static INPUT_PORTS_START( miraxa )
456451
PORT_INCLUDE( mirax )
457452

@@ -468,7 +463,7 @@ static INPUT_PORTS_START( miraxa )
468463
PORT_DIPSETTING( 0x30, "6" )
469464

470465
PORT_MODIFY("DSW2")
471-
PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) /* table at 0x1276 (2 * 3 * 2 bytes) */
466+
PORT_DIPNAME( 0x01, 0x00, DEF_STR( Bonus_Life ) ) // table at 0x1276 (2 * 3 * 2 bytes)
472467
PORT_DIPSETTING( 0x00, "30k 80k 150k" )
473468
PORT_DIPSETTING( 0x01, "50k 100k 900k" )
474469
INPUT_PORTS_END
@@ -480,16 +475,14 @@ static const gfx_layout layout16 =
480475
RGN_FRAC(1,3),
481476
3,
482477
{ RGN_FRAC(2,3),RGN_FRAC(1,3),RGN_FRAC(0,3)},
483-
{ 0, 1, 2, 3, 4, 5, 6, 7 ,
484-
0+8*8,1+8*8,2+8*8,3+8*8,4+8*8,5+8*8,6+8*8,7+8*8},
485-
{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
486-
0*8+8*8*2, 1*8+8*8*2, 2*8+8*8*2, 3*8+8*8*2, 4*8+8*8*2, 5*8+8*8*2, 6*8+8*8*2, 7*8+8*8*2},
478+
{ STEP8(0,1), STEP8(8*8,1) },
479+
{ STEP8(0,8), STEP8(8*8*2,8) },
487480
16*16
488481
};
489482

490483
static GFXDECODE_START( gfx_mirax )
491-
GFXDECODE_ENTRY( "gfx1", 0, gfx_8x8x3_planar, 0, 8 )
492-
GFXDECODE_ENTRY( "gfx2", 0, layout16, 0, 8 )
484+
GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x3_planar, 0, 8 )
485+
GFXDECODE_ENTRY( "sprites", 0, layout16, 0, 8 )
493486
GFXDECODE_END
494487

495488

@@ -509,18 +502,18 @@ void mirax_state::mirax(machine_config &config)
509502
m_audiocpu->set_periodic_int(FUNC(mirax_state::irq0_line_hold), attotime::from_hz(4*60));
510503

511504
ls259_device &mainlatch(LS259(config, "mainlatch")); // R10
512-
mainlatch.q_out_cb<0>().set(FUNC(mirax_state::coin_counter0_w));
505+
mainlatch.q_out_cb<0>().set(FUNC(mirax_state::coin_counter_w<0>));
513506
mainlatch.q_out_cb<1>().set(FUNC(mirax_state::nmi_mask_w));
514-
mainlatch.q_out_cb<2>().set(FUNC(mirax_state::coin_counter1_w)); // only used in 'miraxa' - see notes
507+
mainlatch.q_out_cb<2>().set(FUNC(mirax_state::coin_counter_w<1>)); // only used in 'miraxa' - see notes
515508
// One address flips X, the other flips Y, but I can't tell which is which
516509
// Since the value is the same for the 2 addresses, it doesn't really matter
517510
mainlatch.q_out_cb<6>().set(FUNC(mirax_state::flip_screen_x_w));
518511
mainlatch.q_out_cb<7>().set(FUNC(mirax_state::flip_screen_y_w));
519512

520-
/* video hardware */
513+
// video hardware
521514
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
522515
screen.set_refresh_hz(60);
523-
screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500) /* not accurate */);
516+
screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); // not accurate
524517
screen.set_size(256, 256);
525518
screen.set_visarea(0*8, 32*8-1, 1*8, 31*8-1);
526519
screen.set_screen_update(FUNC(mirax_state::screen_update));
@@ -550,12 +543,12 @@ ROM_START( mirax )
550543
ROM_REGION( 0x10000, "audiocpu", 0 )
551544
ROM_LOAD( "mxr2-4v.rom", 0x0000, 0x2000, CRC(cd2d52dc) SHA1(0d4181dc68beac338f47a2065c7b755008877896) )
552545

553-
ROM_REGION( 0xc000, "gfx1", 0 )
546+
ROM_REGION( 0xc000, "tiles", 0 )
554547
ROM_LOAD( "mxe3-4v.rom", 0x0000, 0x4000, CRC(0cede01f) SHA1(c723dd8ee9dc06c94a7fe5d5b5bccc42e2181af1) )
555548
ROM_LOAD( "mxh3-4v.rom", 0x4000, 0x4000, CRC(58221502) SHA1(daf5c508939b44616ca76308fc33f94d364ed587) )
556549
ROM_LOAD( "mxk3-4v.rom", 0x8000, 0x4000, CRC(6dbc2961) SHA1(5880c28f1ef704fee2d625a42682c7d65613acc8) )
557550

558-
ROM_REGION( 0x18000, "gfx2", 0 )
551+
ROM_REGION( 0x18000, "sprites", 0 )
559552
ROM_LOAD( "mxe2-4v.rom", 0x04000, 0x4000, CRC(2cf5d8b7) SHA1(f66bce4d413a48f6ae07974870dc0f31eefa68e9) )
560553
ROM_LOAD( "mxf2-4v.rom", 0x0c000, 0x4000, CRC(1f42c7fa) SHA1(33e56c6ddf7676a12f57de87ec740c6b6eb1cc8c) )
561554
ROM_LOAD( "mxh2-4v.rom", 0x14000, 0x4000, CRC(cbaff4c6) SHA1(2dc4a1f51b28e98be0cfb5ab7576047c748b6728) )
@@ -580,12 +573,12 @@ ROM_START( miraxa )
580573
ROM_REGION( 0x10000, "audiocpu", 0 )
581574
ROM_LOAD( "mxr2-4v.rom", 0x0000, 0x2000, CRC(cd2d52dc) SHA1(0d4181dc68beac338f47a2065c7b755008877896) )
582575

583-
ROM_REGION( 0xc000, "gfx1", 0 )
576+
ROM_REGION( 0xc000, "tiles", 0 )
584577
ROM_LOAD( "mxe3-4v.rom", 0x0000, 0x4000, CRC(0cede01f) SHA1(c723dd8ee9dc06c94a7fe5d5b5bccc42e2181af1) )
585578
ROM_LOAD( "mxh3-4v.rom", 0x4000, 0x4000, CRC(58221502) SHA1(daf5c508939b44616ca76308fc33f94d364ed587) )
586579
ROM_LOAD( "mxk3-4v.rom", 0x8000, 0x4000, CRC(6dbc2961) SHA1(5880c28f1ef704fee2d625a42682c7d65613acc8) )
587580

588-
ROM_REGION( 0x18000, "gfx2", 0 )
581+
ROM_REGION( 0x18000, "sprites", 0 )
589582
ROM_LOAD( "mxe2-4v.rom", 0x04000, 0x4000, CRC(2cf5d8b7) SHA1(f66bce4d413a48f6ae07974870dc0f31eefa68e9) )
590583
ROM_LOAD( "mxf2-4v.rom", 0x0c000, 0x4000, CRC(1f42c7fa) SHA1(33e56c6ddf7676a12f57de87ec740c6b6eb1cc8c) )
591584
ROM_LOAD( "mxh2-4v.rom", 0x14000, 0x4000, CRC(cbaff4c6) SHA1(2dc4a1f51b28e98be0cfb5ab7576047c748b6728) )
@@ -609,12 +602,12 @@ ROM_START( miraxb )
609602
ROM_REGION( 0x10000, "audiocpu", 0 )
610603
ROM_LOAD( "13.r5", 0x0000, 0x2000, CRC(cd2d52dc) SHA1(0d4181dc68beac338f47a2065c7b755008877896) )
611604

612-
ROM_REGION( 0xc000, "gfx1", 0 )
605+
ROM_REGION( 0xc000, "tiles", 0 )
613606
ROM_LOAD( "4.e3", 0x0000, 0x4000, CRC(0cede01f) SHA1(c723dd8ee9dc06c94a7fe5d5b5bccc42e2181af1) )
614607
ROM_LOAD( "6.h3", 0x4000, 0x4000, CRC(58221502) SHA1(daf5c508939b44616ca76308fc33f94d364ed587) )
615608
ROM_LOAD( "8.k3", 0x8000, 0x4000, CRC(6dbc2961) SHA1(5880c28f1ef704fee2d625a42682c7d65613acc8) )
616609

617-
ROM_REGION( 0x18000, "gfx2", 0 )
610+
ROM_REGION( 0x18000, "sprites", 0 )
618611
ROM_LOAD( "1.e2", 0x04000, 0x4000, CRC(2cf5d8b7) SHA1(f66bce4d413a48f6ae07974870dc0f31eefa68e9) )
619612
ROM_LOAD( "2.f2", 0x0c000, 0x4000, CRC(1f42c7fa) SHA1(33e56c6ddf7676a12f57de87ec740c6b6eb1cc8c) )
620613
ROM_LOAD( "3.h2", 0x14000, 0x4000, CRC(cbaff4c6) SHA1(2dc4a1f51b28e98be0cfb5ab7576047c748b6728) )

0 commit comments

Comments
 (0)