diff options
author | Aaron Giles <aaron@aarongiles.com> | 2010-08-04 15:37:08 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2010-08-04 15:37:08 +0000 |
commit | c85c035c5df40c68195b50ba995369eaf8bd18da (patch) | |
tree | e8f9b512e63268a668d55116f992c12e5777692f /src/mame/drivers/backfire.c | |
parent | b8b87c341ac498766daad95ac743285a14e0e5d8 (diff) |
(Wow, I had no idea quite so many drivers were using driver_data!)
Defined new class driver_data_t, which all driver_data classes must
derive from. Updated all class definitions to inherit from the new
class, and to call it in the constructor. Also changed the alloc()
signature to return a driver_data_t pointer instead of a void *.
Renamed and hid machine->driver_data as machine->m_driver_data.
Added a new templatized method machine->driver_data<class> which returns
a properly downcast'ed version of the driver data. Updated all code
which looked like this:
mydriver_state *state = (mydriver_state *)machine->driver_data;
to this:
mydriver_state *state = machine->driver_data<mydriver_state>();
The new function does a downcast<> which in debug builds dynamically
verifies that you're actually casting to the right type.
Changed atarigen_state to be a base class from which all the related
Atari drivers derive their state from.
For MESS: this was mostly a bulk search/replace, in 4 steps in
src/mame:
1. Add ": public driver_data_t" to each driver state class definition:
Search: (class [a-z0-9_]+_state)$
Replace: \1 : public driver_data_t
2. Change the static alloc function to return a driver_data_t *:
Search: static void \*alloc\(
Replace: static driver_data_t \*alloc\(
3. Change the constructor to initialize driver_data_t:
Search: ([a-z0-9_]+_state\(running_machine \&machine\)) { }
Replace: \1\r\n\t\t: driver_data_t(machine) { }
4. Replace the state fetchers to use the new templatized function:
Search: \(([a-z0-9_]+_state) \*\)(.*)machine->driver_data
Replace: \2machine->driver_data<\1>()
Diffstat (limited to 'src/mame/drivers/backfire.c')
-rw-r--r-- | src/mame/drivers/backfire.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/mame/drivers/backfire.c b/src/mame/drivers/backfire.c index ac5b5c1fee4..cad77af7830 100644 --- a/src/mame/drivers/backfire.c +++ b/src/mame/drivers/backfire.c @@ -20,12 +20,13 @@ #include "video/deco16ic.h" #include "rendlay.h" -class backfire_state +class backfire_state : public driver_data_t { public: - static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, backfire_state(machine)); } + static driver_data_t *alloc(running_machine &machine) { return auto_alloc_clear(&machine, backfire_state(machine)); } - backfire_state(running_machine &machine) { } + backfire_state(running_machine &machine) + : driver_data_t(machine) { } /* memory pointers */ UINT16 * pf1_rowscroll; @@ -55,7 +56,7 @@ public: /* I'm using the functions in deco16ic.c ... same chips, why duplicate code? */ static VIDEO_START( backfire ) { - backfire_state *state = (backfire_state *)machine->driver_data; + backfire_state *state = machine->driver_data<backfire_state>(); /* allocate the ram as 16-bit (we do it here because the CPU is 32-bit) */ state->pf1_rowscroll = auto_alloc_array(machine, UINT16, 0x0800/2); @@ -160,7 +161,7 @@ static void draw_sprites( running_machine *machine, bitmap_t *bitmap, const rect static VIDEO_UPDATE( backfire ) { - backfire_state *state = (backfire_state *)screen->machine->driver_data; + backfire_state *state = screen->machine->driver_data<backfire_state>(); /* screen 1 uses pf1 as the forground and pf3 as the background */ /* screen 2 uses pf2 as the foreground and pf4 as the background */ @@ -224,7 +225,7 @@ static READ32_DEVICE_HANDLER( backfire_eeprom_r ) static READ32_HANDLER( backfire_control2_r ) { - backfire_state *state = (backfire_state *)space->machine->driver_data; + backfire_state *state = space->machine->driver_data<backfire_state>(); // logerror("%08x:Read eprom %08x (%08x)\n", cpu_get_pc(space->cpu), offset << 1, mem_mask); return (eeprom_read_bit(state->eeprom) << 24) | input_port_read(space->machine, "IN1") | (input_port_read(space->machine, "IN1") << 16); @@ -233,7 +234,7 @@ static READ32_HANDLER( backfire_control2_r ) #ifdef UNUSED_FUNCTION static READ32_HANDLER(backfire_control3_r) { - backfire_state *state = (backfire_state *)space->machine->driver_data; + backfire_state *state = space->machine->driver_data<backfire_state>(); // logerror("%08x:Read eprom %08x (%08x)\n", cpu_get_pc(space->cpu), offset << 1, mem_mask); return (eeprom_read_bit(state->eeprom) << 24) | input_port_read(space->machine, "IN2") | (input_port_read(space->machine, "IN2") << 16); @@ -261,14 +262,14 @@ static WRITE32_HANDLER(backfire_nonbuffered_palette_w) /* map 32-bit writes to 16-bit */ -static READ32_HANDLER( backfire_pf1_rowscroll_r ) { backfire_state *state = (backfire_state *)space->machine->driver_data; return state->pf1_rowscroll[offset] ^ 0xffff0000; } -static READ32_HANDLER( backfire_pf2_rowscroll_r ) { backfire_state *state = (backfire_state *)space->machine->driver_data; return state->pf2_rowscroll[offset] ^ 0xffff0000; } -static READ32_HANDLER( backfire_pf3_rowscroll_r ) { backfire_state *state = (backfire_state *)space->machine->driver_data; return state->pf3_rowscroll[offset] ^ 0xffff0000; } -static READ32_HANDLER( backfire_pf4_rowscroll_r ) { backfire_state *state = (backfire_state *)space->machine->driver_data; return state->pf4_rowscroll[offset] ^ 0xffff0000; } -static WRITE32_HANDLER( backfire_pf1_rowscroll_w ) { backfire_state *state = (backfire_state *)space->machine->driver_data; data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf1_rowscroll[offset]); } -static WRITE32_HANDLER( backfire_pf2_rowscroll_w ) { backfire_state *state = (backfire_state *)space->machine->driver_data; data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf2_rowscroll[offset]); } -static WRITE32_HANDLER( backfire_pf3_rowscroll_w ) { backfire_state *state = (backfire_state *)space->machine->driver_data; data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf3_rowscroll[offset]); } -static WRITE32_HANDLER( backfire_pf4_rowscroll_w ) { backfire_state *state = (backfire_state *)space->machine->driver_data; data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf4_rowscroll[offset]); } +static READ32_HANDLER( backfire_pf1_rowscroll_r ) { backfire_state *state = space->machine->driver_data<backfire_state>(); return state->pf1_rowscroll[offset] ^ 0xffff0000; } +static READ32_HANDLER( backfire_pf2_rowscroll_r ) { backfire_state *state = space->machine->driver_data<backfire_state>(); return state->pf2_rowscroll[offset] ^ 0xffff0000; } +static READ32_HANDLER( backfire_pf3_rowscroll_r ) { backfire_state *state = space->machine->driver_data<backfire_state>(); return state->pf3_rowscroll[offset] ^ 0xffff0000; } +static READ32_HANDLER( backfire_pf4_rowscroll_r ) { backfire_state *state = space->machine->driver_data<backfire_state>(); return state->pf4_rowscroll[offset] ^ 0xffff0000; } +static WRITE32_HANDLER( backfire_pf1_rowscroll_w ) { backfire_state *state = space->machine->driver_data<backfire_state>(); data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf1_rowscroll[offset]); } +static WRITE32_HANDLER( backfire_pf2_rowscroll_w ) { backfire_state *state = space->machine->driver_data<backfire_state>(); data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf2_rowscroll[offset]); } +static WRITE32_HANDLER( backfire_pf3_rowscroll_w ) { backfire_state *state = space->machine->driver_data<backfire_state>(); data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf3_rowscroll[offset]); } +static WRITE32_HANDLER( backfire_pf4_rowscroll_w ) { backfire_state *state = space->machine->driver_data<backfire_state>(); data &= 0x0000ffff; mem_mask &= 0x0000ffff; COMBINE_DATA(&state->pf4_rowscroll[offset]); } #ifdef UNUSED_FUNCTION @@ -469,7 +470,7 @@ static const deco16ic_interface backfire_deco16ic_intf = static MACHINE_START( backfire ) { - backfire_state *state = (backfire_state *)machine->driver_data; + backfire_state *state = machine->driver_data<backfire_state>(); state->maincpu = machine->device("maincpu"); state->deco16ic = machine->device("deco_custom"); @@ -675,7 +676,7 @@ static void descramble_sound( running_machine *machine ) static READ32_HANDLER( backfire_speedup_r ) { - backfire_state *state = (backfire_state *)space->machine->driver_data; + backfire_state *state = space->machine->driver_data<backfire_state>(); //mame_printf_debug( "%08x\n",cpu_get_pc(space->cpu)); |