summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2011-02-08 06:48:39 +0000
committer Aaron Giles <aaron@aarongiles.com>2011-02-08 06:48:39 +0000
commit4f7efb1ca4bcf00edd9e519167367f44d797186c (patch)
treec9ee8aae0bc80942f118df4df24d9054504b9ad9
parentf4f3adf2506ce7808363593436de5b13bb304d47 (diff)
Moved the state saving system to C++. For now the registration macros
are still intact. The new state_manager class has templatized methods for saving the various types, and through template specialization can save more complex system types cleanly (like bitmaps and attotimes). Added new mechanism to detect proper state save types. This is much more strict and there will likely be some games/devices that fatalerror at startup until they are remedied. Spot checking has caught the more common situations. The new state_manager is embedded directly in the running_machine, allowing objects to register state saving in their constructors now. Added NAME() macro which is a generalization of FUNC() and can be used to wrap variables that are registered when directly using the new methods as opposed to the previous macros. For example: machine->state().save_item(NAME(global_item)) Added methods in the device_t class that implicitly register state against the current device, making for a cleaner interface. Just a couple of required regexes for now: state_save_register_postload( *)\(( *)([^,;]+), * \3->state().register_postload\1\(\2 state_save_register_presave( *)\(( *)([^,;]+), * \3->state().register_presave\1\(\2
-rw-r--r--src/emu/cpu/arm/arm.c2
-rw-r--r--src/emu/cpu/cubeqcpu/cubeqcpu.c6
-rw-r--r--src/emu/cpu/g65816/g65816.c2
-rw-r--r--src/emu/cpu/h83002/h8_16.c2
-rw-r--r--src/emu/cpu/h83002/h8_8.c2
-rw-r--r--src/emu/cpu/hd6309/hd6309.c2
-rw-r--r--src/emu/cpu/i386/i386.c2
-rw-r--r--src/emu/cpu/jaguar/jaguar.c2
-rw-r--r--src/emu/cpu/m37710/m37710.c28
-rw-r--r--src/emu/cpu/m68000/m68kcpu.c4
-rw-r--r--src/emu/cpu/mips/psx.c2
-rw-r--r--src/emu/cpu/tms34010/tms34010.c2
-rw-r--r--src/emu/debug/debugcmd.c2
-rw-r--r--src/emu/debug/dvmemory.c2
-rw-r--r--src/emu/devintrf.c9
-rw-r--r--src/emu/devintrf.h7
-rw-r--r--src/emu/diexec.c3
-rw-r--r--src/emu/emu.h8
-rw-r--r--src/emu/emucore.h3
-rw-r--r--src/emu/emupal.c4
-rw-r--r--src/emu/machine.c10
-rw-r--r--src/emu/machine.h4
-rw-r--r--src/emu/machine/pci.c2
-rw-r--r--src/emu/machine/pit8253.c3
-rw-r--r--src/emu/memory.c6
-rw-r--r--src/emu/romload.h2
-rw-r--r--src/emu/schedule.c19
-rw-r--r--src/emu/schedule.h1
-rw-r--r--src/emu/screen.c31
-rw-r--r--src/emu/sound.c9
-rw-r--r--src/emu/sound/2151intf.c2
-rw-r--r--src/emu/sound/2203intf.c2
-rw-r--r--src/emu/sound/2608intf.c2
-rw-r--r--src/emu/sound/2610intf.c2
-rw-r--r--src/emu/sound/2612intf.c2
-rw-r--r--src/emu/sound/fm.c3
-rw-r--r--src/emu/sound/fm2612.c3
-rw-r--r--src/emu/sound/fmopl.c2
-rw-r--r--src/emu/sound/k054539.c2
-rw-r--r--src/emu/sound/msm5232.c2
-rw-r--r--src/emu/sound/pokey.c9
-rw-r--r--src/emu/sound/samples.c2
-rw-r--r--src/emu/sound/upd7759.c2
-rw-r--r--src/emu/sound/vlm5030.c2
-rw-r--r--src/emu/sound/ym2151.c2
-rw-r--r--src/emu/sound/ymz280b.c2
-rw-r--r--src/emu/speaker.h53
-rw-r--r--src/emu/state.c756
-rw-r--r--src/emu/state.h331
-rw-r--r--src/emu/tilemap.c2
-rw-r--r--src/emu/timer.c2
-rw-r--r--src/emu/video.c2
-rw-r--r--src/emu/video/mc6845.c2
-rw-r--r--src/emu/video/pc_video.c2
-rw-r--r--src/emu/video/poly.c2
-rw-r--r--src/emu/video/tms9927.c2
-rw-r--r--src/emu/video/voodoo.c5
-rw-r--r--src/mame/audio/8080bw.c2
-rw-r--r--src/mame/audio/cage.c3
-rw-r--r--src/mame/audio/dcs.c2
-rw-r--r--src/mame/drivers/20pacgal.c2
-rw-r--r--src/mame/drivers/ace.c2
-rw-r--r--src/mame/drivers/astrocde.c6
-rw-r--r--src/mame/drivers/atarig1.c2
-rw-r--r--src/mame/drivers/atarisy2.c2
-rw-r--r--src/mame/drivers/atetris.c2
-rw-r--r--src/mame/drivers/crystal.c2
-rw-r--r--src/mame/drivers/darius.c2
-rw-r--r--src/mame/drivers/djmain.c2
-rw-r--r--src/mame/drivers/dynax.c4
-rw-r--r--src/mame/drivers/forte2.c2
-rw-r--r--src/mame/drivers/gottlieb.c6
-rw-r--r--src/mame/drivers/liberatr.c6
-rw-r--r--src/mame/drivers/m90.c2
-rw-r--r--src/mame/drivers/m92.c2
-rw-r--r--src/mame/drivers/mjsister.c2
-rw-r--r--src/mame/drivers/mw8080bw.c2
-rw-r--r--src/mame/drivers/mystwarr.c2
-rw-r--r--src/mame/drivers/neogeo.c2
-rw-r--r--src/mame/drivers/ninjaw.c2
-rw-r--r--src/mame/drivers/othunder.c2
-rw-r--r--src/mame/drivers/pengadvb.c2
-rw-r--r--src/mame/drivers/psikyo4.c4
-rw-r--r--src/mame/drivers/renegade.c2
-rw-r--r--src/mame/drivers/slapshot.c2
-rw-r--r--src/mame/drivers/taito_f2.c2
-rw-r--r--src/mame/drivers/taito_h.c2
-rw-r--r--src/mame/drivers/taito_x.c2
-rw-r--r--src/mame/drivers/taito_z.c4
-rw-r--r--src/mame/drivers/taitoair.c2
-rw-r--r--src/mame/drivers/topspeed.c2
-rw-r--r--src/mame/drivers/vegas.c2
-rw-r--r--src/mame/drivers/warriorb.c2
-rw-r--r--src/mame/drivers/wgp.c2
-rw-r--r--src/mame/drivers/xexex.c2
-rw-r--r--src/mame/drivers/xmen.c2
-rw-r--r--src/mame/machine/atarigen.c2
-rw-r--r--src/mame/machine/midwayic.c3
-rw-r--r--src/mame/machine/naomibd.c2
-rw-r--r--src/mame/machine/nmk112.c2
-rw-r--r--src/mame/machine/psx.c2
-rw-r--r--src/mame/machine/s16fd.c2
-rw-r--r--src/mame/machine/s24fd.c2
-rw-r--r--src/mame/machine/simpsons.c2
-rw-r--r--src/mame/machine/tnzs.c4
-rw-r--r--src/mame/machine/toaplan1.c2
-rw-r--r--src/mame/machine/twincobr.c6
-rw-r--r--src/mame/machine/vertigo.c3
-rw-r--r--src/mame/machine/williams.c4
-rw-r--r--src/mame/video/40love.c2
-rw-r--r--src/mame/video/atarimo.c4
-rw-r--r--src/mame/video/cave.c2
-rw-r--r--src/mame/video/chaknpop.c2
-rw-r--r--src/mame/video/cloak.c2
-rw-r--r--src/mame/video/cps1.c2
-rw-r--r--src/mame/video/gradius3.c2
-rw-r--r--src/mame/video/gridlee.c2
-rw-r--r--src/mame/video/gtia.c2
-rw-r--r--src/mame/video/hyprduel.c2
-rw-r--r--src/mame/video/jaguar.c2
-rw-r--r--src/mame/video/konamiic.c6
-rw-r--r--src/mame/video/konicdev.c6
-rw-r--r--src/mame/video/nemesis.c2
-rw-r--r--src/mame/video/neogeo.c2
-rw-r--r--src/mame/video/psx.c4
-rw-r--r--src/mame/video/stvvdp1.c2
-rw-r--r--src/mame/video/stvvdp2.c2
-rw-r--r--src/mame/video/tail2nos.c2
-rw-r--r--src/mame/video/taitoic.c10
-rw-r--r--src/mame/video/toaplan1.c4
-rw-r--r--src/mame/video/tumbleb.c12
-rw-r--r--src/mame/video/twincobr.c2
-rw-r--r--src/mame/video/ygv608.c2
133 files changed, 740 insertions, 854 deletions
diff --git a/src/emu/cpu/arm/arm.c b/src/emu/cpu/arm/arm.c
index 420ddef7c8a..28f420e98f9 100644
--- a/src/emu/cpu/arm/arm.c
+++ b/src/emu/cpu/arm/arm.c
@@ -535,7 +535,6 @@ static CPU_INIT( arm )
state_save_register_device_item_array(device, 0, cpustate->coproRegister);
state_save_register_device_item(device, 0, cpustate->pendingIrq);
state_save_register_device_item(device, 0, cpustate->pendingFiq);
- state_save_register_device_item(device, 0, cpustate->endian);
}
@@ -552,7 +551,6 @@ static CPU_INIT( arm_be )
state_save_register_device_item_array(device, 0, cpustate->coproRegister);
state_save_register_device_item(device, 0, cpustate->pendingIrq);
state_save_register_device_item(device, 0, cpustate->pendingFiq);
- state_save_register_device_item(device, 0, cpustate->endian);
}
diff --git a/src/emu/cpu/cubeqcpu/cubeqcpu.c b/src/emu/cpu/cubeqcpu/cubeqcpu.c
index db01be30ffe..7b45fd6fb5e 100644
--- a/src/emu/cpu/cubeqcpu/cubeqcpu.c
+++ b/src/emu/cpu/cubeqcpu/cubeqcpu.c
@@ -275,7 +275,7 @@ static void cquestsnd_state_register(device_t *device)
state_save_register_device_item(device, 0, cpustate->prev_ipram);
state_save_register_device_item(device, 0, cpustate->prev_ipwrt);
- state_save_register_postload(device->machine, cquestsnd_postload, (void *)device);
+ device->machine->state().register_postload(cquestsnd_postload, (void *)device);
}
static CPU_INIT( cquestsnd )
@@ -349,7 +349,7 @@ static void cquestrot_state_register(device_t *device)
state_save_register_device_item_pointer(device, 0, cpustate->dram, 16384);
state_save_register_device_item_pointer(device, 0, cpustate->sram, 2048);
- state_save_register_postload(device->machine, cquestrot_postload, (void *)device);
+ device->machine->state().register_postload(cquestrot_postload, (void *)device);
}
static CPU_INIT( cquestrot )
@@ -433,7 +433,7 @@ static void cquestlin_state_register(device_t *device)
state_save_register_device_item_pointer(device, 0, cpustate->e_stack, 32768);
state_save_register_device_item_pointer(device, 0, cpustate->o_stack, 32768);
- state_save_register_postload(device->machine, cquestlin_postload, (void *)device);
+ device->machine->state().register_postload(cquestlin_postload, (void *)device);
}
static CPU_INIT( cquestlin )
diff --git a/src/emu/cpu/g65816/g65816.c b/src/emu/cpu/g65816/g65816.c
index a54a6c93962..1ad3e64aec5 100644
--- a/src/emu/cpu/g65816/g65816.c
+++ b/src/emu/cpu/g65816/g65816.c
@@ -365,7 +365,7 @@ static CPU_INIT( g65816 )
state_save_register_device_item(device, 0, cpustate->irq_delay);
state_save_register_device_item(device, 0, cpustate->stopped);
- state_save_register_postload(device->machine, g65816_restore_state, cpustate);
+ device->machine->state().register_postload(g65816_restore_state, cpustate);
}
/**************************************************************************
diff --git a/src/emu/cpu/h83002/h8_16.c b/src/emu/cpu/h83002/h8_16.c
index d276714eb72..cea2931af24 100644
--- a/src/emu/cpu/h83002/h8_16.c
+++ b/src/emu/cpu/h83002/h8_16.c
@@ -237,7 +237,7 @@ static CPU_INIT(h8)
state_save_register_device_item(device, 0, h8->h8TSTR);
state_save_register_device_item_array(device, 0, h8->h8TCNT);
- state_save_register_postload(device->machine, h8_onstateload, h8);
+ device->machine->state().register_postload(h8_onstateload, h8);
h8_itu_init(h8);
}
diff --git a/src/emu/cpu/h83002/h8_8.c b/src/emu/cpu/h83002/h8_8.c
index f145e415b34..f7d98ae8bcd 100644
--- a/src/emu/cpu/h83002/h8_8.c
+++ b/src/emu/cpu/h83002/h8_8.c
@@ -259,7 +259,7 @@ static CPU_INIT(h8bit)
state_save_register_device_item(device, 0, h8->h8TSTR);
state_save_register_device_item_array(device, 0, h8->h8TCNT);
- state_save_register_postload(h8->device->machine, h8_onstateload, h8);
+ h8->device->machine->state().register_postload(h8_onstateload, h8);
}
static CPU_RESET(h8bit)
diff --git a/src/emu/cpu/hd6309/hd6309.c b/src/emu/cpu/hd6309/hd6309.c
index 74602866f5a..8adeb17f8e0 100644
--- a/src/emu/cpu/hd6309/hd6309.c
+++ b/src/emu/cpu/hd6309/hd6309.c
@@ -541,7 +541,7 @@ static CPU_INIT( hd6309 )
state_save_register_device_item(device, 0, DP);
state_save_register_device_item(device, 0, CC);
state_save_register_device_item(device, 0, MD);
- state_save_register_postload(device->machine, hd6309_postload, (void *) device);
+ device->machine->state().register_postload(hd6309_postload, (void *) device);
state_save_register_device_item(device, 0, m68_state->int_state);
state_save_register_device_item(device, 0, m68_state->nmi_state);
state_save_register_device_item(device, 0, m68_state->irq_state[0]);
diff --git a/src/emu/cpu/i386/i386.c b/src/emu/cpu/i386/i386.c
index 6eba89454a0..d3999ab8685 100644
--- a/src/emu/cpu/i386/i386.c
+++ b/src/emu/cpu/i386/i386.c
@@ -605,7 +605,7 @@ static CPU_INIT( i386 )
state_save_register_device_item(device, 0, cpustate->ldtr.flags);
state_save_register_device_item(device, 0, cpustate->irq_state);
state_save_register_device_item(device, 0, cpustate->performed_intersegment_jump);
- state_save_register_postload(device->machine, i386_postload, (void *)device);
+ device->machine->state().register_postload(i386_postload, (void *)device);
}
static void build_opcode_table(i386_state *cpustate, UINT32 features)
diff --git a/src/emu/cpu/jaguar/jaguar.c b/src/emu/cpu/jaguar/jaguar.c
index ddcf2c7df91..0ece28b5d3c 100644
--- a/src/emu/cpu/jaguar/jaguar.c
+++ b/src/emu/cpu/jaguar/jaguar.c
@@ -430,7 +430,7 @@ static void init_common(int isdsp, legacy_cpu_device *device, device_irq_callbac
state_save_register_device_item_array(device, 0, jaguar->a);
state_save_register_device_item_array(device, 0, jaguar->ctrl);
state_save_register_device_item(device, 0, jaguar->ppc);
- state_save_register_postload(device->machine, jaguar_postload, (void *)device);
+ device->machine->state().register_postload(jaguar_postload, (void *)device);
}
diff --git a/src/emu/cpu/m37710/m37710.c b/src/emu/cpu/m37710/m37710.c
index 29de9d00cfe..bd17e16ec04 100644
--- a/src/emu/cpu/m37710/m37710.c
+++ b/src/emu/cpu/m37710/m37710.c
@@ -940,24 +940,16 @@ static CPU_INIT( m37710 )
state_save_register_device_item(device, 0, cpustate->irq_level);
state_save_register_device_item(device, 0, cpustate->stopped);
state_save_register_device_item_array(device, 0, cpustate->m37710_regs);
- state_save_register_device_item(device, 0, cpustate->reload[0].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[0].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[1].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[1].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[2].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[2].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[3].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[3].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[4].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[4].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[5].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[5].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[6].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[6].attoseconds);
- state_save_register_device_item(device, 0, cpustate->reload[7].seconds);
- state_save_register_device_item(device, 0, cpustate->reload[7].attoseconds);
-
- state_save_register_postload(device->machine, m37710_restore_state, cpustate);
+ state_save_register_device_item(device, 0, cpustate->reload[0]);
+ state_save_register_device_item(device, 0, cpustate->reload[1]);
+ state_save_register_device_item(device, 0, cpustate->reload[2]);
+ state_save_register_device_item(device, 0, cpustate->reload[3]);
+ state_save_register_device_item(device, 0, cpustate->reload[4]);
+ state_save_register_device_item(device, 0, cpustate->reload[5]);
+ state_save_register_device_item(device, 0, cpustate->reload[6]);
+ state_save_register_device_item(device, 0, cpustate->reload[7]);
+
+ device->machine->state().register_postload(m37710_restore_state, cpustate);
}
/**************************************************************************
diff --git a/src/emu/cpu/m68000/m68kcpu.c b/src/emu/cpu/m68000/m68kcpu.c
index 4738f23dd37..2dbbc94fbc1 100644
--- a/src/emu/cpu/m68000/m68kcpu.c
+++ b/src/emu/cpu/m68000/m68kcpu.c
@@ -769,8 +769,8 @@ static CPU_INIT( m68k )
state_save_register_device_item(device, 0, m68k->save_halted);
state_save_register_device_item(device, 0, m68k->pref_addr);
state_save_register_device_item(device, 0, m68k->pref_data);
- state_save_register_presave(device->machine, m68k_presave, m68k);
- state_save_register_postload(device->machine, m68k_postload, m68k);
+ device->machine->state().register_presave(m68k_presave, m68k);
+ device->machine->state().register_postload(m68k_postload, m68k);
}
/* Pulse the RESET line on the CPU */
diff --git a/src/emu/cpu/mips/psx.c b/src/emu/cpu/mips/psx.c
index c613887b563..7a7d6bdec9e 100644
--- a/src/emu/cpu/mips/psx.c
+++ b/src/emu/cpu/mips/psx.c
@@ -1627,7 +1627,7 @@ static void mips_state_register( const char *type, legacy_cpu_device *device )
state_save_register_device_item( device, 0, psxcpu->multiplier_operation );
state_save_register_device_item( device, 0, psxcpu->multiplier_operand1 );
state_save_register_device_item( device, 0, psxcpu->multiplier_operand2 );
- state_save_register_postload( device->machine, mips_postload, psxcpu );
+ device->machine->state().register_postload( mips_postload, psxcpu );
}
static CPU_INIT( psxcpu )
diff --git a/src/emu/cpu/tms34010/tms34010.c b/src/emu/cpu/tms34010/tms34010.c
index 752ef891ac5..42db4963dc6 100644
--- a/src/emu/cpu/tms34010/tms34010.c
+++ b/src/emu/cpu/tms34010/tms34010.c
@@ -669,7 +669,7 @@ static CPU_INIT( tms34010 )
state_save_register_device_item(device, 0, tms->pixelshift);
state_save_register_device_item(device, 0, tms->gfxcycles);
state_save_register_device_item_pointer(device, 0, (&tms->regs[0].reg), ARRAY_LENGTH(tms->regs));
- state_save_register_postload(device->machine, tms34010_state_postload, tms);
+ device->machine->state().register_postload(tms34010_state_postload, tms);
}
static CPU_RESET( tms34010 )
diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c
index 8c5c98ef234..d7c3e5d88d7 100644
--- a/src/emu/debug/debugcmd.c
+++ b/src/emu/debug/debugcmd.c
@@ -244,7 +244,7 @@ void debug_command_init(running_machine *machine)
void *base;
/* stop when we run out of items */
- name = state_save_get_indexed_item(machine, itemnum, &base, &valsize, &valcount);
+ name = machine->state().indexed_item(itemnum, base, valsize, valcount);
if (name == NULL)
break;
diff --git a/src/emu/debug/dvmemory.c b/src/emu/debug/dvmemory.c
index dda57369e86..dce4f239f59 100644
--- a/src/emu/debug/dvmemory.c
+++ b/src/emu/debug/dvmemory.c
@@ -177,7 +177,7 @@ void debug_view_memory::enumerate_sources()
// stop when we run out of items
UINT32 valsize, valcount;
void *base;
- const char *itemname = state_save_get_indexed_item(&m_machine, itemnum, &base, &valsize, &valcount);
+ const char *itemname = m_machine.state().indexed_item(itemnum, base, valsize, valcount);
if (itemname == NULL)
break;
diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c
index 685dc0950e7..f6f1b91ba41 100644
--- a/src/emu/devintrf.c
+++ b/src/emu/devintrf.c
@@ -134,8 +134,8 @@ void device_list::start_all()
m_machine->add_notifier(MACHINE_NOTIFY_EXIT, static_exit);
// add pre-save and post-load callbacks
- state_save_register_presave(m_machine, static_pre_save, this);
- state_save_register_postload(m_machine, static_post_load, this);
+ m_machine->state().register_presave(static_pre_save, this);
+ m_machine->state().register_postload(static_post_load, this);
// iterate over devices to start them
device_t *nextdevice;
@@ -535,6 +535,7 @@ void device_interface::interface_debug_setup()
device_t::device_t(running_machine &_machine, const device_config &config)
: machine(&_machine),
m_machine(_machine),
+ m_state_manager(_machine.state()),
m_debug(NULL),
m_execute(NULL),
m_memory(NULL),
@@ -724,13 +725,13 @@ void device_t::start()
intf->interface_pre_start();
// remember the number of state registrations
- int state_registrations = state_save_get_reg_count(machine);
+ int state_registrations = machine->state().registration_count();
// start the device
device_start();
// complain if nothing was registered by the device
- state_registrations = state_save_get_reg_count(machine) - state_registrations;
+ state_registrations = machine->state().registration_count() - state_registrations;
device_execute_interface *exec;
device_sound_interface *sound;
if (state_registrations == 0 && (interface(exec) || interface(sound)))
diff --git a/src/emu/devintrf.h b/src/emu/devintrf.h
index 14b62f9b269..05d319caa7e 100644
--- a/src/emu/devintrf.h
+++ b/src/emu/devintrf.h
@@ -437,6 +437,12 @@ public:
void synchronize(device_timer_id id = 0, int param = 0, void *ptr = NULL) { timer_set(attotime::zero, id, param, ptr); }
void timer_expired(emu_timer &timer, device_timer_id id, int param, void *ptr) { device_timer(timer, id, param, ptr); }
+ // state saving interfaces
+ template<typename T>
+ void save_item(T &value, const char *valname, int index = 0) { m_state_manager.save_item(name(), tag(), index, value, valname); }
+ template<typename T>
+ void save_pointer(T *value, const char *valname, UINT32 count, int index = 0) { m_state_manager.save_pointer(name(), tag(), index, value, valname); }
+
// debugging
device_debug *debug() const { return m_debug; }
@@ -475,6 +481,7 @@ protected:
//------------------- end derived class overrides
running_machine & m_machine;
+ state_manager & m_state_manager;
device_debug * m_debug;
// for speed
diff --git a/src/emu/diexec.c b/src/emu/diexec.c
index f0e8fa18ecd..6e116c86833 100644
--- a/src/emu/diexec.c
+++ b/src/emu/diexec.c
@@ -569,8 +569,7 @@ void device_execute_interface::interface_pre_start()
state_save_register_device_item(&m_device, 0, m_nexteatcycles);
state_save_register_device_item(&m_device, 0, m_trigger);
state_save_register_device_item(&m_device, 0, m_totalcycles);
- state_save_register_device_item(&m_device, 0, m_localtime.seconds);
- state_save_register_device_item(&m_device, 0, m_localtime.attoseconds);
+ state_save_register_device_item(&m_device, 0, m_localtime);
state_save_register_device_item(&m_device, 0, m_iloops);
}
diff --git a/src/emu/emu.h b/src/emu/emu.h
index 8659d2ce5b0..9cb34fbe1cf 100644
--- a/src/emu/emu.h
+++ b/src/emu/emu.h
@@ -70,6 +70,10 @@
#include "memory.h"
#include "addrmap.h"
+// machine-wide utilities
+#include "romload.h"
+#include "state.h"
+
// define machine_config_constructor here due to circular dependency
// between devices and the machine config
class machine_config;
@@ -103,10 +107,6 @@ typedef device_config * (*machine_config_constructor)(machine_config &config, de
#include "mconfig.h"
#include "driver.h"
-// machine-wide utilities
-#include "romload.h"
-#include "state.h"
-
// image-related
#include "softlist.h"
#include "image.h"
diff --git a/src/emu/emucore.h b/src/emu/emucore.h
index 02b85a20a01..086a4af1af7 100644
--- a/src/emu/emucore.h
+++ b/src/emu/emucore.h
@@ -198,6 +198,9 @@ inline void operator--(_Type &value) { value = (_Type)((int)value - 1); } \
inline void operator--(_Type &value, int) { value = (_Type)((int)value - 1); }
+// this macro passes an item followed by a string version of itself as two consecutive parameters
+#define NAME(x) x, #x
+
// this macro wraps a function 'x' and can be used to pass a function followed by its name
#define FUNC(x) x, #x
diff --git a/src/emu/emupal.c b/src/emu/emupal.c
index 2950b7de3e8..7b705e0ce79 100644
--- a/src/emu/emupal.c
+++ b/src/emu/emupal.c
@@ -143,8 +143,8 @@ void palette_init(running_machine *machine)
palette->save_bright = auto_alloc_array(machine, float, numcolors);
state_save_register_global_pointer(machine, palette->save_pen, numcolors);
state_save_register_global_pointer(machine, palette->save_bright, numcolors);
- state_save_register_presave(machine, palette_presave, palette);
- state_save_register_postload(machine, palette_postload, palette);
+ machine->state().register_presave(palette_presave, palette);
+ machine->state().register_postload(palette_postload, palette);
}
}
diff --git a/src/emu/machine.c b/src/emu/machine.c
index cea7fb73649..b64f6ff0bc5 100644
--- a/src/emu/machine.c
+++ b/src/emu/machine.c
@@ -154,7 +154,6 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o
sample_rate(options_get_int(&options, OPTION_SAMPLERATE)),
debug_flags(0),
ui_active(false),
- state_data(NULL),
memory_data(NULL),
palette_data(NULL),
tilemap_data(NULL),
@@ -167,6 +166,7 @@ running_machine::running_machine(const machine_config &_config, osd_interface &o
generic_video_data(NULL),
generic_audio_data(NULL),
m_logerror_list(NULL),
+ m_state(*this),
m_scheduler(*this),
m_options(options),
m_osd(osd),
@@ -264,15 +264,11 @@ void running_machine::start()
config_init(this);
input_init(this);
output_init(this);
- state_init(this);
- state_save_allow_registration(this, true);
palette_init(this);
m_render = auto_alloc(this, render_manager(*this));
generic_machine_init(this);
generic_sound_init(this);
- m_scheduler.register_for_save();
-
// allocate a soft_reset timer
m_soft_reset_timer = m_scheduler.timer_alloc(MSTUB(timer_expired, running_machine, soft_reset), this);
@@ -344,7 +340,7 @@ void running_machine::start()
m_cheat = auto_alloc(this, cheat_manager(*this));
// disallow save state registrations starting here
- state_save_allow_registration(this, false);
+ m_state.allow_registration(false);
}
@@ -798,7 +794,7 @@ void running_machine::handle_saveload()
astring fullname(mame_file_full_name(file));
// read/write the save state
- state_save_error staterr = (m_saveload_schedule == SLS_LOAD) ? state_save_read_file(this, file) : state_save_write_file(this, file);
+ state_save_error staterr = (m_saveload_schedule == SLS_LOAD) ? m_state.read_file(file) : m_state.write_file(file);
// handle the result
switch (staterr)
diff --git a/src/emu/machine.h b/src/emu/machine.h
index 6c237de4264..153ebc016b1 100644
--- a/src/emu/machine.h
+++ b/src/emu/machine.h
@@ -187,7 +187,6 @@ class video_manager;
class debug_view_manager;
class osd_interface;
-typedef struct _state_private state_private;
typedef struct _memory_private memory_private;
typedef struct _palette_private palette_private;
typedef struct _tilemap_private tilemap_private;
@@ -356,6 +355,7 @@ public:
bool exit_pending() const { return m_exit_pending; }
bool new_driver_pending() const { return (m_new_driver_pending != NULL); }
const char *new_driver_name() const { return m_new_driver_pending->name; }
+ state_manager &state() { return m_state; }
device_scheduler &scheduler() { return m_scheduler; }
osd_interface &osd() const { return m_osd; }
screen_device *first_screen() const { return primary_screen; }
@@ -440,7 +440,6 @@ public:
generic_pointers generic; // generic pointers
// internal core information
- state_private * state_data; // internal data from state.c
memory_private * memory_data; // internal data from memory.c
palette_private * palette_data; // internal data from palette.c
tilemap_private * tilemap_data; // internal data from tilemap.c
@@ -486,6 +485,7 @@ private:
};
logerror_callback_item *m_logerror_list;
+ state_manager m_state; // state manager
device_scheduler m_scheduler; // scheduler object
core_options & m_options;
osd_interface & m_osd;
diff --git a/src/emu/machine/pci.c b/src/emu/machine/pci.c
index a3534f3e76d..2bcaac38a5a 100644
--- a/src/emu/machine/pci.c
+++ b/src/emu/machine/pci.c
@@ -292,7 +292,7 @@ static DEVICE_START( pci_bus )
state_save_register_device_item(device, 0, pcibus->devicenum);
state_save_register_device_item(device, 0, pcibus->busnum);
- state_save_register_postload(device->machine, pci_bus_postload, pcibus);
+ device->machine->state().register_postload(pci_bus_postload, pcibus);
}
diff --git a/src/emu/machine/pit8253.c b/src/emu/machine/pit8253.c
index 050cd38eea0..e526674dd3e 100644
--- a/src/emu/machine/pit8253.c
+++ b/src/emu/machine/pit8253.c
@@ -1105,8 +1105,7 @@ static void common_start( device_t *device, int device_type ) {
state_save_register_device_item(device, timerno, timer->null_count);
state_save_register_device_item(device, timerno, timer->phase);
state_save_register_device_item(device, timerno, timer->cycles_to_output);
- state_save_register_device_item(device, timerno, timer->last_updated.seconds);
- state_save_register_device_item(device, timerno, timer->last_updated.attoseconds);
+ state_save_register_device_item(device, timerno, timer->last_updated);
state_save_register_device_item(device, timerno, timer->clock);
}
}
diff --git a/src/emu/memory.c b/src/emu/memory.c
index abf6a424965..8556edd2078 100644
--- a/src/emu/memory.c
+++ b/src/emu/memory.c
@@ -1590,7 +1590,7 @@ void memory_init(running_machine *machine)
space->locate_memory();
// register a callback to reset banks when reloading state
- state_save_register_postload(machine, bank_reattach, NULL);
+ machine->state().register_postload(bank_reattach, NULL);
// dump the final memory configuration
generate_memdump(machine);
@@ -4092,7 +4092,7 @@ memory_block::memory_block(address_space &space, offs_t bytestart, offs_t byteen
int bytes_per_element = space.data_width() / 8;
astring name;
name.printf("%08x-%08x", bytestart, byteend);
- state_save_register_memory(&space.m_machine, "memory", space.device().tag(), space.spacenum(), name, m_data, bytes_per_element, (UINT32)(byteend + 1 - bytestart) / bytes_per_element, __FILE__, __LINE__);
+ space.m_machine.state().save_memory("memory", space.device().tag(), space.spacenum(), name, m_data, bytes_per_element, (UINT32)(byteend + 1 - bytestart) / bytes_per_element);
}
}
@@ -4142,7 +4142,7 @@ memory_bank::memory_bank(address_space &space, int index, offs_t bytestart, offs
m_name.printf("Bank '%s'", tag);
}
- if (!m_anonymous && state_save_registration_allowed(&space.m_machine))
+ if (!m_anonymous && space.m_machine.state().registration_allowed())
state_save_register_item(&space.m_machine, "memory", m_tag, 0, m_curentry);
}
diff --git a/src/emu/romload.h b/src/emu/romload.h
index 2a653185bb0..039042ffae4 100644
--- a/src/emu/romload.h
+++ b/src/emu/romload.h
@@ -123,6 +123,8 @@ enum
TYPE DEFINITIONS
***************************************************************************/
+class machine_config;
+
typedef device_config rom_source;
diff --git a/src/emu/schedule.c b/src/emu/schedule.c
index 5b20495563a..47f31bb8a85 100644
--- a/src/emu/schedule.c
+++ b/src/emu/schedule.c
@@ -283,12 +283,9 @@ void emu_timer::register_save()
// save the bits
state_save_register_item(m_machine, "timer", name, index, m_param);
state_save_register_item(m_machine, "timer", name, index, m_enabled);
- state_save_register_item(m_machine, "timer", name, index, m_period.seconds);
- state_save_register_item(m_machine, "timer", name, index, m_period.attoseconds);
- state_save_register_item(m_machine, "timer", name, index, m_start.seconds);
- state_save_register_item(m_machine, "timer", name, index, m_start.attoseconds);
- state_save_register_item(m_machine, "timer", name, index, m_expire.seconds);
- state_save_register_item(m_machine, "timer", name, index, m_expire.attoseconds);
+ state_save_register_item(m_machine, "timer", name, index, m_period);
+ state_save_register_item(m_machine, "timer", name, index, m_start);
+ state_save_register_item(m_machine, "timer", name, index, m_expire);
}
@@ -336,16 +333,10 @@ device_scheduler::device_scheduler(running_machine &machine) :
// append a single never-expiring timer so there is always one in the list
m_timer_list = &m_timer_allocator.alloc()->init(m_machine, NULL, NULL, NULL, true);
m_timer_list->adjust(attotime::never);
-}
-
-// remove me once save state registration is embedded
-void device_scheduler::register_for_save()
-{
// register global states
- state_save_register_item(&m_machine, "timer", NULL, 0, m_basetime.seconds);
- state_save_register_item(&m_machine, "timer", NULL, 0, m_basetime.attoseconds);
- state_save_register_postload(&m_machine, &state_postload_stub<device_scheduler, &device_scheduler::postload>, this);
+ state_save_register_item(&m_machine, "timer", NULL, 0, m_basetime);
+ m_machine.state().register_postload(&state_postload_stub<device_scheduler, &device_scheduler::postload>, this);
}
diff --git a/src/emu/schedule.h b/src/emu/schedule.h
index 63f87b484d9..e60978bf6ec 100644
--- a/src/emu/schedule.h
+++ b/src/emu/schedule.h
@@ -155,7 +155,6 @@ public:
// construction/destruction
device_scheduler(running_machine &machine);
~device_scheduler();
- void register_for_save();
// getters
attotime time() const;
diff --git a/src/emu/screen.c b/src/emu/screen.c
index 41d7d4dfc5f..9f3cba08710 100644
--- a/src/emu/screen.c
+++ b/src/emu/screen.c
@@ -379,22 +379,21 @@ void screen_device::device_start()
if (overname != NULL && strcmp(overname, "none") != 0)
load_effect_overlay(overname);
- state_save_register_device_item(this, 0, m_width);
- state_save_register_device_item(this, 0, m_height);
- state_save_register_device_item(this, 0, m_visarea.min_x);
- state_save_register_device_item(this, 0, m_visarea.min_y);
- state_save_register_device_item(this, 0, m_visarea.max_x);
- state_save_register_device_item(this, 0, m_visarea.max_y);
- state_save_register_device_item(this, 0, m_last_partial_scan);
- state_save_register_device_item(this, 0, m_frame_period);
- state_save_register_device_item(this, 0, m_scantime);
- state_save_register_device_item(this, 0, m_pixeltime);
- state_save_register_device_item(this, 0, m_vblank_period);
- state_save_register_device_item(this, 0, m_vblank_start_time.seconds);
- state_save_register_device_item(this, 0, m_vblank_start_time.attoseconds);
- state_save_register_device_item(this, 0, m_vblank_end_time.seconds);
- state_save_register_device_item(this, 0, m_vblank_end_time.attoseconds);
- state_save_register_device_item(this, 0, m_frame_number);
+ // register items for saving
+ save_item(NAME(m_width));
+ save_item(NAME(m_height));
+ save_item(NAME(m_visarea.min_x));
+ save_item(NAME(m_visarea.min_y));
+ save_item(NAME(m_visarea.max_x));
+ save_item(NAME(m_visarea.max_y));
+ save_item(NAME(m_last_partial_scan));
+ save_item(NAME(m_frame_period));
+ save_item(NAME(m_scantime));
+ save_item(NAME(m_pixeltime));
+ save_item(NAME(m_vblank_period));
+ save_item(NAME(m_vblank_start_time));
+ save_item(NAME(m_vblank_end_time));
+ save_item(NAME(m_frame_number));
}
diff --git a/src/emu/sound.c b/src/emu/sound.c
index 775bc3efc06..7a324bab630 100644
--- a/src/emu/sound.c
+++ b/src/emu/sound.c
@@ -112,7 +112,7 @@ sound_stream::sound_stream(device_t &device, int inputs, int outputs, int sample
astring state_tag;
state_tag.printf("%d", m_device.machine->sound().m_stream_list.count());
state_save_register_item(m_device.machine, "stream", state_tag, 0, m_sample_rate);
- state_save_register_postload(m_device.machine, state_postload_stub<sound_stream, &sound_stream::postload>, this);
+ m_device.machine->state().register_postload(state_postload_stub<sound_stream, &sound_stream::postload>, this);
// save the gain of each input and output
for (int inputnum = 0; inputnum < m_inputs; inputnum++)
@@ -806,8 +806,7 @@ sound_manager::sound_manager(running_machine &machine)
machine.add_notifier(MACHINE_NOTIFY_RESET, &sound_manager::reset);
// register global states
- state_save_register_global(&machine, m_last_update.seconds);
- state_save_register_global(&machine, m_last_update.attoseconds);
+ state_save_register_global(&machine, m_last_update);
// set the starting attenuation
set_attenuation(options_get_int(machine.options(), OPTION_VOLUME));
@@ -863,7 +862,7 @@ void sound_manager::set_attenuation(int attenuation)
bool sound_manager::indexed_speaker_input(int index, speaker_input &info) const
{
// scan through the speakers until we find the indexed input
- for (info.speaker = downcast<speaker_device *>(m_machine.m_devicelist.first(SPEAKER)); info.speaker != NULL; info.speaker = downcast<speaker_device *>(info.speaker->typenext()))
+ for (info.speaker = downcast<speaker_device *>(m_machine.m_devicelist.first(SPEAKER)); info.speaker != NULL; info.speaker = info.speaker->next_speaker())
{
if (index < info.speaker->inputs())
{
@@ -1004,7 +1003,7 @@ void sound_manager::update()
// force all the speaker streams to generate the proper number of samples
int samples_this_update = 0;
- for (speaker_device *speaker = downcast<speaker_device *>(m_machine.m_devicelist.first(SPEAKER)); speaker != NULL; speaker = downcast<speaker_device *>(speaker->typenext()))
+ for (speaker_device *speaker = downcast<speaker_device *>(m_machine.m_devicelist.first(SPEAKER)); speaker != NULL; speaker = speaker->next_speaker())
speaker->mix(m_leftmix, m_rightmix, samples_this_update, (m_muted & MUTE_REASON_SYSTEM));
// now downmix the final result
diff --git a/src/emu/sound/2151intf.c b/src/emu/sound/2151intf.c
index 12d713caf4e..1531cf82c95 100644
--- a/src/emu/sound/2151intf.c
+++ b/src/emu/sound/2151intf.c
@@ -61,7 +61,7 @@ static DEVICE_START( ym2151 )
info->chip = ym2151_init(device,device->clock(),rate);
assert_always(info->chip != NULL, "Error creating YM2151 chip");
- state_save_register_postload(device->machine, ym2151intf_postload, info);
+ device->machine->state().register_postload(ym2151intf_postload, info);
ym2151_set_irq_handler(info->chip,info->intf->irqhandler);
ym2151_set_port_write_handler(info->chip,info->intf->portwritehandler);
diff --git a/src/emu/sound/2203intf.c b/src/emu/sound/2203intf.c
index 2ee37092c24..1604af2a8cd 100644
--- a/src/emu/sound/2203intf.c
+++ b/src/emu/sound/2203intf.c
@@ -144,7 +144,7 @@ static DEVICE_START( ym2203 )
info->chip = ym2203_init(info,device,device->clock(),rate,timer_handler,IRQHandler,&psgintf);
assert_always(info->chip != NULL, "Error creating YM2203 chip");
- state_save_register_postload(device->machine, ym2203_intf_postload, info);
+ device->machine->state().register_postload(ym2203_intf_postload, info);
}
static DEVICE_STOP( ym2203 )
diff --git a/src/emu/sound/2608intf.c b/src/emu/sound/2608intf.c
index 910207cfd32..9d54be5f90b 100644
--- a/src/emu/sound/2608intf.c
+++ b/src/emu/sound/2608intf.c
@@ -167,7 +167,7 @@ static DEVICE_START( ym2608 )
timer_handler,IRQHandler,&psgintf);
assert_always(info->chip != NULL, "Error creating YM2608 chip");
- state_save_register_postload(device->machine, ym2608_intf_postload, info);
+ device->machine->state().register_postload(ym2608_intf_postload, info);
}
static DEVICE_STOP( ym2608 )
diff --git a/src/emu/sound/2610intf.c b/src/emu/sound/2610intf.c
index 110d34445d9..e59bf97d8f8 100644
--- a/src/emu/sound/2610intf.c
+++ b/src/emu/sound/2610intf.c
@@ -179,7 +179,7 @@ static DEVICE_START( ym2610 )
timer_handler,IRQHandler,&psgintf);
assert_always(info->chip != NULL, "Error creating YM2610 chip");
- state_save_register_postload(device->machine, ym2610_intf_postload, info);
+ device->machine->state().register_postload(ym2610_intf_postload, info);
}
static DEVICE_STOP( ym2610 )
diff --git a/src/emu/sound/2612intf.c b/src/emu/sound/2612intf.c
index 0e6af28184d..88ca4ae82fa 100644
--- a/src/emu/sound/2612intf.c
+++ b/src/emu/sound/2612intf.c
@@ -118,7 +118,7 @@ static DEVICE_START( ym2612 )
info->chip = ym2612_init(info,device,device->clock(),rate,timer_handler,IRQHandler);
assert_always(info->chip != NULL, "Error creating YM2612 chip");
- state_save_register_postload(device->machine, ym2612_intf_postload, info);
+ device->machine->state().register_postload(ym2612_intf_postload, info);
}
diff --git a/src/emu/sound/fm.c b/src/emu/sound/fm.c
index bc2baf3a37a..1eba48e0622 100644
--- a/src/emu/sound/fm.c
+++ b/src/emu/sound/fm.c
@@ -1704,8 +1704,7 @@ static void FMsave_state_channel(device_t *device,FM_CH *CH,int num_ch)
static void FMsave_state_st(device_t *device,FM_ST *ST)
{
#if FM_BUSY_FLAG_SUPPORT
- state_save_register_device_item(device, 0, ST->busy_expiry_time.seconds );
- state_save_register_device_item(device, 0, ST->busy_expiry_time.attoseconds );
+ state_save_register_device_item(device, 0, ST->busy_expiry_time );
#endif
state_save_register_device_item(device, 0, ST->address );
state_save_register_device_item(device, 0, ST->irq );
diff --git a/src/emu/sound/fm2612.c b/src/emu/sound/fm2612.c
index 19eb58b2296..ea1ede395b5 100644
--- a/src/emu/sound/fm2612.c
+++ b/src/emu/sound/fm2612.c
@@ -1707,8 +1707,7 @@ static void FMsave_state_channel(device_t *device,FM_CH *CH,int num_ch)
static void FMsave_state_st(device_t *device,FM_ST *ST)
{
#if FM_BUSY_FLAG_SUPPORT
- state_save_register_device_item(device, 0, ST->busy_expiry_time.seconds );
- state_save_register_device_item(device, 0, ST->busy_expiry_time.attoseconds );
+ state_save_register_device_item(device, 0, ST->busy_expiry_time );
#endif
state_save_register_device_item(device, 0, ST->address );
state_save_register_device_item(device, 0, ST->irq );
diff --git a/src/emu/sound/fmopl.c b/src/emu/sound/fmopl.c
index a04c5db335c..f7fa61e34fc 100644
--- a/src/emu/sound/fmopl.c
+++ b/src/emu/sound/fmopl.c
@@ -1957,7 +1957,7 @@ static void OPL_save_state(FM_OPL *OPL, device_t *device)
state_save_register_device_item(device, 0, OPL->statusmask);
state_save_register_device_item(device, 0, OPL->mode);
- state_save_register_postload(device->machine, OPL_postload, OPL);
+ device->machine->state().register_postload(OPL_postload, OPL);
}
diff --git a/src/emu/sound/k054539.c b/src/emu/sound/k054539.c
index 24ce125184c..82c99c8828f 100644
--- a/src/emu/sound/k054539.c
+++ b/src/emu/sound/k054539.c
@@ -674,7 +674,7 @@ static DEVICE_START( k054539 )
k054539_init_chip(device, info);
- state_save_register_postload(device->machine, reset_zones, info);
+ device->machine->state().register_postload(reset_zones, info);
}
diff --git a/src/emu/sound/msm5232.c b/src/emu/sound/msm5232.c
index 3f89f65060f..329930584fb 100644
--- a/src/emu/sound/msm5232.c
+++ b/src/emu/sound/msm5232.c
@@ -799,7 +799,7 @@ static DEVICE_START( msm5232 )
chip->stream = device->machine->sound().stream_alloc(*device, 0, 11, rate, chip, MSM5232_update_one);
/* register with the save state system */
- state_save_register_postload(device->machine, msm5232_postload, chip);
+ device->machine->state().register_postload(msm5232_postload, chip);
state_save_register_device_item_array(device, 0, chip->EN_out16);
state_save_register_device_item_array(device, 0, chip->EN_out8);
state_save_register_device_item_array(device, 0, chip->EN_out4);
diff --git a/src/emu/sound/pokey.c b/src/emu/sound/pokey.c
index db0d3420b5a..7d108a48678 100644
--- a/src/emu/sound/pokey.c
+++ b/src/emu/sound/pokey.c
@@ -589,12 +589,9 @@ static void register_for_save(pokey_state *chip, device_t *device)
state_save_register_device_item(device, 0, chip->r9);
state_save_register_device_item(device, 0, chip->r17);
state_save_register_device_item(device, 0, chip->clockmult);
- state_save_register_device_item(device, 0, chip->timer_period[0].seconds);
- state_save_register_device_item(device, 0, chip->timer_period[0].attoseconds);
- state_save_register_device_item(device, 0, chip->timer_period[1].seconds);
- state_save_register_device_item(device, 0, chip->timer_period[1].attoseconds);
- state_save_register_device_item(device, 0, chip->timer_period[2].seconds);
- state_save_register_device_item(device, 0, chip->timer_period[2].attoseconds);
+ state_save_register_device_item(device, 0, chip->timer_period[0]);
+ state_save_register_device_item(device, 0, chip->timer_period[1]);
+ state_save_register_device_item(device, 0, chip->timer_period[2]);
state_save_register_device_item_array(device, 0, chip->timer_param);
state_save_register_device_item_array(device, 0, chip->AUDF);
state_save_register_device_item_array(device, 0, chip->AUDC);
diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c
index 2efb1501e3f..3615df582f4 100644
--- a/src/emu/sound/samples.c
+++ b/src/emu/sound/samples.c
@@ -501,7 +501,7 @@ static DEVICE_START( samples )
state_save_register_device_item(device, i, info->channel[i].loop);
state_save_register_device_item(device, i, info->channel[i].paused);
}
- state_save_register_postload(device->machine, samples_postload, info);
+ device->machine->state().register_postload(samples_postload, info);
/* initialize any custom handlers */
if (intf->start)
diff --git a/src/emu/sound/upd7759.c b/src/emu/sound/upd7759.c
index 98cc4f0d62d..0f2579d356f 100644
--- a/src/emu/sound/upd7759.c
+++ b/src/emu/sound/upd7759.c
@@ -628,7 +628,7 @@ static void register_for_save(upd7759_state *chip, device_t *device)
state_save_register_device_item(device, 0, chip->sample);
state_save_register_device_item(device, 0, chip->romoffset);
- state_save_register_postload(device->machine, upd7759_postload, chip);
+ device->machine->state().register_postload(upd7759_postload, chip);
}
diff --git a/src/emu/sound/vlm5030.c b/src/emu/sound/vlm5030.c
index 543d9b9915d..e18606e24a4 100644
--- a/src/emu/sound/vlm5030.c
+++ b/src/emu/sound/vlm5030.c
@@ -726,7 +726,7 @@ static DEVICE_START( vlm5030 )
state_save_register_device_item(device,0,chip->target_pitch);
state_save_register_device_item_array(device,0,chip->target_k);
state_save_register_device_item_array(device,0,chip->x);
- state_save_register_postload(device->machine, vlm5030_restore_state, chip);
+ device->machine->state().register_postload(vlm5030_restore_state, chip);
}
diff --git a/src/emu/sound/ym2151.c b/src/emu/sound/ym2151.c
index b124a16b9fb..8b8b7d0efc1 100644
--- a/src/emu/sound/ym2151.c
+++ b/src/emu/sound/ym2151.c
@@ -1485,7 +1485,7 @@ static void ym2151_state_save_register( YM2151 *chip, device_t *device )
state_save_register_device_item_array(device, 0, chip->connect);
- state_save_register_postload(device->machine, ym2151_postload, chip);
+ device->machine->state().register_postload(ym2151_postload, chip);
}
#else
STATE_POSTLOAD( ym2151_postload )
diff --git a/src/emu/sound/ymz280b.c b/src/emu/sound/ymz280b.c
index 61c7877dc4b..e3c931acce3 100644
--- a/src/emu/sound/ymz280b.c
+++ b/src/emu/sound/ymz280b.c
@@ -694,7 +694,7 @@ static DEVICE_START( ymz280b )
}
}
- state_save_register_postload(device->machine, YMZ280B_state_save_update_step, chip);
+ device->machine->state().register_postload(YMZ280B_state_save_update_step, chip);
#if MAKE_WAVS
chip->wavresample = wav_open("resamp.wav", INTERNAL_SAMPLE_RATE, 2);
diff --git a/src/emu/speaker.h b/src/emu/speaker.h
index e464aa51783..12bdcca501e 100644
--- a/src/emu/speaker.h
+++ b/src/emu/speaker.h
@@ -85,6 +85,7 @@ public:
virtual device_t *alloc_device(running_machine &machine) const;
// inline configuration helpers
+ speaker_device_config *next_speaker() const { return downcast<speaker_device_config *>(typenext()); }
static void static_set_position(device_config *device, double x, double y, double z);
protected:
@@ -109,6 +110,9 @@ class speaker_device : public device_t,
virtual ~speaker_device();
public:
+ // getters
+ speaker_device *next_speaker() const { return downcast<speaker_device *>(typenext()); }
+
// internally for use by the sound system
void mix(INT32 *leftmix, INT32 *rightmix, int &samples_this_update, bool suppress);
@@ -135,53 +139,4 @@ protected:
extern const device_type SPEAKER;
-
-//**************************************************************************
-// INLINE HELPERS
-//**************************************************************************
-
-//-------------------------------------------------
-// speaker_first - return the first speaker
-// device config in a machine_config
-//-------------------------------------------------
-
-inline const speaker_device_config *speaker_first(const machine_config &config)
-{
- return downcast<speaker_device_config *>(config.m_devicelist.first(SPEAKER));
-}
-
-
-//-------------------------------------------------
-// speaker_next - return the next speaker
-// device config in a machine_config
-//-------------------------------------------------
-
-inline const speaker_device_config *speaker_next(const speaker_device_config *previous)
-{
- return downcast<speaker_device_config *>(previous->typenext());
-}
-
-
-//-------------------------------------------------
-// speaker_first - return the first speaker
-// device in a machine
-//-------------------------------------------------
-
-inline speaker_device *speaker_first(running_machine &machine)
-{
- return downcast<speaker_device *>(machine.m_devicelist.first(SPEAKER));
-}
-
-
-//-------------------------------------------------
-// speaker_next - return the next speaker
-// device in a machine
-//-------------------------------------------------
-
-inline speaker_device *speaker_next(speaker_device *previous)
-{
- return downcast<speaker_device *>(previous->typenext());
-}
-
-
#endif /* __SOUND_H__ */
diff --git a/src/emu/state.c b/src/emu/state.c
index 8fec0571200..bcef78d61bf 100644
--- a/src/emu/state.c
+++ b/src/emu/state.c
@@ -4,8 +4,36 @@
Save state management functions.
- Copyright Nicola Salmoria and the MAME Team.
- Visit http://mamedev.org for licensing and usage restrictions.
+****************************************************************************
+
+ Copyright Aaron Giles
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name 'MAME' nor the names of its contributors may be
+ used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
****************************************************************************
@@ -28,25 +56,24 @@
#include <zlib.h>
+//**************************************************************************
+// DEBUGGING
+//**************************************************************************
-/***************************************************************************
- DEBUGGING
-***************************************************************************/
-
-#define VERBOSE 0
+#define VERBOSE 1
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
-/***************************************************************************
- CONSTANTS
-***************************************************************************/
+//**************************************************************************
+// CONSTANTS
+//**************************************************************************
-#define SAVE_VERSION 2
-#define HEADER_SIZE 32
+const int SAVE_VERSION = 2;
+const int HEADER_SIZE = 32;
-/* Available flags */
+// Available flags
enum
{
SS_MSB_FIRST = 0x02
@@ -54,394 +81,325 @@ enum
-/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
-
-typedef struct _state_entry state_entry;
-struct _state_entry
-{
- state_entry * next; /* pointer to next entry */
- running_machine * machine; /* pointer back to the owning machine */
- void * data; /* pointer to the memory to save/restore */
- astring name; /* full name */
- UINT8 typesize; /* size of the raw data type */
- UINT32 typecount; /* number of items */
- UINT32 offset; /* offset within the final structure */
-};
-
-
-typedef struct _state_callback state_callback;
-struct _state_callback
-{
- state_callback * next; /* pointer to next entry */
- running_machine * machine; /* pointer back to the owning machine */
- void * param; /* function parameter */
- union
- {
- state_presave_func presave; /* presave callback */
- state_postload_func postload; /* postload callback */
- } func; /* function pointers */
-};
-
-
-/* In mame.h: typedef struct _state_private state_private; */
-struct _state_private
-{
- UINT8 reg_allowed; /* are registrations allowed? */
- int illegal_regs; /* number of illegal registrations */
-
- state_entry * entrylist; /* list of live entries */
- state_callback * prefunclist; /* presave function list */
- state_callback * postfunclist; /* postsave function list */
-
- UINT8 * ioarray; /* array where we accumulate all the data */
- UINT32 ioarraysize; /* size of the array */
- mame_file * iofile; /* file currently in use */
-};
-
-
-
-/***************************************************************************
- GLOBAL VARIABLES
-***************************************************************************/
+//**************************************************************************
+// GLOBAL VARIABLES
+//**************************************************************************
#ifdef MESS
-static const char ss_magic_num[8] = { 'M', 'E', 'S', 'S', 'S', 'A', 'V', 'E' };
+const char state_manager::s_magic_num[8] = { 'M', 'E', 'S', 'S', 'S', 'A', 'V', 'E' };
#else
-static const char ss_magic_num[8] = { 'M', 'A', 'M', 'E', 'S', 'A', 'V', 'E' };
+const char state_manager::s_magic_num[8] = { 'M', 'A', 'M', 'E', 'S', 'A', 'V', 'E' };
#endif
-/***************************************************************************
- INLINE FUNCTIONS
-***************************************************************************/
+//**************************************************************************
+// INITIALIZATION
+//**************************************************************************
-/*-------------------------------------------------
- flip_data - reverse the endianness of a
- block of data
--------------------------------------------------*/
+//-------------------------------------------------
+// state_manager - constructor
+//-------------------------------------------------
-INLINE void flip_data(state_entry *entry)
+state_manager::state_manager(running_machine &machine)
+ : m_machine(machine),
+ m_reg_allowed(true),
+ m_illegal_regs(0),
+ m_entry_list(machine.m_respool),
+ m_presave_list(machine.m_respool),
+ m_postload_list(machine.m_respool)
{
- UINT16 *data16;
- UINT32 *data32;
- UINT64 *data64;
- int count;
-
- switch (entry->typesize)
- {
- case 2:
- data16 = (UINT16 *)entry->data;
- for (count = 0; count < entry->typecount; count++)
- data16[count] = FLIPENDIAN_INT16(data16[count]);
- break;
-
- case 4:
- data32 = (UINT32 *)entry->data;
- for (count = 0; count < entry->typecount; count++)
- data32[count] = FLIPENDIAN_INT32(data32[count]);
- break;
-
- case 8:
- data64 = (UINT64 *)entry->data;
- for (count = 0; count < entry->typecount; count++)
- data64[count] = FLIPENDIAN_INT64(data64[count]);
- break;
- }
}
+//-------------------------------------------------
+// allow_registration - allow/disallow
+// registrations to happen
+//-------------------------------------------------
-/***************************************************************************
- INITIALIZATION
-***************************************************************************/
-
-/*-------------------------------------------------
- state_init - initialize the system and reset
- all registrations
--------------------------------------------------*/
+void state_manager::allow_registration(bool allowed)
+{
+ // allow/deny registration
+ m_reg_allowed = allowed;
+ if (!allowed)
+ dump_registry();
+}
-enum test_enum_type { test_val };
-class test_class_type { public: int dummy; };
+//-------------------------------------------------
+// indexed_item - return an item with the given
+// index
+//-------------------------------------------------
-void state_init(running_machine *machine)
+const char *state_manager::indexed_item(int index, void *&base, UINT32 &valsize, UINT32 &valcount) const
{
- bool test_bool = false;
- INT8 test_INT8 = 0;
- UINT8 test_UINT8 = 0;
- INT16 test_INT16 = 0;
- UINT16 test_UINT16 = 0;
- INT32 test_INT32 = 0;
- UINT32 test_UINT32 = 0;
- INT64 test_INT64 = 0;
- UINT64 test_UINT64 = 0;
- float test_float = 0.0f;
- double test_double = 0.0;
- test_enum_type test_enum = test_val;
-#ifdef __GNUC__
- test_class_type test_class;
-#endif
-
- assert_always(IS_VALID_SAVE_TYPE(test_bool), "bool is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_INT8), "INT8 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_UINT8), "UINT8 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_INT16), "INT16 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_UINT16), "UINT16 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_INT32), "INT32 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_UINT32), "UINT32 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_INT64), "INT64 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_UINT64), "UINT64 is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_float), "float is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_double), "double is not a valid type for save");
- assert_always(IS_VALID_SAVE_TYPE(test_enum), "enums are not a valid type for save");
-#ifdef __GNUC__
- assert_always(!IS_VALID_SAVE_TYPE(test_class), "classes are a valid type for save");
-#endif
-
- machine->state_data = auto_alloc_clear(machine, state_private);
+ state_entry *entry = m_entry_list.find(index);
+ if (entry == NULL)
+ return NULL;
+
+ base = entry->m_data;
+ valsize = entry->m_typesize;
+ valcount = entry->m_typecount;
+
+ return entry->m_name;
}
-/*-------------------------------------------------
- state_save_get_reg_count - return the number
- of total registrations so far
--------------------------------------------------*/
+//-------------------------------------------------
+// register_presave - register a pre-save
+// function callback
+//-------------------------------------------------
-int state_save_get_reg_count(running_machine *machine)
+void state_manager::register_presave(prepost_func func, void *param)
{
- state_private *global = machine->state_data;
- state_entry *entry;
- int count = 0;
+ // check for invalid timing
+ if (!m_reg_allowed)
+ fatalerror("Attempt to register callback function after state registration is closed!");
- /* count entries */
- for (entry = global->entrylist; entry != NULL; entry = entry->next)
- count++;
+ // scan for duplicates and push through to the end
+ for (state_callback *cb = m_presave_list.first(); cb != NULL; cb = cb->next())
+ if (cb->m_func == func && cb->m_param == param)
+ fatalerror("Duplicate save state function (%p, %p)", param, func);
- return count;
+ // allocate a new entry
+ m_presave_list.append(*auto_alloc(&m_machine, state_callback(func, param)));
}
+//-------------------------------------------------
+// state_save_register_postload -
+// register a post-load function callback
+//-------------------------------------------------
-/***************************************************************************
- REGISTRATION HANDLING
-***************************************************************************/
-
-/*-------------------------------------------------
- state_save_allow_registration - allow/disallow
- registrations to happen
--------------------------------------------------*/
-
-void state_save_allow_registration(running_machine *machine, int allowed)
+void state_manager::register_postload(prepost_func func, void *param)
{
- /* allow/deny registration */
- machine->state_data->reg_allowed = allowed;
- if (!allowed)
- state_save_dump_registry(machine);
-}
-
+ // check for invalid timing
+ if (!m_reg_allowed)
+ fatalerror("Attempt to register callback function after state registration is closed!");
-/*-------------------------------------------------
- state_save_registration_allowed - query
- whether or not registrations are allowed
--------------------------------------------------*/
+ // scan for duplicates and push through to the end
+ for (state_callback *cb = m_postload_list.first(); cb != NULL; cb = cb->next())
+ if (cb->m_func == func && cb->m_param == param)
+ fatalerror("Duplicate save state function (%p, %p)", param, func);
-int state_save_registration_allowed(running_machine *machine)
-{
- return machine->state_data->reg_allowed;
+ // allocate a new entry
+ m_postload_list.append(*auto_alloc(&m_machine, state_callback(func, param)));
}
-/*-------------------------------------------------
- state_save_register_memory - register an
- array of data in memory
--------------------------------------------------*/
+//-------------------------------------------------
+// save_memory - register an array of data in
+// memory
+//-------------------------------------------------
-void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line)
+void state_manager::save_memory(const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount)
{
- state_private *global = machine->state_data;
- state_entry **entryptr, *next;
- astring totalname;
-
assert(valsize == 1 || valsize == 2 || valsize == 4 || valsize == 8);
- /* check for invalid timing */
- if (!global->reg_allowed)
+ // check for invalid timing
+ if (!m_reg_allowed)
{
- logerror("Attempt to register save state entry after state registration is closed!\nFile: %s, line %d, module %s tag %s name %s\n", file, line, module, tag, name);
- if (machine->gamedrv->flags & GAME_SUPPORTS_SAVE)
- fatalerror("Attempt to register save state entry after state registration is closed!\nFile: %s, line %d, module %s tag %s name %s\n", file, line, module, tag, name);
- global->illegal_regs++;
+ logerror("Attempt to register save state entry after state registration is closed!\nModule %s tag %s name %s\n", module, tag, name);
+ if (m_machine.gamedrv->flags & GAME_SUPPORTS_SAVE)
+ fatalerror("Attempt to register save state entry after state registration is closed!\nModule %s tag %s name %s\n", module, tag, name);
+ m_illegal_regs++;
return;
}
- /* create the full name */
+ // create the full name
+ astring totalname;
if (tag != NULL)
totalname.printf("%s/%s/%X/%s", module, tag, index, name);
else
totalname.printf("%s/%X/%s", module, index, name);
- /* look for duplicates and an entry to insert in front of */
- for (entryptr = &global->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next)
+ // look for duplicates and an entry to insert in front of
+ state_entry *insert_after = NULL;
+ for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
{
- /* stop if the next guy's string is greater than ours */
- int cmpval = (*entryptr)->name.cmp(totalname);
- if (cmpval > 0)
+ // stop when we find an entry whose name is after ours
+ if (entry->m_name > totalname)
break;
+ insert_after = entry;
- /* error if we are equal */
- if (cmpval == 0)
+ // error if we are equal
+ if (entry->m_name == totalname)
fatalerror("Duplicate save state registration entry (%s)", totalname.cstr());
}
- /* didn't find one; allocate a new one */
- next = *entryptr;
- *entryptr = auto_alloc_clear(machine, state_entry);
-
- /* fill in the rest */
- (*entryptr)->next = next;
- (*entryptr)->machine = machine;
- (*entryptr)->data = val;
- (*entryptr)->name = totalname;
- (*entryptr)->typesize = valsize;
- (*entryptr)->typecount = valcount;
+ // insert us into the list
+ m_entry_list.insert_after(*auto_alloc(&m_machine, state_entry(val, totalname, valsize, valcount)), insert_after);
}
-/*-------------------------------------------------
- state_save_register_bitmap - register a
- bitmap to be saved
--------------------------------------------------*/
+//-------------------------------------------------
+// check_file - check if a file is a valid save
+// state
+//-------------------------------------------------
-void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line)
+state_save_error state_manager::check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...))
{
- state_save_register_memory(machine, module, tag, index, name, val->base, val->bpp / 8, val->rowpixels * val->height, file, line);
-}
+ // if we want to validate the signature, compute it
+ UINT32 sig = 0;
+ if (machine != NULL)
+ sig = machine->state().signature();
+ // seek to the beginning and read the header
+ mame_fcompress(file, FCOMPRESS_NONE);
+ mame_fseek(file, 0, SEEK_SET);
+ UINT8 header[HEADER_SIZE];
+ if (mame_fread(file, header, sizeof(header)) != sizeof(header))
+ {
+ if (errormsg != NULL)
+ (*errormsg)("Could not read " APPNAME " save file header");
+ return STATERR_READ_ERROR;
+ }
+ // let the generic header check work out the rest
+ return validate_header(header, gamename, sig, errormsg, "");
+}
-/***************************************************************************
- CALLBACK FUNCTION REGISTRATION
-***************************************************************************/
-/*-------------------------------------------------
- state_save_register_presave -
- register a pre-save function callback
--------------------------------------------------*/
+//-------------------------------------------------
+// read_file - read the data from a file
+//-------------------------------------------------
-void state_save_register_presave(running_machine *machine, state_presave_func func, void *param)
+state_save_error state_manager::read_file(mame_file *file)
{
- state_private *global = machine->state_data;
- state_callback **cbptr;
+ // if we have illegal registrations, return an error
+ if (m_illegal_regs > 0)
+ return STATERR_ILLEGAL_REGISTRATIONS;
- /* check for invalid timing */
- if (!global->reg_allowed)
- fatalerror("Attempt to register callback function after state registration is closed!");
+ // read the header and turn on compression for the rest of the file
+ mame_fcompress(file, FCOMPRESS_NONE);
+ mame_fseek(file, 0, SEEK_SET);
+ UINT8 header[HEADER_SIZE];
+ if (mame_fread(file, header, sizeof(header)) != sizeof(header))
+ return STATERR_READ_ERROR;
+ mame_fcompress(file, FCOMPRESS_MEDIUM);
- /* scan for duplicates and push through to the end */
- for (cbptr = &global->prefunclist; *cbptr != NULL; cbptr = &(*cbptr)->next)
- if ((*cbptr)->func.presave == func && (*cbptr)->param == param)
- fatalerror("Duplicate save state function (%p, %p)", param, func);
+ // verify the header and report an error if it doesn't match
+ UINT32 sig = signature();
+ if (validate_header(header, m_machine.gamedrv->name, sig, popmessage, "Error: ") != STATERR_NONE)
+ return STATERR_INVALID_HEADER;
- /* allocate a new entry */
- *cbptr = auto_alloc(machine, state_callback);
+ // determine whether or not to flip the data when done
+ bool flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0);
- /* fill it in */
- (*cbptr)->next = NULL;
- (*cbptr)->machine = machine;
- (*cbptr)->func.presave = func;
- (*cbptr)->param = param;
+ // read all the data, flipping if necessary
+ for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
+ {
+ UINT32 totalsize = entry->m_typesize * entry->m_typecount;
+ if (mame_fread(file, entry->m_data, totalsize) != totalsize)
+ return STATERR_READ_ERROR;
+
+ // handle flipping
+ if (flip)
+ entry->flip_data();
+ }
+
+ // call the post-load functions
+ for (state_callback *func = m_postload_list.first(); func != NULL; func = func->next())
+ (*func->m_func)(&m_machine, func->m_param);
+
+ return STATERR_NONE;
}
-/*-------------------------------------------------
- state_save_register_postload -
- register a post-load function callback
--------------------------------------------------*/
+//-------------------------------------------------
+// write_file - writes the data to a file
+//-------------------------------------------------
-void state_save_register_postload(running_machine *machine, state_postload_func func, void *param)
+state_save_error state_manager::write_file(mame_file *file)
{
- state_private *global = machine->state_data;
- state_callback **cbptr;
+ // if we have illegal registrations, return an error
+ if (m_illegal_regs > 0)
+ return STATERR_ILLEGAL_REGISTRATIONS;
- /* check for invalid timing */
- if (!global->reg_allowed)
- fatalerror("Attempt to register callback function after state registration is closed!");
+ // generate the header
+ UINT8 header[HEADER_SIZE];
+ memcpy(&header[0], s_magic_num, 8);
+ header[8] = SAVE_VERSION;
+ header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST);
+ strncpy((char *)&header[0x0a], m_machine.gamedrv->name, 0x1c - 0x0a);
+ UINT32 sig = signature();
+ *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(sig);
- /* scan for duplicates and push through to the end */
- for (cbptr = &global->postfunclist; *cbptr != NULL; cbptr = &(*cbptr)->next)
- if ((*cbptr)->func.postload == func && (*cbptr)->param == param)
- fatalerror("Duplicate save state function (%p, %p)", param, func);
+ // write the header and turn on compression for the rest of the file
+ mame_fcompress(file, FCOMPRESS_NONE);
+ mame_fseek(file, 0, SEEK_SET);
+ if (mame_fwrite(file, header, sizeof(header)) != sizeof(header))
+ return STATERR_WRITE_ERROR;
+ mame_fcompress(file, FCOMPRESS_MEDIUM);
- /* allocate a new entry */
- *cbptr = auto_alloc(machine, state_callback);
+ // call the pre-save functions
+ for (state_callback *func = m_presave_list.first(); func != NULL; func = func->next())
+ (*func->m_func)(&m_machine, func->m_param);
- /* fill it in */
- (*cbptr)->next = NULL;
- (*cbptr)->machine = machine;
- (*cbptr)->func.postload = func;
- (*cbptr)->param = param;
+ // then write all the data
+ for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
+ {
+ UINT32 totalsize = entry->m_typesize * entry->m_typecount;
+ if (mame_fwrite(file, entry->m_data, totalsize) != totalsize)
+ return STATERR_WRITE_ERROR;
+ }
+ return STATERR_NONE;
}
+//-------------------------------------------------
+// signature - compute the signature, which
+// is a CRC over the structure of the data
+//-------------------------------------------------
-/***************************************************************************
- PROCESSING HELPERS
-***************************************************************************/
-
-/*-------------------------------------------------
- get_signature - compute the signature, which
- is a CRC over the structure of the data
--------------------------------------------------*/
-
-static UINT32 get_signature(running_machine *machine)
+UINT32 state_manager::signature() const
{
- state_private *global = machine->state_data;
- state_entry *entry;
+ // iterate over entries
UINT32 crc = 0;
-
- /* iterate over entries */
- for (entry = global->entrylist; entry != NULL; entry = entry->next)
+ for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
{
- UINT32 temp[2];
+ // add the entry name to the CRC
+ crc = crc32(crc, (UINT8 *)entry->m_name.cstr(), entry->m_name.len());
- /* add the entry name to the CRC */
- crc = crc32(crc, (UINT8 *)entry->name.cstr(), entry->name.len());
-
- /* add the type and size to the CRC */
- temp[0] = LITTLE_ENDIANIZE_INT32(entry->typecount);
- temp[1] = LITTLE_ENDIANIZE_INT32(entry->typesize);
+ // add the type and size to the CRC
+ UINT32 temp[2];
+ temp[0] = LITTLE_ENDIANIZE_INT32(entry->m_typecount);
+ temp[1] = LITTLE_ENDIANIZE_INT32(entry->m_typesize);
crc = crc32(crc, (UINT8 *)&temp[0], sizeof(temp));
}
-
return crc;
}
+//-------------------------------------------------
+// dump_registry - dump the registry to the
+// logfile
+//-------------------------------------------------
+
+void state_manager::dump_registry() const
+{
+ for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
+ LOG(("%s: %d x %d\n", entry->m_name.cstr(), entry->m_typesize, entry->m_typecount));
+}
-/***************************************************************************
- SAVE STATE FILE PROCESSING
-***************************************************************************/
-/*-------------------------------------------------
- validate_header - validate the data in the
- header
--------------------------------------------------*/
+//-------------------------------------------------
+// validate_header - validate the data in the
+// header
+//-------------------------------------------------
-static state_save_error validate_header(const UINT8 *header, const char *gamename, UINT32 signature,
+state_save_error state_manager::validate_header(const UINT8 *header, const char *gamename, UINT32 signature,
void (CLIB_DECL *errormsg)(const char *fmt, ...), const char *error_prefix)
{
- /* check magic number */
- if (memcmp(header, ss_magic_num, 8))
+ // check magic number
+ if (memcmp(header, s_magic_num, 8))
{
if (errormsg != NULL)
(*errormsg)("%sThis is not a " APPNAME " save file", error_prefix);
return STATERR_INVALID_HEADER;
}
- /* check save state version */
+ // check save state version
if (header[8] != SAVE_VERSION)
{
if (errormsg != NULL)
@@ -449,7 +407,7 @@ static state_save_error validate_header(const UINT8 *header, const char *gamenam
return STATERR_INVALID_HEADER;
}
- /* check gamename, if we were asked to */
+ // check gamename, if we were asked to
if (gamename != NULL && strncmp(gamename, (const char *)&header[0x0a], 0x1c - 0x0a))
{
if (errormsg != NULL)
@@ -457,7 +415,7 @@ static state_save_error validate_header(const UINT8 *header, const char *gamenam
return STATERR_INVALID_HEADER;
}
- /* check signature, if we were asked to */
+ // check signature, if we were asked to
if (signature != 0)
{
UINT32 rawsig = *(UINT32 *)&header[0x1c];
@@ -472,175 +430,63 @@ static state_save_error validate_header(const UINT8 *header, const char *gamenam
}
-/*-------------------------------------------------
- state_save_check_file - check if a file is
- a valid save state
--------------------------------------------------*/
+//-------------------------------------------------
+// state_callback - constructor
+//-------------------------------------------------
-state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...))
+state_manager::state_callback::state_callback(prepost_func callback, void *param)
+ : m_next(NULL),
+ m_param(param),
+ m_func(callback)
{
- UINT8 header[HEADER_SIZE];
- UINT32 signature = 0;
-
- /* if we want to validate the signature, compute it */
- if (machine != NULL)
- signature = get_signature(machine);
-
- /* seek to the beginning and read the header */
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
- if (mame_fread(file, header, sizeof(header)) != sizeof(header))
- {
- if (errormsg != NULL)
- (*errormsg)("Could not read " APPNAME " save file header");
- return STATERR_READ_ERROR;
- }
-
- /* let the generic header check work out the rest */
- return validate_header(header, gamename, signature, errormsg, "");
}
-/*-------------------------------------------------
- state_save_write_file - writes the data to
- a file
--------------------------------------------------*/
+//-------------------------------------------------
+// state_entry - constructor
+//-------------------------------------------------
-state_save_error state_save_write_file(running_machine *machine, mame_file *file)
+state_manager::state_entry::state_entry(void *data, const char *name, UINT8 size, UINT32 count)
+ : m_next(NULL),
+ m_data(data),
+ m_name(name),
+ m_typesize(size),
+ m_typecount(count),
+ m_offset(0)
{
- state_private *global = machine->state_data;
- UINT32 signature = get_signature(machine);
- UINT8 header[HEADER_SIZE];
- state_callback *func;
- state_entry *entry;
-
- /* if we have illegal registrations, return an error */
- if (global->illegal_regs > 0)
- return STATERR_ILLEGAL_REGISTRATIONS;
-
- /* generate the header */
- memcpy(&header[0], ss_magic_num, 8);
- header[8] = SAVE_VERSION;
- header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST);
- strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a);
- *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature);
-
- /* write the header and turn on compression for the rest of the file */
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
- if (mame_fwrite(file, header, sizeof(header)) != sizeof(header))
- return STATERR_WRITE_ERROR;
- mame_fcompress(file, FCOMPRESS_MEDIUM);
-
- /* call the pre-save functions */
- for (func = global->prefunclist; func != NULL; func = func->next)
- (*func->func.presave)(machine, func->param);
-
- /* then write all the data */
- for (entry = global->entrylist; entry != NULL; entry = entry->next)
- {
- UINT32 totalsize = entry->typesize * entry->typecount;
- if (mame_fwrite(file, entry->data, totalsize) != totalsize)
- return STATERR_WRITE_ERROR;
- }
- return STATERR_NONE;
}
-/*-------------------------------------------------
- state_save_read_file - read the data from a
- file
--------------------------------------------------*/
+//-------------------------------------------------
+// flip_data - reverse the endianness of a
+// block of data
+//-------------------------------------------------
-state_save_error state_save_read_file(running_machine *machine, mame_file *file)
+void state_manager::state_entry::flip_data()
{
- state_private *global = machine->state_data;
- UINT32 signature = get_signature(machine);
- UINT8 header[HEADER_SIZE];
- state_callback *func;
- state_entry *entry;
- int flip;
-
- /* if we have illegal registrations, return an error */
- if (global->illegal_regs > 0)
- return STATERR_ILLEGAL_REGISTRATIONS;
-
- /* read the header and turn on compression for the rest of the file */
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
- if (mame_fread(file, header, sizeof(header)) != sizeof(header))
- return STATERR_READ_ERROR;
- mame_fcompress(file, FCOMPRESS_MEDIUM);
-
- /* verify the header and report an error if it doesn't match */
- if (validate_header(header, machine->gamedrv->name, signature, popmessage, "Error: ") != STATERR_NONE)
- return STATERR_INVALID_HEADER;
-
- /* determine whether or not to flip the data when done */
- flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0);
+ UINT16 *data16;
+ UINT32 *data32;
+ UINT64 *data64;
+ int count;
- /* read all the data, flipping if necessary */
- for (entry = global->entrylist; entry != NULL; entry = entry->next)
+ switch (m_typesize)
{
- UINT32 totalsize = entry->typesize * entry->typecount;
- if (mame_fread(file, entry->data, totalsize) != totalsize)
- return STATERR_READ_ERROR;
-
- /* handle flipping */
- if (flip)
- flip_data(entry);
- }
-
- /* call the post-load functions */
- for (func = global->postfunclist; func != NULL; func = func->next)
- (*func->func.postload)(machine, func->param);
-
- return STATERR_NONE;
-}
-
-
-
-/***************************************************************************
- DEBUGGING
-***************************************************************************/
-
-/*-------------------------------------------------
- state_save_get_indexed_item - return an item
- with the given index
--------------------------------------------------*/
-
-const char *state_save_get_indexed_item(running_machine *machine, int index, void **base, UINT32 *valsize, UINT32 *valcount)
-{
- state_private *global = machine->state_data;
- state_entry *ss;
-
- for (ss = global->entrylist; ss != NULL; ss = ss->next)
- if (index-- == 0)
- {
- if (base != NULL)
- *base = ss->data;
- if (valsize != NULL)
- *valsize = ss->typesize;
- if (valcount != NULL)
- *valcount = ss->typecount;
- return ss->name;
- }
-
- return NULL;
-}
-
-
-/*-------------------------------------------------
- state_save_dump_registry - dump the registry
- to the logfile
--------------------------------------------------*/
+ case 2:
+ data16 = (UINT16 *)m_data;
+ for (count = 0; count < m_typecount; count++)
+ data16[count] = FLIPENDIAN_INT16(data16[count]);
+ break;
-void state_save_dump_registry(running_machine *machine)
-{
- state_private *global = machine->state_data;
- state_entry *entry;
+ case 4:
+ data32 = (UINT32 *)m_data;
+ for (count = 0; count < m_typecount; count++)
+ data32[count] = FLIPENDIAN_INT32(data32[count]);
+ break;
- for (entry = global->entrylist; entry; entry=entry->next)
- LOG(("%s: %d x %d\n", entry->name.cstr(), entry->typesize, entry->typecount));
+ case 8:
+ data64 = (UINT64 *)m_data;
+ for (count = 0; count < m_typecount; count++)
+ data64[count] = FLIPENDIAN_INT64(data64[count]);
+ break;
+ }
}
-
diff --git a/src/emu/state.h b/src/emu/state.h
index 6ed3c887855..0af6e94c77f 100644
--- a/src/emu/state.h
+++ b/src/emu/state.h
@@ -4,8 +4,36 @@
Save state management functions.
- Copyright Nicola Salmoria and the MAME Team.
- Visit http://mamedev.org for licensing and usage restrictions.
+****************************************************************************
+
+ Copyright Aaron Giles
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name 'MAME' nor the names of its contributors may be
+ used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
@@ -18,25 +46,13 @@
#ifndef __STATE_H__
#define __STATE_H__
-#ifdef __GNUC__
-#include <tr1/type_traits>
-#endif
-
-
-/***************************************************************************
- TYPE DEFINTIONS
-***************************************************************************/
-typedef void (*state_presave_func)(running_machine *machine, void *param);
-typedef void (*state_postload_func)(running_machine *machine, void *param);
+//**************************************************************************
+// CONSTANTS
+//**************************************************************************
-
-/***************************************************************************
- CONSTANTS
-***************************************************************************/
-
-enum _state_save_error
+enum state_save_error
{
STATERR_NONE,
STATERR_ILLEGAL_REGISTRATIONS,
@@ -44,13 +60,12 @@ enum _state_save_error
STATERR_READ_ERROR,
STATERR_WRITE_ERROR
};
-typedef enum _state_save_error state_save_error;
-/***************************************************************************
- MACROS
-***************************************************************************/
+//**************************************************************************
+// MACROS
+//**************************************************************************
#define STATE_PRESAVE(name) void name(running_machine *machine, void *param)
#define STATE_POSTLOAD(name) void name(running_machine *machine, void *param)
@@ -71,139 +86,235 @@ void state_postload_stub(running_machine *machine, void *param)
}
-#ifdef __GNUC__
-#define IS_VALID_SAVE_TYPE(_var) \
- (std::tr1::is_arithmetic<typeof(_var)>::value || std::tr1::is_enum<typeof(_var)>::value || \
- std::tr1::is_same<typeof(_var), PAIR>::value || std::tr1::is_same<typeof(_var), PAIR64>::value)
-#else
-#define IS_VALID_SAVE_TYPE(_var) \
- (sizeof(_var) == 1 || sizeof(_var) == 2 || sizeof(_var) == 4 || sizeof(_var) == 8)
-#endif
-
-
-/* generic registration; all further registrations are based on this */
-#define state_save_register_generic(_mach, _mod, _tag, _index, _name, _val, _valsize, _count) \
-do { \
- assert_always(IS_VALID_SAVE_TYPE(_valsize), "Invalid data type supplied for state saving."); \
- state_save_register_memory(_mach, _mod, _tag, _index, _name, _val, sizeof(_valsize), _count, __FILE__, __LINE__); \
-} while (0)
-
-
-/* register items with explicit tags */
+// register items with explicit tags
#define state_save_register_item(_mach, _mod, _tag, _index, _val) \
- state_save_register_generic(_mach, _mod, _tag, _index, #_val, &_val, _val, 1)
+ (_mach)->state().save_item(_mod, _tag, _index, _val, #_val)
#define state_save_register_item_pointer(_mach, _mod, _tag, _index, _val, _count) \
- state_save_register_generic(_mach, _mod, _tag, _index, #_val, &_val[0], _val[0], _count)
+ (_mach)->state().save_pointer(_mod, _tag, _index, _val, #_val, _count)
#define state_save_register_item_array(_mach, _mod, _tag, _index, _val) \
- state_save_register_item_pointer(_mach, _mod, _tag, _index, _val, sizeof(_val)/sizeof(_val[0]))
+ (_mach)->state().save_item(_mod, _tag, _index, _val, #_val)
#define state_save_register_item_2d_array(_mach, _mod, _tag, _index, _val) \
- state_save_register_item_pointer(_mach, _mod, _tag, _index, _val[0], sizeof(_val)/sizeof(_val[0][0]))
+ (_mach)->state().save_item(_mod, _tag, _index, _val, #_val)
-#define state_save_register_item_bitmap(_mach, _mod, _tag, _index, _val) \
- state_save_register_bitmap(_mach, _mod, _tag, _index, #_val, _val, __FILE__, __LINE__)
+#define state_save_register_item_bitmap(_mach, _mod, _tag, _index, _val) \
+ (_mach)->state().save_item(_mod, _tag, _index, *(_val), #_val)
-/* register device items */
+// register device items
#define state_save_register_device_item(_dev, _index, _val) \
- state_save_register_generic((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, &_val, _val, 1)
+ (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val)
#define state_save_register_device_item_pointer(_dev, _index, _val, _count) \
- state_save_register_generic((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, &_val[0], _val[0], _count)
+ (_dev)->machine->state().save_pointer((_dev)->name(), (_dev)->tag(), _index, _val, #_val, _count)
#define state_save_register_device_item_array(_dev, _index, _val) \
- state_save_register_item_pointer((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, _val, sizeof(_val)/sizeof(_val[0]))
+ (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val)
#define state_save_register_device_item_2d_array(_dev, _index, _val) \
- state_save_register_item_pointer((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, _val[0], sizeof(_val)/sizeof(_val[0][0]))
+ (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, _val, #_val)
-#define state_save_register_device_item_bitmap(_dev, _index, _val) \
- state_save_register_bitmap((_dev)->machine, (_dev)->name(), (_dev)->tag(), _index, #_val, _val, __FILE__, __LINE__)
+#define state_save_register_device_item_bitmap(_dev, _index, _val) \
+ (_dev)->machine->state().save_item((_dev)->name(), (_dev)->tag(), _index, *(_val), #_val)
-/* register global items */
+// register global items
#define state_save_register_global(_mach, _val) \
- state_save_register_item(_mach, "globals", NULL, 0, _val)
+ (_mach)->state().save_item(_val, #_val)
#define state_save_register_global_pointer(_mach, _val, _count) \
- state_save_register_item_pointer(_mach, "globals", NULL, 0, _val, _count)
+ (_mach)->state().save_pointer(_val, #_val, _count)
#define state_save_register_global_array(_mach, _val) \
- state_save_register_item_array(_mach, "globals", NULL, 0, _val)
+ (_mach)->state().save_item(_val, #_val)
#define state_save_register_global_2d_array(_mach, _val) \
- state_save_register_item_2d_array(_mach, "globals", NULL, 0, _val)
+ (_mach)->state().save_item(_val, #_val)
#define state_save_register_global_bitmap(_mach, _val) \
- state_save_register_bitmap(_mach, "globals", NULL, 0, #_val, _val, __FILE__, __LINE__)
-
-
-
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
-
-
-/* ----- core system operations ----- */
-
-/* initialize the system and reset all registrations */
-void state_init(running_machine *machine);
-
-/* return the number of total registrations so far */
-int state_save_get_reg_count(running_machine *machine);
-
-
-
-/* ----- registration handling ----- */
-
-/* allow/disallow registrations to happen (called by the core) */
-void state_save_allow_registration(running_machine *machine, int allowed);
-
-/* query whether or not registrations are allowed */
-int state_save_registration_allowed(running_machine *machine);
+ (_mach)->state().save_item(*(_val), #_val)
-/* register an array of data in memory */
-void state_save_register_memory(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount, const char *file, int line);
-/* register a bitmap to be saved */
-void state_save_register_bitmap(running_machine *machine, const char *module, const char *tag, UINT32 index, const char *name, bitmap_t *val, const char *file, int line);
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
-
-/* ----- callback function registraton ----- */
-
-/* register a pre-save function callback */
-void state_save_register_presave(running_machine *machine, state_presave_func func, void *param);
-
-/* register a post-load function callback */
-void state_save_register_postload(running_machine *machine, state_postload_func func, void *param);
-
+class state_manager
+{
+ // type_checker is a set of templates to identify valid save types
+ template<typename T> struct type_checker { static const bool is_atom = false; static const bool is_pointer = false; };
+ template<typename T> struct type_checker<T*> { static const bool is_atom = false; static const bool is_pointer = true; };
+
+public:
+ typedef void (*prepost_func)(running_machine *machine, void *param);
+
+ // construction/destruction
+ state_manager(running_machine &machine);
+
+ // getters
+ int registration_count() const { return m_entry_list.count(); }
+ bool registration_allowed() const { return m_reg_allowed; }
+
+ // registration control
+ void allow_registration(bool allowed = true);
+ const char *indexed_item(int index, void *&base, UINT32 &valsize, UINT32 &valcount) const;
+
+ // function registration
+ void register_presave(prepost_func func, void *param);
+ void register_postload(prepost_func func, void *param);
+
+ // generic memory registration
+ void save_memory(const char *module, const char *tag, UINT32 index, const char *name, void *val, UINT32 valsize, UINT32 valcount = 1);
+
+ // templatized wrapper for general objects
+ template<typename T>
+ void save_item(const char *module, const char *tag, int index, T &value, const char *valname)
+ {
+ if (type_checker<T>::is_pointer) throw emu_fatalerror("Called save_item on a pointer with no count!");
+ if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!");
+ save_memory(module, tag, index, valname, &value, sizeof(value));
+ }
+
+ // templatized wrapper for 1-dimensional arrays
+ template<typename T, std::size_t N>
+ void save_item(const char *module, const char *tag, int index, T (&value)[N], const char *valname)
+ {
+ if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!");
+ save_memory(module, tag, index, valname, &value[0], sizeof(value[0]), N);
+ }
+
+ // templatized wrapper for 2-dimensional arrays
+ template<typename T, std::size_t M, std::size_t N>
+ void save_item(const char *module, const char *tag, int index, T (&value)[M][N], const char *valname)
+ {
+ if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!");
+ save_memory(module, tag, index, valname, &value[0][0], sizeof(value[0][0]), M * N);
+ }
+
+ // templatized wrapper for pointers
+ template<typename T>
+ void save_pointer(const char *module, const char *tag, int index, T *value, const char *valname, UINT32 count)
+ {
+ if (!type_checker<T>::is_atom) throw emu_fatalerror("Called save_item on a non-fundamental type!");
+ save_memory(module, tag, index, valname, value, sizeof(*value), count);
+ }
+
+ // global memory registration
+ template<typename T>
+ void save_item(T &value, const char *valname, int index = 0) { save_item("global", NULL, index, value, valname); }
+ template<typename T>
+ void save_pointer(T *value, const char *valname, UINT32 count, int index = 0) { save_pointer("global", NULL, index, value, valname, count); }
+
+ // file processing
+ static state_save_error check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...));
+ state_save_error write_file(mame_file *file);
+ state_save_error read_file(mame_file *file);
+
+private:
+ // internal helpers
+ UINT32 signature() const;
+ void dump_registry() const;
+ static state_save_error validate_header(const UINT8 *header, const char *gamename, UINT32 signature, void (CLIB_DECL *errormsg)(const char *fmt, ...), const char *error_prefix);
+
+ // state callback item
+ class state_callback
+ {
+ public:
+ // construction/destruction
+ state_callback(prepost_func callback, void *param);
+
+ // getters
+ state_callback *next() const { return m_next; }
+
+ // state
+ state_callback * m_next; // pointer to next entry
+ void * m_param; // function parameter
+ prepost_func m_func; // pointer to the function
+ };
+
+ class state_entry
+ {
+ public:
+ // construction/destruction
+ state_entry(void *data, const char *name, UINT8 size, UINT32 count);
+
+ // getters
+ state_entry *next() const { return m_next; }
+
+ // helpers
+ void flip_data();
+
+ // state
+ state_entry * m_next; // pointer to next entry
+ void * m_data; // pointer to the memory to save/restore
+ astring m_name; // full name
+ UINT8 m_typesize; // size of the raw data type
+ UINT32 m_typecount; // number of items
+ UINT32 m_offset; // offset within the final structure
+ };
+
+ // internal state
+ running_machine & m_machine; // reference to our machine
+ bool m_reg_allowed; // are registrations allowed?
+ int m_illegal_regs; // number of illegal registrations
+
+ simple_list<state_entry> m_entry_list; // list of reigstered entries
+ simple_list<state_callback> m_presave_list; // list of pre-save functions
+ simple_list<state_callback> m_postload_list; // list of post-load functions
+
+ static const char s_magic_num[8]; // magic number for header
+};
-/* ----- save state file processing ----- */
+// template specializations to enumerate the fundamental atomic types you are allowed to save
+template<> struct state_manager::type_checker<bool> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<INT8> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<UINT8> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<INT16> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<UINT16> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<INT32> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<UINT32> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<INT64> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<UINT64> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<PAIR> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<PAIR64> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<float> { static const bool is_atom = true; static const bool is_pointer = false; };
+template<> struct state_manager::type_checker<double> { static const bool is_atom = true; static const bool is_pointer = false; };
-/* check if a file is a valid save state */
-state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...));
-/* write out the save state file */
-state_save_error state_save_write_file(running_machine *machine, mame_file *file);
-/* read in a save state file */
-state_save_error state_save_read_file(running_machine *machine, mame_file *file);
+//**************************************************************************
+// INLINE FUNCTIONS
+//**************************************************************************
+//-------------------------------------------------
+// save_item - specialized save_item for bitmaps
+//-------------------------------------------------
+template<>
+inline void state_manager::save_item(const char *module, const char *tag, int index, bitmap_t &value, const char *name)
+{
+ save_memory(module, tag, index, name, value.base, value.bpp / 8, value.rowpixels * value.height);
+}
-/* ----- debugging ----- */
-/* return an item with the given index */
-const char *state_save_get_indexed_item(running_machine *machine, int index, void **base, UINT32 *valsize, UINT32 *valcount);
+//-------------------------------------------------
+// save_item - specialized save_item for attotimes
+//-------------------------------------------------
-/* dump the registry to the logfile */
-void state_save_dump_registry(running_machine *machine);
+template<>
+inline void state_manager::save_item(const char *module, const char *tag, int index, attotime &value, const char *name)
+{
+ astring tempstr(name, ".attoseconds");
+ save_memory(module, tag, index, tempstr, &value.attoseconds, sizeof(value.attoseconds));
+ tempstr.cpy(name).cat(".seconds");
+ save_memory(module, tag, index, tempstr, &value.seconds, sizeof(value.seconds));
+}
#endif /* __STATE_H__ */
diff --git a/src/emu/tilemap.c b/src/emu/tilemap.c
index 2db2f7aebbf..592d9cbab8e 100644
--- a/src/emu/tilemap.c
+++ b/src/emu/tilemap.c
@@ -411,7 +411,7 @@ static tilemap_t *tilemap_create_common(running_machine *machine, void *get_info
machine->tilemap_data->instance++;
/* reset everything after a load */
- state_save_register_postload(machine, tilemap_postload, tmap);
+ machine->state().register_postload(tilemap_postload, tmap);
return tmap;
}
diff --git a/src/emu/timer.c b/src/emu/timer.c
index 1d0e3af8525..698f01345fc 100644
--- a/src/emu/timer.c
+++ b/src/emu/timer.c
@@ -286,7 +286,7 @@ void timer_device::device_start()
m_timer = timer_alloc();
// register for save states
- state_save_register_device_item(this, 0, m_first_time);
+ save_item(NAME(m_first_time));
}
diff --git a/src/emu/video.c b/src/emu/video.c
index a5e16bc2540..4405c963b77 100644
--- a/src/emu/video.c
+++ b/src/emu/video.c
@@ -136,7 +136,7 @@ video_manager::video_manager(running_machine &machine)
{
// request a callback upon exiting
machine.add_notifier(MACHINE_NOTIFY_EXIT, exit_static);
- state_save_register_postload(&machine, state_postload_stub<video_manager, &video_manager::postload>, this);
+ machine.state().register_postload(state_postload_stub<video_manager, &video_manager::postload>, this);
// extract initial execution state from global configuration settings
update_refresh_speed();
diff --git a/src/emu/video/mc6845.c b/src/emu/video/mc6845.c
index af178545019..c577f7a30f4 100644
--- a/src/emu/video/mc6845.c
+++ b/src/emu/video/mc6845.c
@@ -909,7 +909,7 @@ static void common_start(device_t *device, int device_type)
mc6845->vert_char_total = 0x7f;
/* register for state saving */
- state_save_register_postload(device->machine, mc6845_state_save_postload, mc6845);
+ device->machine->state().register_postload(mc6845_state_save_postload, mc6845);
state_save_register_device_item(device, 0, mc6845->clock);
state_save_register_device_item(device, 0, mc6845->hpixels_per_column);
diff --git a/src/emu/video/pc_video.c b/src/emu/video/pc_video.c
index 97ce140ed7a..9891af9b8d6 100644
--- a/src/emu/video/pc_video.c
+++ b/src/emu/video/pc_video.c
@@ -53,7 +53,7 @@ void pc_video_start(running_machine *machine,
video_start_generic_bitmapped(machine);
}
- state_save_register_postload(machine, pc_video_postload, NULL);
+ machine->state().register_postload(pc_video_postload, NULL);
}
diff --git a/src/emu/video/poly.c b/src/emu/video/poly.c
index c5a63a35f33..02c1c16f8bf 100644
--- a/src/emu/video/poly.c
+++ b/src/emu/video/poly.c
@@ -347,7 +347,7 @@ poly_manager *poly_alloc(running_machine *machine, int max_polys, size_t extra_d
poly->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ);
/* request a pre-save callback for synchronization */
- state_save_register_presave(machine, poly_state_presave, poly);
+ machine->state().register_presave(poly_state_presave, poly);
return poly;
}
diff --git a/src/emu/video/tms9927.c b/src/emu/video/tms9927.c
index 86aae4e193c..21997405172 100644
--- a/src/emu/video/tms9927.c
+++ b/src/emu/video/tms9927.c
@@ -283,7 +283,7 @@ static DEVICE_START( tms9927 )
}
/* register for state saving */
- state_save_register_postload(device->machine, tms9927_state_save_postload, tms);
+ device->machine->state().register_postload(tms9927_state_save_postload, tms);
state_save_register_device_item(device, 0, tms->clock);
state_save_register_device_item_array(device, 0, tms->reg);
diff --git a/src/emu/video/voodoo.c b/src/emu/video/voodoo.c
index a6e3cda939f..1d6ed0c32f9 100644
--- a/src/emu/video/voodoo.c
+++ b/src/emu/video/voodoo.c
@@ -656,7 +656,7 @@ static void init_save_state(device_t *device)
voodoo_state *v = get_safe_token(device);
int index, subindex;
- state_save_register_postload(device->machine, voodoo_postload, v);
+ device->machine->state().register_postload(voodoo_postload, v);
/* register states: core */
state_save_register_device_item(device, 0, v->extra_cycles);
@@ -669,8 +669,7 @@ static void init_save_state(device_t *device)
state_save_register_device_item(device, 0, v->pci.init_enable);
state_save_register_device_item(device, 0, v->pci.stall_state);
state_save_register_device_item(device, 0, v->pci.op_pending);
- state_save_register_device_item(device, 0, v->pci.op_end_time.seconds);
- state_save_register_device_item(device, 0, v->pci.op_end_time.attoseconds);
+ state_save_register_device_item(device, 0, v->pci.op_end_time);
state_save_register_device_item_array(device, 0, v->pci.fifo_mem);
/* register states: dac */
diff --git a/src/mame/audio/8080bw.c b/src/mame/audio/8080bw.c
index b5ffe8e07a3..0735627ca8b 100644
--- a/src/mame/audio/8080bw.c
+++ b/src/mame/audio/8080bw.c
@@ -924,7 +924,7 @@ MACHINE_START( schaser_sh )
state_save_register_global(machine, state->schaser_effect_555_is_low);
state_save_register_global(machine, state->schaser_effect_555_time_remain_savable);
state_save_register_global(machine, state->port_2_last_extra);
- state_save_register_postload(machine, schaser_reinit_555_time_remain, NULL);
+ machine->state().register_postload(schaser_reinit_555_time_remain, NULL);
}
diff --git a/src/mame/audio/cage.c b/src/mame/audio/cage.c
index df537751486..2984f1dd057 100644
--- a/src/mame/audio/cage.c
+++ b/src/mame/audio/cage.c
@@ -183,8 +183,7 @@ void cage_init(running_machine *machine, offs_t speedup)
state_save_register_global(machine, cpu_to_cage_ready);
state_save_register_global(machine, cage_to_cpu_ready);
- state_save_register_global(machine, serial_period_per_word.seconds);
- state_save_register_global(machine, serial_period_per_word.attoseconds);
+ state_save_register_global(machine, serial_period_per_word);
state_save_register_global(machine, dma_enabled);
state_save_register_global(machine, dma_timer_enabled);
state_save_register_global_array(machine, cage_timer_enabled);
diff --git a/src/mame/audio/dcs.c b/src/mame/audio/dcs.c
index abc666b7a46..647d184b99f 100644
--- a/src/mame/audio/dcs.c
+++ b/src/mame/audio/dcs.c
@@ -929,7 +929,7 @@ static void dcs_register_state(running_machine *machine)
state_save_register_global_pointer(machine, dcs_sram, 0x8000*4 / sizeof(dcs_sram[0]));
if (dcs.rev == 2)
- state_save_register_postload(machine, sdrc_postload, NULL);
+ machine->state().register_postload(sdrc_postload, NULL);
}
void dcs_init(running_machine *machine)
diff --git a/src/mame/drivers/20pacgal.c b/src/mame/drivers/20pacgal.c
index 908dc941f14..dccb52fd847 100644
--- a/src/mame/drivers/20pacgal.c
+++ b/src/mame/drivers/20pacgal.c
@@ -338,7 +338,7 @@ static MACHINE_START( 20pacgal )
state_save_register_global(machine, state->game_selected);
state_save_register_global_pointer(machine, state->ram_48000, 0x2000);
- state_save_register_postload(machine, postload_20pacgal, NULL);
+ machine->state().register_postload(postload_20pacgal, NULL);
}
static MACHINE_RESET( 20pacgal )
diff --git a/src/mame/drivers/ace.c b/src/mame/drivers/ace.c
index 7bd1dea183f..e2c887f2d1d 100644
--- a/src/mame/drivers/ace.c
+++ b/src/mame/drivers/ace.c
@@ -329,7 +329,7 @@ static MACHINE_START( ace )
{
ace_state *state = machine->driver_data<ace_state>();
state_save_register_global_array(machine, state->objpos);
- state_save_register_postload(machine, ace_postload, NULL);
+ machine->state().register_postload(ace_postload, NULL);
}
static MACHINE_RESET( ace )
diff --git a/src/mame/drivers/astrocde.c b/src/mame/drivers/astrocde.c
index 95d7628804d..13683210c54 100644
--- a/src/mame/drivers/astrocde.c
+++ b/src/mame/drivers/astrocde.c
@@ -1765,7 +1765,7 @@ static DRIVER_INIT( profpac )
/* reset banking */
profpac_banksw_w(iospace, 0, 0);
- state_save_register_postload(machine, profbank_banksw_restore, NULL);
+ machine->state().register_postload(profbank_banksw_restore, NULL);
}
@@ -1781,7 +1781,7 @@ static DRIVER_INIT( demndrgn )
/* reset banking */
profpac_banksw_w(iospace, 0, 0);
- state_save_register_postload(machine, profbank_banksw_restore, NULL);
+ machine->state().register_postload(profbank_banksw_restore, NULL);
}
@@ -1802,7 +1802,7 @@ static DRIVER_INIT( tenpindx )
/* reset banking */
profpac_banksw_w(iospace, 0, 0);
- state_save_register_postload(machine, profbank_banksw_restore, NULL);
+ machine->state().register_postload(profbank_banksw_restore, NULL);
}
diff --git a/src/mame/drivers/atarig1.c b/src/mame/drivers/atarig1.c
index 91c60f4dcb6..91e371529a2 100644
--- a/src/mame/drivers/atarig1.c
+++ b/src/mame/drivers/atarig1.c
@@ -1176,7 +1176,7 @@ static void init_g1_common(running_machine *machine, offs_t slapstic_base, int s
pitfightb_cheap_slapstic_init(machine);
state_save_register_global(machine, state->bslapstic_bank);
state_save_register_global(machine, state->bslapstic_primed);
- state_save_register_postload(machine, pitfightb_state_postload, NULL);
+ machine->state().register_postload(pitfightb_state_postload, NULL);
}
else if (slapstic != 0)
atarigen_slapstic_init(machine->device("maincpu"), slapstic_base, 0, slapstic);
diff --git a/src/mame/drivers/atarisy2.c b/src/mame/drivers/atarisy2.c
index b687deaf732..e1b0b6221b8 100644
--- a/src/mame/drivers/atarisy2.c
+++ b/src/mame/drivers/atarisy2.c
@@ -230,7 +230,7 @@ static MACHINE_START( atarisy2 )
state_save_register_global(machine, state->which_adc);
state_save_register_global(machine, state->p2portwr_state);
state_save_register_global(machine, state->p2portrd_state);
- state_save_register_postload(machine, bankselect_postload, NULL);
+ machine->state().register_postload(bankselect_postload, NULL);
state_save_register_global(machine, state->sound_reset_state);
}
diff --git a/src/mame/drivers/atetris.c b/src/mame/drivers/atetris.c
index 664c740df0d..6685f1ce4c0 100644
--- a/src/mame/drivers/atetris.c
+++ b/src/mame/drivers/atetris.c
@@ -119,7 +119,7 @@ static MACHINE_START( atetris )
/* Set up save state */
state_save_register_global(machine, state->current_bank);
state_save_register_global(machine, state->nvram_write_enable);
- state_save_register_postload(machine, atetris_postload, NULL);
+ machine->state().register_postload(atetris_postload, NULL);
}
diff --git a/src/mame/drivers/crystal.c b/src/mame/drivers/crystal.c
index 980248597f0..cc48c3e461d 100644
--- a/src/mame/drivers/crystal.c
+++ b/src/mame/drivers/crystal.c
@@ -585,7 +585,7 @@ static MACHINE_START( crystal )
state_save_register_global(machine, state->PIO);
state_save_register_global_array(machine, state->DMActrl);
state_save_register_global(machine, state->OldPort4);
- state_save_register_postload(machine, crystal_banksw_postload, NULL);
+ machine->state().register_postload(crystal_banksw_postload, NULL);
}
static MACHINE_RESET( crystal )
diff --git a/src/mame/drivers/darius.c b/src/mame/drivers/darius.c
index b4e35bf175b..256f56cbfc1 100644
--- a/src/mame/drivers/darius.c
+++ b/src/mame/drivers/darius.c
@@ -899,7 +899,7 @@ static MACHINE_START( darius )
state_save_register_global(machine, state->nmi_enable);
state_save_register_global_array(machine, state->vol);
state_save_register_global_array(machine, state->pan);
- state_save_register_postload(machine, darius_postload, NULL);
+ machine->state().register_postload(darius_postload, NULL);
}
diff --git a/src/mame/drivers/djmain.c b/src/mame/drivers/djmain.c
index 3e3a9bf49af..81beacad493 100644
--- a/src/mame/drivers/djmain.c
+++ b/src/mame/drivers/djmain.c
@@ -1442,7 +1442,7 @@ static MACHINE_START( djmain )
state_save_register_global(machine, v_ctrl);
state_save_register_global_array(machine, obj_regs);
- state_save_register_postload(machine, djmain_postload, NULL);
+ machine->state().register_postload(djmain_postload, NULL);
}
diff --git a/src/mame/drivers/dynax.c b/src/mame/drivers/dynax.c
index a1837aa8bb5..9186c5042e2 100644
--- a/src/mame/drivers/dynax.c
+++ b/src/mame/drivers/dynax.c
@@ -4933,7 +4933,7 @@ static MACHINE_START( tenkai )
{
MACHINE_START_CALL(dynax);
- state_save_register_postload(machine, tenkai_bank_postload, NULL);
+ machine->state().register_postload(tenkai_bank_postload, NULL);
}
static MACHINE_CONFIG_START( tenkai, dynax_state )
@@ -4996,7 +4996,7 @@ static MACHINE_START( gekisha )
{
MACHINE_START_CALL(dynax);
- state_save_register_postload(machine, gekisha_bank_postload, NULL);
+ machine->state().register_postload(gekisha_bank_postload, NULL);
}
static MACHINE_RESET( gekisha )
diff --git a/src/mame/drivers/forte2.c b/src/mame/drivers/forte2.c
index 246d0e16d16..f8623111142 100644
--- a/src/mame/drivers/forte2.c
+++ b/src/mame/drivers/forte2.c
@@ -107,7 +107,7 @@ static MACHINE_START( forte2 )
/* register for save states */
state_save_register_global(machine, forte2_input_mask);
- state_save_register_postload(machine, forte2, NULL);
+ machine->state().register_postload(forte2, NULL);
}
static MACHINE_RESET( forte2 )
diff --git a/src/mame/drivers/gottlieb.c b/src/mame/drivers/gottlieb.c
index 1d3b88f8675..32ba23fe3b4 100644
--- a/src/mame/drivers/gottlieb.c
+++ b/src/mame/drivers/gottlieb.c
@@ -294,10 +294,8 @@ static MACHINE_START( gottlieb )
state_save_register_global_pointer(machine, laserdisc_audio_buffer, AUDIORAM_SIZE);
state_save_register_global(machine, laserdisc_audio_address);
state_save_register_global_array(machine, laserdisc_last_samples);
- state_save_register_global(machine, laserdisc_last_time.seconds);
- state_save_register_global(machine, laserdisc_last_time.attoseconds);
- state_save_register_global(machine, laserdisc_last_clock.seconds);
- state_save_register_global(machine, laserdisc_last_clock.attoseconds);
+ state_save_register_global(machine, laserdisc_last_time);
+ state_save_register_global(machine, laserdisc_last_clock);
state_save_register_global(machine, laserdisc_zero_seen);
state_save_register_global(machine, laserdisc_audio_bits);
state_save_register_global(machine, laserdisc_audio_bit_count);
diff --git a/src/mame/drivers/liberatr.c b/src/mame/drivers/liberatr.c
index d4f9a8f2103..76febb61785 100644
--- a/src/mame/drivers/liberatr.c
+++ b/src/mame/drivers/liberatr.c
@@ -146,9 +146,9 @@ void liberatr_state::machine_start()
{
atarigen_state::machine_start();
- state_save_register_device_item(this, 0, m_trackball_offset);
- state_save_register_device_item(this, 0, m_ctrld);
- state_save_register_device_item_array(this, 0, m_videoram);
+ save_item(NAME(m_trackball_offset));
+ save_item(NAME(m_ctrld));
+ save_item(NAME(m_videoram));
}
diff --git a/src/mame/drivers/m90.c b/src/mame/drivers/m90.c
index 64e959feaed..b22c745a8d2 100644
--- a/src/mame/drivers/m90.c
+++ b/src/mame/drivers/m90.c
@@ -1148,7 +1148,7 @@ static DRIVER_INIT( quizf1 )
set_m90_bank(machine);
state_save_register_global(machine, bankaddress);
- state_save_register_postload(machine, quizf1_postload, NULL);
+ machine->state().register_postload(quizf1_postload, NULL);
}
diff --git a/src/mame/drivers/m92.c b/src/mame/drivers/m92.c
index 095efcf6650..73711f63614 100644
--- a/src/mame/drivers/m92.c
+++ b/src/mame/drivers/m92.c
@@ -233,7 +233,7 @@ static MACHINE_START( m92 )
state_save_register_global(machine, state->irqvector);
state_save_register_global(machine, state->sound_status);
state_save_register_global(machine, state->bankaddress);
- state_save_register_postload(machine, m92_postload, NULL);
+ machine->state().register_postload(m92_postload, NULL);
state->scanline_timer = machine->scheduler().timer_alloc(FUNC(m92_scanline_interrupt));
}
diff --git a/src/mame/drivers/mjsister.c b/src/mame/drivers/mjsister.c
index 6f6c7bb5a5c..64f317670c1 100644
--- a/src/mame/drivers/mjsister.c
+++ b/src/mame/drivers/mjsister.c
@@ -467,7 +467,7 @@ static MACHINE_START( mjsister )
state_save_register_global(machine, state->dac_bank);
state_save_register_global(machine, state->dac_adr_s);
state_save_register_global(machine, state->dac_adr_e);
- state_save_register_postload(machine, mjsister_redraw, 0);
+ machine->state().register_postload(mjsister_redraw, 0);
}
static MACHINE_RESET( mjsister )
diff --git a/src/mame/drivers/mw8080bw.c b/src/mame/drivers/mw8080bw.c
index f58c32a45da..4769c484798 100644
--- a/src/mame/drivers/mw8080bw.c
+++ b/src/mame/drivers/mw8080bw.c
@@ -900,7 +900,7 @@ static MACHINE_START( maze )
/* setup for save states */
state_save_register_global(machine, state->maze_tone_timing_state);
- state_save_register_postload(machine, maze_update_discrete, NULL);
+ machine->state().register_postload(maze_update_discrete, NULL);
MACHINE_START_CALL(mw8080bw);
}
diff --git a/src/mame/drivers/mystwarr.c b/src/mame/drivers/mystwarr.c
index bf8fe28165e..c4574dfe8c4 100644
--- a/src/mame/drivers/mystwarr.c
+++ b/src/mame/drivers/mystwarr.c
@@ -865,7 +865,7 @@ static MACHINE_START( mystwarr )
state_save_register_global(machine, mw_irq_control);
state_save_register_global(machine, cur_sound_region);
- state_save_register_postload(machine, mystwarr_postload, NULL);
+ machine->state().register_postload(mystwarr_postload, NULL);
}
static MACHINE_RESET(mystwarr)
diff --git a/src/mame/drivers/neogeo.c b/src/mame/drivers/neogeo.c
index aef773d3a6b..55f13e54cab 100644
--- a/src/mame/drivers/neogeo.c
+++ b/src/mame/drivers/neogeo.c
@@ -1102,7 +1102,7 @@ static MACHINE_START( neogeo )
state_save_register_global(machine, state->led2_value);
state_save_register_global(machine, state->recurse);
- state_save_register_postload(machine, neogeo_postload, NULL);
+ machine->state().register_postload(neogeo_postload, NULL);
}
diff --git a/src/mame/drivers/ninjaw.c b/src/mame/drivers/ninjaw.c
index 90dfe56c760..a9750f75391 100644
--- a/src/mame/drivers/ninjaw.c
+++ b/src/mame/drivers/ninjaw.c
@@ -783,7 +783,7 @@ static MACHINE_START( ninjaw )
state_save_register_global(machine, state->cpua_ctrl);
state_save_register_global(machine, state->banknum);
state_save_register_global_array(machine, state->pandata);
- state_save_register_postload(machine, ninjaw_postload, NULL);
+ machine->state().register_postload(ninjaw_postload, NULL);
}
static MACHINE_RESET( ninjaw )
diff --git a/src/mame/drivers/othunder.c b/src/mame/drivers/othunder.c
index 83dc27138c9..338267613c8 100644
--- a/src/mame/drivers/othunder.c
+++ b/src/mame/drivers/othunder.c
@@ -706,7 +706,7 @@ static MACHINE_START( othunder )
state_save_register_global(machine, state->ad_irq);
state_save_register_global(machine, state->banknum);
state_save_register_global_array(machine, state->pan);
- state_save_register_postload(machine, othunder_postload, NULL);
+ machine->state().register_postload(othunder_postload, NULL);
}
static MACHINE_RESET( othunder )
diff --git a/src/mame/drivers/pengadvb.c b/src/mame/drivers/pengadvb.c
index 512f4300bb5..50a8a78a6cd 100644
--- a/src/mame/drivers/pengadvb.c
+++ b/src/mame/drivers/pengadvb.c
@@ -248,7 +248,7 @@ static MACHINE_START( pengadvb )
state_save_register_global_pointer(machine, main_mem, 0x4000);
state_save_register_global(machine, mem_map);
state_save_register_global_array(machine, mem_banks);
- state_save_register_postload(machine, pengadvb, NULL);
+ machine->state().register_postload(pengadvb, NULL);
}
static MACHINE_RESET( pengadvb )
diff --git a/src/mame/drivers/psikyo4.c b/src/mame/drivers/psikyo4.c
index a319047def4..655c0b2a9b2 100644
--- a/src/mame/drivers/psikyo4.c
+++ b/src/mame/drivers/psikyo4.c
@@ -1072,8 +1072,8 @@ static void install_hotgmck_pcm_bank(running_machine *machine)
set_hotgmck_pcm_bank(machine, 1);
memory_install_write32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x5800008, 0x580000b, 0, 0, hotgmck_pcm_bank_w );
- state_save_register_postload(machine, hotgmck_pcm_bank_postload, (void *)0);
- state_save_register_postload(machine, hotgmck_pcm_bank_postload, (void *)1);
+ machine->state().register_postload(hotgmck_pcm_bank_postload, (void *)0);
+ machine->state().register_postload(hotgmck_pcm_bank_postload, (void *)1);
}
static DRIVER_INIT( hotgmck )
diff --git a/src/mame/drivers/renegade.c b/src/mame/drivers/renegade.c
index 981bc3cfb18..15d22cd74e2 100644
--- a/src/mame/drivers/renegade.c
+++ b/src/mame/drivers/renegade.c
@@ -265,7 +265,7 @@ static MACHINE_START( renegade )
state_save_register_global(machine, mcu_key);
state_save_register_global(machine, bank);
- state_save_register_postload(machine, renegade_postload, NULL);
+ machine->state().register_postload(renegade_postload, NULL);
}
static DRIVER_INIT( renegade )
diff --git a/src/mame/drivers/slapshot.c b/src/mame/drivers/slapshot.c
index 29729fa6198..a863b7c1411 100644
--- a/src/mame/drivers/slapshot.c
+++ b/src/mame/drivers/slapshot.c
@@ -547,7 +547,7 @@ static MACHINE_START( slapshot )
state->banknum = 0;
state_save_register_global(machine, state->banknum);
- state_save_register_postload(machine, slapshot_postload, NULL);
+ machine->state().register_postload(slapshot_postload, NULL);
}
diff --git a/src/mame/drivers/taito_f2.c b/src/mame/drivers/taito_f2.c
index 07272f13d8b..72d7ac6f4d1 100644
--- a/src/mame/drivers/taito_f2.c
+++ b/src/mame/drivers/taito_f2.c
@@ -5744,7 +5744,7 @@ static DRIVER_INIT( driveout )
state_save_register_global(machine, state->driveout_sound_latch);
state_save_register_global(machine, state->oki_bank);
state_save_register_global(machine, state->nibble);
- state_save_register_postload(machine, driveout_postload, NULL);
+ machine->state().register_postload(driveout_postload, NULL);
}
diff --git a/src/mame/drivers/taito_h.c b/src/mame/drivers/taito_h.c
index 18c030519b5..ad2e7ac43a2 100644
--- a/src/mame/drivers/taito_h.c
+++ b/src/mame/drivers/taito_h.c
@@ -534,7 +534,7 @@ static MACHINE_START( taitoh )
state->tc0080vco = machine->device("tc0080vco");
state_save_register_global(machine, state->banknum);
- state_save_register_postload(machine, taitoh_postload, NULL);
+ machine->state().register_postload(taitoh_postload, NULL);
}
diff --git a/src/mame/drivers/taito_x.c b/src/mame/drivers/taito_x.c
index d92e707b122..3098f775053 100644
--- a/src/mame/drivers/taito_x.c
+++ b/src/mame/drivers/taito_x.c
@@ -898,7 +898,7 @@ static MACHINE_START( taitox )
state->taitox_banknum = -1;
state_save_register_global(machine, state->taitox_banknum);
- state_save_register_postload(machine, taitox_postload, NULL);
+ machine->state().register_postload(taitox_postload, NULL);
}
static const tc0140syt_interface taitox_tc0140syt_intf =
diff --git a/src/mame/drivers/taito_z.c b/src/mame/drivers/taito_z.c
index 7bdb9f94e39..48da1385668 100644
--- a/src/mame/drivers/taito_z.c
+++ b/src/mame/drivers/taito_z.c
@@ -2994,7 +2994,7 @@ static MACHINE_START( taitoz )
memory_configure_bank(machine, "bank10", 0, banks, machine->region("audiocpu")->base() + 0xc000, 0x4000);
- state_save_register_postload(machine, taitoz_postload, NULL);
+ machine->state().register_postload(taitoz_postload, NULL);
MACHINE_START_CALL(bshark);
}
@@ -4888,7 +4888,7 @@ static DRIVER_INIT( bshark )
state->dblaxle_vibration = 0;
state->eep_latch = 0;
- state_save_register_postload(machine, bshark_postload, NULL);
+ machine->state().register_postload(bshark_postload, NULL);
state_save_register_global(machine, state->eep_latch);
}
diff --git a/src/mame/drivers/taitoair.c b/src/mame/drivers/taitoair.c
index e86dff3fd60..ea9164aa7c1 100644
--- a/src/mame/drivers/taitoair.c
+++ b/src/mame/drivers/taitoair.c
@@ -630,7 +630,7 @@ static MACHINE_START( taitoair )
state_save_register_item(machine, "globals", NULL, i, state->q.p[i].y);
}
- state_save_register_postload(machine, taitoair_postload, NULL);
+ machine->state().register_postload(taitoair_postload, NULL);
}
static MACHINE_RESET( taitoair )
diff --git a/src/mame/drivers/topspeed.c b/src/mame/drivers/topspeed.c
index 7aacf44bbc9..d6de269ea17 100644
--- a/src/mame/drivers/topspeed.c
+++ b/src/mame/drivers/topspeed.c
@@ -662,7 +662,7 @@ static MACHINE_START( topspeed )
state_save_register_global(machine, state->cpua_ctrl);
state_save_register_global(machine, state->ioc220_port);
state_save_register_global(machine, state->banknum);
- state_save_register_postload(machine, topspeed_postload, NULL);
+ machine->state().register_postload(topspeed_postload, NULL);
}
static MACHINE_RESET( topspeed )
diff --git a/src/mame/drivers/vegas.c b/src/mame/drivers/vegas.c
index c7b7440c577..e84bf6fd472 100644
--- a/src/mame/drivers/vegas.c
+++ b/src/mame/drivers/vegas.c
@@ -565,7 +565,7 @@ static MACHINE_START( vegas )
state_save_register_global(machine, sio_led_state);
state_save_register_global(machine, pending_analog_read);
state_save_register_global(machine, cmos_unlocked);
- state_save_register_postload(machine, vegas_postload, NULL);
+ machine->state().register_postload(vegas_postload, NULL);
}
diff --git a/src/mame/drivers/warriorb.c b/src/mame/drivers/warriorb.c
index 02723248521..992fb7b1808 100644
--- a/src/mame/drivers/warriorb.c
+++ b/src/mame/drivers/warriorb.c
@@ -558,7 +558,7 @@ static MACHINE_START( warriorb )
state_save_register_global(machine, state->banknum);
state_save_register_global_array(machine, state->pandata);
- state_save_register_postload(machine, warriorb_postload, NULL);
+ machine->state().register_postload(warriorb_postload, NULL);
}
static MACHINE_RESET( taito_dualscreen )
diff --git a/src/mame/drivers/wgp.c b/src/mame/drivers/wgp.c
index 4b349920d6e..48466ff6b65 100644
--- a/src/mame/drivers/wgp.c
+++ b/src/mame/drivers/wgp.c
@@ -964,7 +964,7 @@ static MACHINE_START( wgp )
state_save_register_global(machine, state->cpua_ctrl);
state_save_register_global(machine, state->banknum);
state_save_register_global(machine, state->port_sel);
- state_save_register_postload(machine, wgp_postload, NULL);
+ machine->state().register_postload(wgp_postload, NULL);
}
static const tc0100scn_interface wgp_tc0100scn_intf =
diff --git a/src/mame/drivers/xexex.c b/src/mame/drivers/xexex.c
index 76240a08529..c243756cfbf 100644
--- a/src/mame/drivers/xexex.c
+++ b/src/mame/drivers/xexex.c
@@ -493,7 +493,7 @@ static MACHINE_START( xexex )
state_save_register_global(machine, state->cur_control2);
state_save_register_global(machine, state->cur_sound_region);
- state_save_register_postload(machine, xexex_postload, NULL);
+ machine->state().register_postload(xexex_postload, NULL);
state->dmadelay_timer = machine->scheduler().timer_alloc(FUNC(dmaend_callback));
}
diff --git a/src/mame/drivers/xmen.c b/src/mame/drivers/xmen.c
index 4a63b30718f..d86f65c4fce 100644
--- a/src/mame/drivers/xmen.c
+++ b/src/mame/drivers/xmen.c
@@ -330,7 +330,7 @@ static MACHINE_START( xmen )
state_save_register_global(machine, state->sprite_colorbase);
state_save_register_global_array(machine, state->layer_colorbase);
state_save_register_global_array(machine, state->layerpri);
- state_save_register_postload(machine, xmen_postload, NULL);
+ machine->state().register_postload(xmen_postload, NULL);
}
static MACHINE_RESET( xmen )
diff --git a/src/mame/machine/atarigen.c b/src/mame/machine/atarigen.c
index c2fbfb2e013..c5a2688a601 100644
--- a/src/mame/machine/atarigen.c
+++ b/src/mame/machine/atarigen.c
@@ -165,7 +165,7 @@ void atarigen_init(running_machine *machine)
state_save_register_global(machine, state->playfield2_latch);
/* need a postload to reset the state */
- state_save_register_postload(machine, slapstic_postload, NULL);
+ machine->state().register_postload(slapstic_postload, NULL);
}
diff --git a/src/mame/machine/midwayic.c b/src/mame/machine/midwayic.c
index e9ad14988b6..f625e667c02 100644
--- a/src/mame/machine/midwayic.c
+++ b/src/mame/machine/midwayic.c
@@ -258,8 +258,7 @@ static TIMER_CALLBACK( reset_timer )
static void pic_register_state(running_machine *machine)
{
state_save_register_global(machine, pic.latch);
- state_save_register_global(machine, pic.latch_expire_time.seconds);
- state_save_register_global(machine, pic.latch_expire_time.attoseconds);
+ state_save_register_global(machine, pic.latch_expire_time);
state_save_register_global(machine, pic.state);
state_save_register_global(machine, pic.index);
state_save_register_global(machine, pic.total);
diff --git a/src/mame/machine/naomibd.c b/src/mame/machine/naomibd.c
index 6d7a5ac7793..53dbdc6a4ab 100644
--- a/src/mame/machine/naomibd.c
+++ b/src/mame/machine/naomibd.c
@@ -413,7 +413,7 @@ static void init_save_state(device_t *device)
{
naomibd_state *v = get_safe_token(device);
- state_save_register_postload(device->machine, naomibd_postload, v);
+ device->machine->state().register_postload(naomibd_postload, v);
/* register states */
state_save_register_device_item(device, 0, v->rom_offset);
diff --git a/src/mame/machine/nmk112.c b/src/mame/machine/nmk112.c
index 60defd34d11..eef608bbdcd 100644
--- a/src/mame/machine/nmk112.c
+++ b/src/mame/machine/nmk112.c
@@ -140,7 +140,7 @@ static DEVICE_START( nmk112 )
nmk112->page_mask = ~intf->disable_page_mask;
state_save_register_device_item_array(device, 0, nmk112->current_bank);
- state_save_register_postload(device->machine, nmk112_postload_bankswitch, nmk112);
+ device->machine->state().register_postload(nmk112_postload_bankswitch, nmk112);
}
static DEVICE_RESET( nmk112 )
diff --git a/src/mame/machine/psx.c b/src/mame/machine/psx.c
index 77764f6319a..0a8f2593a11 100644
--- a/src/mame/machine/psx.c
+++ b/src/mame/machine/psx.c
@@ -1749,5 +1749,5 @@ void psx_driver_init( running_machine *machine )
state_save_register_global_array( machine, p_psx->mdec.p_n_quantize_uv );
state_save_register_global_array( machine, p_psx->mdec.p_n_cos );
- state_save_register_postload( machine, psx_postload, NULL );
+ machine->state().register_postload( psx_postload, NULL );
}
diff --git a/src/mame/machine/s16fd.c b/src/mame/machine/s16fd.c
index c1de529c687..e23b3160f2d 100644
--- a/src/mame/machine/s16fd.c
+++ b/src/mame/machine/s16fd.c
@@ -228,5 +228,5 @@ void fd1094_driver_init(running_machine *machine, const char* tag, void (*set_de
state_save_register_global(machine, fd1094_selected_state);
state_save_register_global(machine, fd1094_state);
- state_save_register_postload(machine, fd1094_postload, NULL);
+ machine->state().register_postload(fd1094_postload, NULL);
}
diff --git a/src/mame/machine/s24fd.c b/src/mame/machine/s24fd.c
index 2781aa591ee..7fc913693f1 100644
--- a/src/mame/machine/s24fd.c
+++ b/src/mame/machine/s24fd.c
@@ -179,5 +179,5 @@ void s24_fd1094_driver_init(running_machine *machine)
state_save_register_global(machine, fd1094_selected_state);
state_save_register_global(machine, fd1094_state);
- state_save_register_postload(machine, s24_fd1094_postload, NULL);
+ machine->state().register_postload(s24_fd1094_postload, NULL);
}
diff --git a/src/mame/machine/simpsons.c b/src/mame/machine/simpsons.c
index 863fb579387..499fbbe30d4 100644
--- a/src/mame/machine/simpsons.c
+++ b/src/mame/machine/simpsons.c
@@ -101,7 +101,7 @@ MACHINE_START( simpsons )
state_save_register_global_pointer(machine, machine->generic.paletteram.u8, 0x1000);
state_save_register_global_pointer(machine, state->xtraram, 0x1000);
state_save_register_global_pointer(machine, state->spriteram, 0x1000 / 2);
- state_save_register_postload(machine, simpsons_postload, NULL);
+ machine->state().register_postload(simpsons_postload, NULL);
}
MACHINE_RESET( simpsons )
diff --git a/src/mame/machine/tnzs.c b/src/mame/machine/tnzs.c
index aaf4a576ba5..69ac50afab2 100644
--- a/src/mame/machine/tnzs.c
+++ b/src/mame/machine/tnzs.c
@@ -713,7 +713,7 @@ MACHINE_START( tnzs )
state_save_register_global(machine, state->bank1);
state_save_register_global(machine, state->bank2);
- state_save_register_postload(machine, tnzs_postload, NULL);
+ machine->state().register_postload(tnzs_postload, NULL);
}
MACHINE_START( jpopnics )
@@ -735,7 +735,7 @@ MACHINE_START( jpopnics )
state_save_register_global(machine, state->bank1);
state_save_register_global(machine, state->bank2);
- state_save_register_postload(machine, tnzs_postload, NULL);
+ machine->state().register_postload(tnzs_postload, NULL);
}
diff --git a/src/mame/machine/toaplan1.c b/src/mame/machine/toaplan1.c
index 12a297b8518..1cdff604568 100644
--- a/src/mame/machine/toaplan1.c
+++ b/src/mame/machine/toaplan1.c
@@ -439,7 +439,7 @@ void demonwld_driver_savestate(running_machine *machine)
state_save_register_global(machine, state->main_ram_seg);
state_save_register_global(machine, state->dsp_BIO);
state_save_register_global(machine, state->dsp_execute);
- state_save_register_postload(machine, demonwld_restore_dsp, NULL);
+ machine->state().register_postload(demonwld_restore_dsp, NULL);
}
MACHINE_RESET( vimana )
diff --git a/src/mame/machine/twincobr.c b/src/mame/machine/twincobr.c
index 6a3b556af31..ef49c4cb59d 100644
--- a/src/mame/machine/twincobr.c
+++ b/src/mame/machine/twincobr.c
@@ -345,7 +345,7 @@ void twincobr_driver_savestate(running_machine *machine)
state_save_register_global(machine, twincobr_dsp_BIO);
state_save_register_global(machine, dsp_execute);
state_save_register_global(machine, fsharkbt_8741);
- state_save_register_postload(machine, twincobr_restore_dsp, NULL);
+ machine->state().register_postload(twincobr_restore_dsp, NULL);
}
MACHINE_RESET( wardner )
@@ -369,6 +369,6 @@ void wardner_driver_savestate(running_machine *machine)
state_save_register_global(machine, twincobr_dsp_BIO);
state_save_register_global(machine, dsp_execute);
state_save_register_global(machine, wardner_membank);
- state_save_register_postload(machine, wardner_restore_bank, NULL); /* Restore the Main CPU bank */
- state_save_register_postload(machine, twincobr_restore_dsp, NULL);
+ machine->state().register_postload(wardner_restore_bank, NULL); /* Restore the Main CPU bank */
+ machine->state().register_postload(twincobr_restore_dsp, NULL);
}
diff --git a/src/mame/machine/vertigo.c b/src/mame/machine/vertigo.c
index 9bcee6a0b6d..f827d85ce20 100644
--- a/src/mame/machine/vertigo.c
+++ b/src/mame/machine/vertigo.c
@@ -210,8 +210,7 @@ MACHINE_START( vertigo )
{
state_save_register_global(machine, irq_state);
state_save_register_global(machine, adc_result);
- state_save_register_global(machine, irq4_time.seconds);
- state_save_register_global(machine, irq4_time.attoseconds);
+ state_save_register_global(machine, irq4_time);
vertigo_vproc_init(machine);
}
diff --git a/src/mame/machine/williams.c b/src/mame/machine/williams.c
index 7635214341a..a17216a7532 100644
--- a/src/mame/machine/williams.c
+++ b/src/mame/machine/williams.c
@@ -454,7 +454,7 @@ MACHINE_START( williams2 )
/* register for save states */
state_save_register_global(machine, vram_bank);
- state_save_register_postload(machine, williams2_postload, NULL);
+ machine->state().register_postload(williams2_postload, NULL);
}
@@ -739,7 +739,7 @@ MACHINE_START( defender )
/* configure the banking and make sure it is reset to 0 */
memory_configure_bank(machine, "bank1", 0, 9, &machine->region("maincpu")->base()[0x10000], 0x1000);
- state_save_register_postload(machine, defender_postload, NULL);
+ machine->state().register_postload(defender_postload, NULL);
}
diff --git a/src/mame/video/40love.c b/src/mame/video/40love.c
index c75865f000d..48cf039eb04 100644
--- a/src/mame/video/40love.c
+++ b/src/mame/video/40love.c
@@ -123,7 +123,7 @@ VIDEO_START( fortyl )
state_save_register_global_bitmap(machine, state->tmp_bitmap1);
state_save_register_global_bitmap(machine, state->tmp_bitmap2);
state_save_register_global(machine, state->pixram_sel);
- state_save_register_postload(machine, redraw_pixels, NULL);
+ machine->state().register_postload(redraw_pixels, NULL);
}
diff --git a/src/mame/video/atarimo.c b/src/mame/video/atarimo.c
index acb38fa7a59..eeb7029f868 100644
--- a/src/mame/video/atarimo.c
+++ b/src/mame/video/atarimo.c
@@ -295,9 +295,9 @@ static void init_savestate(running_machine *machine, int index, atarimo_data *mo
state_save_register_item(machine, "atarimo", NULL, index, mo->dirtyheight);
#endif
- state_save_register_bitmap(machine, "atarimo", NULL, index, "bitmap", mo->bitmap, __FILE__, __LINE__);
+ machine->state().save_item("atarimo", NULL, index, *mo->bitmap, "bitmap");
- state_save_register_memory(machine, "atarimo", NULL, index, "spriteram", mo->spriteram, sizeof(atarimo_entry), mo->spriteramsize, __FILE__, __LINE__);
+ machine->state().save_memory("atarimo", NULL, index, "spriteram", mo->spriteram, sizeof(atarimo_entry), mo->spriteramsize);
state_save_register_item_pointer(machine, "atarimo", NULL, index, mo->codelookup, round_to_powerof2(mo->codemask.mask));
diff --git a/src/mame/video/cave.c b/src/mame/video/cave.c
index d4415d8e754..d9fe458b7e8 100644
--- a/src/mame/video/cave.c
+++ b/src/mame/video/cave.c
@@ -794,7 +794,7 @@ static void sprite_init_cave( running_machine *machine )
state_save_register_global(machine, state->blit.clip_top);
state_save_register_global(machine, state->blit.clip_bottom);
- state_save_register_postload(machine, cave_sprite_postload, NULL);
+ machine->state().register_postload(cave_sprite_postload, NULL);
}
static void cave_sprite_check( screen_device &screen, const rectangle *clip )
diff --git a/src/mame/video/chaknpop.c b/src/mame/video/chaknpop.c
index f94f9cbc13c..478fc32ec56 100644
--- a/src/mame/video/chaknpop.c
+++ b/src/mame/video/chaknpop.c
@@ -181,7 +181,7 @@ VIDEO_START( chaknpop )
memory_set_bank(machine, "bank1", 0);
tx_tilemap_mark_all_dirty(machine);
- state_save_register_postload(machine, chaknpop_postload, NULL);
+ machine->state().register_postload(chaknpop_postload, NULL);
}
diff --git a/src/mame/video/cloak.c b/src/mame/video/cloak.c
index a1ff73f5e2f..935dcd08c1d 100644
--- a/src/mame/video/cloak.c
+++ b/src/mame/video/cloak.c
@@ -192,7 +192,7 @@ VIDEO_START( cloak )
state_save_register_global_pointer(machine, state->bitmap_videoram1, 256*256);
state_save_register_global_pointer(machine, state->bitmap_videoram2, 256*256);
state_save_register_global_pointer(machine, state->palette_ram, NUM_PENS);
- state_save_register_postload(machine, cloak_postload, NULL);
+ machine->state().register_postload(cloak_postload, NULL);
}
static void draw_bitmap(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
diff --git a/src/mame/video/cps1.c b/src/mame/video/cps1.c
index 2d8a3891bc9..65d7df0aefa 100644
--- a/src/mame/video/cps1.c
+++ b/src/mame/video/cps1.c
@@ -2167,7 +2167,7 @@ static VIDEO_START( cps )
state_save_register_global_pointer(machine, state->cps2_buffered_obj, state->cps2_obj_size / 2);
}
- state_save_register_postload(machine, cps_postload, NULL);
+ machine->state().register_postload(cps_postload, NULL);
}
VIDEO_START( cps1 )
diff --git a/src/mame/video/gradius3.c b/src/mame/video/gradius3.c
index ed7a2cced6d..dc42fb459f0 100644
--- a/src/mame/video/gradius3.c
+++ b/src/mame/video/gradius3.c
@@ -88,7 +88,7 @@ VIDEO_START( gradius3 )
gfx_element_set_source(machine->gfx[0], (UINT8 *)state->gfxram);
- state_save_register_postload(machine, gradius3_postload, NULL);
+ machine->state().register_postload(gradius3_postload, NULL);
}
diff --git a/src/mame/video/gridlee.c b/src/mame/video/gridlee.c
index 73c25134577..0cd5f817dca 100644
--- a/src/mame/video/gridlee.c
+++ b/src/mame/video/gridlee.c
@@ -91,7 +91,7 @@ VIDEO_START( gridlee )
state_save_register_global(machine, gridlee_cocktail_flip);
state_save_register_global(machine, palettebank_vis);
- state_save_register_postload(machine, expand_pixels, NULL);
+ machine->state().register_postload(expand_pixels, NULL);
}
diff --git a/src/mame/video/gtia.c b/src/mame/video/gtia.c
index 4ecfdc1922d..b75606adedc 100644
--- a/src/mame/video/gtia.c
+++ b/src/mame/video/gtia.c
@@ -139,7 +139,7 @@ static void gtia_state(running_machine *machine)
state_save_register_global(machine, gtia.w.gractl);
state_save_register_global(machine, gtia.w.hitclr);
state_save_register_global(machine, gtia.w.cons);
- state_save_register_postload(machine, gtia_state_postload, NULL);
+ machine->state().register_postload(gtia_state_postload, NULL);
}
diff --git a/src/mame/video/hyprduel.c b/src/mame/video/hyprduel.c
index 27e113fbe39..a2980669947 100644
--- a/src/mame/video/hyprduel.c
+++ b/src/mame/video/hyprduel.c
@@ -381,7 +381,7 @@ static VIDEO_START( common_14220 )
/* Set up save state */
state_save_register_global(machine, state->sprite_xoffs);
state_save_register_global(machine, state->sprite_yoffs);
- state_save_register_postload(machine, hyprduel_postload, NULL);
+ machine->state().register_postload(hyprduel_postload, NULL);
}
VIDEO_START( hyprduel_14220 )
diff --git a/src/mame/video/jaguar.c b/src/mame/video/jaguar.c
index a48d924049a..415674f38b8 100644
--- a/src/mame/video/jaguar.c
+++ b/src/mame/video/jaguar.c
@@ -915,7 +915,7 @@ VIDEO_START( cojag )
state_save_register_global_array(machine, blitter_regs);
state_save_register_global_array(machine, gpu_regs);
state_save_register_global(machine, cpu_irq_state);
- state_save_register_postload(machine, cojag_postload, NULL);
+ machine->state().register_postload(cojag_postload, NULL);
}
diff --git a/src/mame/video/konamiic.c b/src/mame/video/konamiic.c
index 4d2c4ed606e..4e897156c13 100644
--- a/src/mame/video/konamiic.c
+++ b/src/mame/video/konamiic.c
@@ -2069,7 +2069,7 @@ void K052109_vh_start(running_machine *machine,const char *gfx_memory_region,int
state_save_register_global_array(machine, K052109_dy);
state_save_register_global(machine, has_extra_video_ram);
- state_save_register_postload(machine, K052109_tileflip_reset, NULL);
+ machine->state().register_postload(K052109_tileflip_reset, NULL);
}
READ8_HANDLER( K052109_r )
@@ -5128,7 +5128,7 @@ void K053251_vh_start(running_machine *machine)
K053251_set_tilemaps(NULL,NULL,NULL,NULL,NULL);
state_save_register_global_array(machine, K053251_ram);
- state_save_register_postload(machine, K053251_reset_indexes, NULL);
+ machine->state().register_postload(K053251_reset_indexes, NULL);
}
void K053251_set_tilemaps(tilemap_t *ci0,tilemap_t *ci1,tilemap_t *ci2,tilemap_t *ci3,tilemap_t *ci4)
@@ -5901,7 +5901,7 @@ void K056832_vh_start(running_machine *machine, const char *gfx_memory_region, i
state_save_register_global_array(machine, K056832_dy);
state_save_register_global_array(machine, K056832_LayerTileMode);
- state_save_register_postload(machine, K056832_postload, NULL);
+ machine->state().register_postload(K056832_postload, NULL);
}
/* call if a game uses external linescroll */
diff --git a/src/mame/video/konicdev.c b/src/mame/video/konicdev.c
index 0157f8d5b4f..caa91652040 100644
--- a/src/mame/video/konicdev.c
+++ b/src/mame/video/konicdev.c
@@ -2746,7 +2746,7 @@ static DEVICE_START( k052109 )
state_save_register_device_item_array(device, 0, k052109->dx);
state_save_register_device_item_array(device, 0, k052109->dy);
state_save_register_device_item(device, 0, k052109->has_extra_video_ram);
- state_save_register_postload(device->machine, k052109_tileflip_reset, k052109);
+ device->machine->state().register_postload(k052109_tileflip_reset, k052109);
}
static DEVICE_RESET( k052109 )
@@ -5757,7 +5757,7 @@ static DEVICE_START( k053251 )
state_save_register_device_item(device, 0, k053251->tilemaps_set);
state_save_register_device_item_array(device, 0, k053251->dirty_tmap);
- state_save_register_postload(device->machine, k053251_reset_indexes, k053251);
+ device->machine->state().register_postload(k053251_reset_indexes, k053251);
}
static DEVICE_RESET( k053251 )
@@ -8003,7 +8003,7 @@ static DEVICE_START( k056832 )
state_save_register_device_item(device, i, k056832->last_colorbase[i]);
}
- state_save_register_postload(device->machine, k056832_postload, k056832);
+ device->machine->state().register_postload(k056832_postload, k056832);
}
/***************************************************************************/
diff --git a/src/mame/video/nemesis.c b/src/mame/video/nemesis.c
index f699a1e831f..dea28829ece 100644
--- a/src/mame/video/nemesis.c
+++ b/src/mame/video/nemesis.c
@@ -330,7 +330,7 @@ VIDEO_START( nemesis )
gfx_element_set_source(machine->gfx[7], (UINT8 *)state->charram);
/* Set up save state */
- state_save_register_postload(machine, nemesis_postload, NULL);
+ machine->state().register_postload(nemesis_postload, NULL);
}
diff --git a/src/mame/video/neogeo.c b/src/mame/video/neogeo.c
index 3f56130965e..cd1a52795ff 100644
--- a/src/mame/video/neogeo.c
+++ b/src/mame/video/neogeo.c
@@ -892,7 +892,7 @@ VIDEO_START( neogeo )
state_save_register_global(machine, state->auto_animation_counter);
state_save_register_global(machine, state->auto_animation_frame_counter);
- state_save_register_postload(machine, regenerate_pens, NULL);
+ machine->state().register_postload(regenerate_pens, NULL);
state->region_zoomy = machine->region("zoomy")->base();
}
diff --git a/src/mame/video/psx.c b/src/mame/video/psx.c
index 59ec4b191c3..b940c33417b 100644
--- a/src/mame/video/psx.c
+++ b/src/mame/video/psx.c
@@ -749,7 +749,7 @@ static void psx_gpu_init( running_machine *machine, int n_gputype )
}
// icky!!!
- state_save_register_memory( machine, "globals", NULL, 0, "m_packet", (UINT8 *)&p_psxgpu->m_packet, 1, sizeof( p_psxgpu->m_packet ), __FILE__, __LINE__ );
+ machine->state().save_memory( "globals", NULL, 0, "m_packet", (UINT8 *)&p_psxgpu->m_packet, 1, sizeof( p_psxgpu->m_packet ) );
state_save_register_global_pointer( machine, p_psxgpu->p_vram, p_psxgpu->n_vram_size );
state_save_register_global( machine, p_psxgpu->n_gpu_buffer_offset );
@@ -783,7 +783,7 @@ static void psx_gpu_init( running_machine *machine, int n_gputype )
state_save_register_global( machine, p_psxgpu->n_iy );
state_save_register_global( machine, p_psxgpu->n_ti );
- state_save_register_postload( machine, updatevisiblearea, NULL );
+ machine->state().register_postload( updatevisiblearea, NULL );
machine->driver_data<psx_state>()->p_psxgpu = p_psxgpu;
}
diff --git a/src/mame/video/stvvdp1.c b/src/mame/video/stvvdp1.c
index 0fbe4271697..b0fc18c1441 100644
--- a/src/mame/video/stvvdp1.c
+++ b/src/mame/video/stvvdp1.c
@@ -2130,6 +2130,6 @@ int stv_vdp1_start ( running_machine *machine )
state_save_register_global(machine, stv_vdp1_clear_framebuffer_on_next_frame);
state_save_register_global(machine, stvvdp1_local_x);
state_save_register_global(machine, stvvdp1_local_y);
- state_save_register_postload(machine, stv_vdp1_state_save_postload, NULL);
+ machine->state().register_postload(stv_vdp1_state_save_postload, NULL);
return 0;
}
diff --git a/src/mame/video/stvvdp2.c b/src/mame/video/stvvdp2.c
index fe3a49dda3d..8df85a4403c 100644
--- a/src/mame/video/stvvdp2.c
+++ b/src/mame/video/stvvdp2.c
@@ -5462,7 +5462,7 @@ static int stv_vdp2_start (running_machine *machine)
state_save_register_global_pointer(machine, stv_vdp2_regs, 0x040000/4);
state_save_register_global_pointer(machine, stv_vdp2_vram, 0x100000/4);
state_save_register_global_pointer(machine, stv_vdp2_cram, 0x080000/4);
- state_save_register_postload(machine, stv_vdp2_state_save_postload, NULL);
+ machine->state().register_postload(stv_vdp2_state_save_postload, NULL);
return 0;
}
diff --git a/src/mame/video/tail2nos.c b/src/mame/video/tail2nos.c
index 9f31a5db221..b03f3b6b91e 100644
--- a/src/mame/video/tail2nos.c
+++ b/src/mame/video/tail2nos.c
@@ -65,7 +65,7 @@ VIDEO_START( tail2nos )
state->zoomdata = (UINT16 *)machine->region("gfx3")->base();
state_save_register_global_pointer(machine, state->zoomdata, 0x20000 / 2);
- state_save_register_postload(machine, tail2nos_postload, NULL);
+ machine->state().register_postload(tail2nos_postload, NULL);
}
diff --git a/src/mame/video/taitoic.c b/src/mame/video/taitoic.c
index 6434cecbc34..7b356f50cde 100644
--- a/src/mame/video/taitoic.c
+++ b/src/mame/video/taitoic.c
@@ -1021,7 +1021,7 @@ static DEVICE_START( pc080sn )
state_save_register_device_item_pointer(device, 0, pc080sn->ram, PC080SN_RAM_SIZE / 2);
state_save_register_device_item_array(device, 0, pc080sn->ctrl);
- state_save_register_postload(device->machine, pc080sn_restore_scroll, pc080sn);
+ device->machine->state().register_postload(pc080sn_restore_scroll, pc080sn);
}
@@ -1907,7 +1907,7 @@ static DEVICE_START( tc0080vco )
device->machine->gfx[tc0080vco->tx_gfx] = gfx_element_alloc(device->machine, &tc0080vco_charlayout, (UINT8 *)tc0080vco->char_ram, 64, 0);
state_save_register_device_item_pointer(device, 0, tc0080vco->ram, TC0080VCO_RAM_SIZE / 2);
- state_save_register_postload(device->machine, tc0080vco_postload, tc0080vco);
+ device->machine->state().register_postload(tc0080vco_postload, tc0080vco);
}
/***************************************************************************/
@@ -2517,7 +2517,7 @@ static DEVICE_START( tc0100scn )
state_save_register_device_item_array(device, 0, tc0100scn->ctrl);
state_save_register_device_item(device, 0, tc0100scn->dblwidth);
state_save_register_device_item(device, 0, tc0100scn->gfxbank);
- state_save_register_postload(device->machine, tc0100scn_postload, tc0100scn);
+ device->machine->state().register_postload(tc0100scn_postload, tc0100scn);
}
@@ -3727,7 +3727,7 @@ static DEVICE_START( tc0480scp )
state_save_register_device_item_pointer(device, 0, tc0480scp->ram, TC0480SCP_RAM_SIZE / 2);
state_save_register_device_item_array(device, 0, tc0480scp->ctrl);
state_save_register_device_item(device, 0, tc0480scp->dblwidth);
- state_save_register_postload(device->machine, tc0480scp_postload, tc0480scp);
+ device->machine->state().register_postload(tc0480scp_postload, tc0480scp);
}
static DEVICE_RESET( tc0480scp )
@@ -4760,7 +4760,7 @@ static DEVICE_START( tc0110pcr )
state_save_register_device_item_pointer(device, 0, tc0110pcr->ram, TC0110PCR_RAM_SIZE);
state_save_register_device_item(device, 0, tc0110pcr->type);
- state_save_register_postload(device->machine, tc0110pcr_restore_colors, tc0110pcr);
+ device->machine->state().register_postload(tc0110pcr_restore_colors, tc0110pcr);
}
static DEVICE_RESET( tc0110pcr )
diff --git a/src/mame/video/toaplan1.c b/src/mame/video/toaplan1.c
index 1fbb22a408c..3890171656f 100644
--- a/src/mame/video/toaplan1.c
+++ b/src/mame/video/toaplan1.c
@@ -360,7 +360,7 @@ VIDEO_START( rallybik )
register_common(machine);
- state_save_register_postload(machine, rallybik_flipscreen, NULL);
+ machine->state().register_postload(rallybik_flipscreen, NULL);
}
VIDEO_START( toaplan1 )
@@ -384,7 +384,7 @@ VIDEO_START( toaplan1 )
register_common(machine);
- state_save_register_postload(machine, toaplan1_flipscreen, NULL);
+ machine->state().register_postload(toaplan1_flipscreen, NULL);
}
diff --git a/src/mame/video/tumbleb.c b/src/mame/video/tumbleb.c
index 22fc6d118e7..c04986f25db 100644
--- a/src/mame/video/tumbleb.c
+++ b/src/mame/video/tumbleb.c
@@ -507,7 +507,7 @@ VIDEO_START( pangpang )
state->sprite_xoffset = -1;
state->sprite_yoffset = 0;
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
@@ -525,7 +525,7 @@ VIDEO_START( tumblepb )
state->sprite_xoffset = -1;
state->sprite_yoffset = 0;
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
VIDEO_START( sdfight )
@@ -543,7 +543,7 @@ VIDEO_START( sdfight )
state->sprite_xoffset = 0;
state->sprite_yoffset = 1;
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
VIDEO_START( fncywld )
@@ -560,7 +560,7 @@ VIDEO_START( fncywld )
state->sprite_xoffset = -1;
state->sprite_yoffset = 0;
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
VIDEO_START( jumppop )
@@ -583,7 +583,7 @@ VIDEO_START( jumppop )
state->sprite_xoffset = -1;
state->sprite_yoffset = 0;
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
@@ -597,7 +597,7 @@ VIDEO_START( suprtrio )
tilemap_set_transparent_pen(state->pf1_alt_tilemap, 0);
- state_save_register_postload(machine, tumbleb_tilemap_redraw, NULL);
+ machine->state().register_postload(tumbleb_tilemap_redraw, NULL);
}
/******************************************************************************/
diff --git a/src/mame/video/twincobr.c b/src/mame/video/twincobr.c
index ba0862bd5a0..2a6dc0715dc 100644
--- a/src/mame/video/twincobr.c
+++ b/src/mame/video/twincobr.c
@@ -161,7 +161,7 @@ VIDEO_START( toaplan0 )
state_save_register_global(machine, twincobr_bg_ram_bank);
state_save_register_global(machine, twincobr_flip_screen);
state_save_register_global(machine, wardner_sprite_hack);
- state_save_register_postload(machine, twincobr_restore_screen, NULL);
+ machine->state().register_postload(twincobr_restore_screen, NULL);
}
static STATE_POSTLOAD( twincobr_restore_screen )
diff --git a/src/mame/video/ygv608.c b/src/mame/video/ygv608.c
index 87c441b3b78..25f1dd17f0c 100644
--- a/src/mame/video/ygv608.c
+++ b/src/mame/video/ygv608.c
@@ -492,7 +492,7 @@ static void ygv608_register_state_save(running_machine *machine)
state_save_register_item_2d_array(machine, "ygv608", NULL, 0, ygv608.scroll_data_table);
state_save_register_item_2d_array(machine, "ygv608", NULL, 0, ygv608.colour_palette);
- state_save_register_postload(machine, ygv608_postload, NULL);
+ machine->state().register_postload(ygv608_postload, NULL);
}
static void ygv608_exit(running_machine &machine)