diff --git a/src/emu/machine/x2212.c b/src/emu/machine/x2212.c index c32dde91ab6..338764786e8 100644 --- a/src/emu/machine/x2212.c +++ b/src/emu/machine/x2212.c @@ -1,156 +1,247 @@ -/* - * Xicor X2212 - * - * 256 x 4 bit Nonvolatile Static RAM - * - */ +/*************************************************************************** + + x2212.c + + Xicor X2212 256 x 4 bit Nonvolatile Static RAM. + +***************************************************************************/ #include "emu.h" #include "machine/x2212.h" -#define SIZE_DATA ( 0x100 ) -typedef struct +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +const device_type X2212 = x2212_device_config::static_alloc_device_config; + +static ADDRESS_MAP_START( x2212_map, ADDRESS_SPACE_PROGRAM, 8 ) + AM_RANGE(0x0000, 0x00ff) AM_RAM +ADDRESS_MAP_END + + + +//************************************************************************** +// DEVICE CONFIGURATION +//************************************************************************** + +//------------------------------------------------- +// x2212_device_config - constructor +//------------------------------------------------- + +x2212_device_config::x2212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) + : device_config(mconfig, static_alloc_device_config, "X2212", tag, owner, clock), + device_config_memory_interface(mconfig, *this), + device_config_nvram_interface(mconfig, *this), + m_space_config("SRAM", ENDIANNESS_BIG, 8, 8, 0, *ADDRESS_MAP_NAME(x2212_map)), + m_auto_save(false) { - UINT8 *sram; - UINT8 *e2prom; - UINT8 *default_data; - int store; - int array_recall; -} x2212_state; - -/*------------------------------------------------- - get_safe_token - makes sure that the passed - in device is, in fact, an X2212 --------------------------------------------------*/ - -INLINE x2212_state *get_safe_token(running_device *device) -{ - assert(device != NULL); - assert(device->type() == X2212); - - return (x2212_state *)downcast(device)->token(); -} - -WRITE8_DEVICE_HANDLER( x2212_write ) -{ - x2212_state *c = get_safe_token(device); - - c->sram[ offset ] = data; } -READ8_DEVICE_HANDLER( x2212_read ) -{ - x2212_state *c = get_safe_token(device); +//------------------------------------------------- +// static_alloc_device_config - allocate a new +// configuration object +//------------------------------------------------- - return c->sram[ offset ]; +device_config *x2212_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) +{ + return global_alloc(x2212_device_config(mconfig, tag, owner, clock)); } -WRITE_LINE_DEVICE_HANDLER( x2212_store ) -{ - x2212_state *c = get_safe_token(device); +//------------------------------------------------- +// alloc_device - allocate a new device object +//------------------------------------------------- + +device_t *x2212_device_config::alloc_device(running_machine &machine) const +{ + return auto_alloc(&machine, x2212_device(machine, *this)); +} + + +//------------------------------------------------- +// memory_space_config - return a description of +// any address spaces owned by this device +//------------------------------------------------- + +const address_space_config *x2212_device_config::memory_space_config(int spacenum) const +{ + return (spacenum == 0) ? &m_space_config : NULL; +} + + +//------------------------------------------------- +// static_set_auto_save - configuration helper +// to set the auto-save flag +//------------------------------------------------- + +void x2212_device_config::static_set_auto_save(device_config *device) +{ + downcast(device)->m_auto_save = true; +} + + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// x2212_device - constructor +//------------------------------------------------- + +x2212_device::x2212_device(running_machine &_machine, const x2212_device_config &config) + : device_t(_machine, config), + device_memory_interface(_machine, config, *this), + device_nvram_interface(_machine, config, *this), + m_config(config), + m_store(true), + m_array_recall(true) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void x2212_device::device_start() +{ + state_save_register_device_item_array(this, 0, m_e2prom); + state_save_register_device_item(this, 0, m_store); + state_save_register_device_item(this, 0, m_array_recall); +} + + +//------------------------------------------------- +// nvram_default - called to initialize NVRAM to +// its default state +//------------------------------------------------- + +void x2212_device::nvram_default() +{ + // default to all-0xff + memset(m_e2prom, 0xff, SIZE_DATA); + for (int byte = 0; byte < SIZE_DATA; byte++) + m_addrspace[0]->write_byte(byte, 0xff); + + // populate from a memory region if present + if (m_region != NULL) + { + if (m_region->bytes() != SIZE_DATA) + fatalerror("x2212 region '%s' wrong size (expected size = 0x100)", tag()); + if (m_region->width() != 1) + fatalerror("x2212 region '%s' needs to be an 8-bit region", tag()); + + memcpy(m_e2prom, *m_region, SIZE_DATA); + } +} + + +//------------------------------------------------- +// nvram_read - called to read NVRAM from the +// .nv file +//------------------------------------------------- + +void x2212_device::nvram_read(mame_file &file) +{ + mame_fread(&file, m_e2prom, SIZE_DATA); +} + + +//------------------------------------------------- +// nvram_write - called to write NVRAM to the +// .nv file +//------------------------------------------------- + +void x2212_device::nvram_write(mame_file &file) +{ + // auto-save causes an implicit store prior to exiting (writing) + if (m_config.m_auto_save) + store(); + mame_fwrite(&file, m_e2prom, SIZE_DATA); +} + + + +//************************************************************************** +// INTERNAL HELPERS +//************************************************************************** + +//------------------------------------------------- +// store - store data from live RAM into the +// EEPROM +//------------------------------------------------- + +void x2212_device::store() +{ + for (int byte = 0; byte < SIZE_DATA; byte++) + m_e2prom[byte] = m_addrspace[0]->read_byte(byte); +} + + +//------------------------------------------------- +// recall - fetch data from the EEPROM into live +// RAM +//------------------------------------------------- + +void x2212_device::recall() +{ + for (int byte = 0; byte < SIZE_DATA; byte++) + m_addrspace[0]->write_byte(byte, m_e2prom[byte]); +} + + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +//------------------------------------------------- +// write - store to the live RAM +//------------------------------------------------- + +WRITE8_MEMBER( x2212_device::write ) +{ + m_addrspace[0]->write_byte(offset, data & 0x0f); +} + + +//------------------------------------------------- +// read - read from the live RAM +//------------------------------------------------- + +READ8_MEMBER( x2212_device::read ) +{ + return m_addrspace[0]->read_byte(offset) & 0x0f; +} + + +//------------------------------------------------- +// store - set the state of the store line +// (active high) +//------------------------------------------------- + +WRITE_LINE_MEMBER( x2212_device::store ) +{ state &= 1; - if( !state && c->store ) - { - memcpy( c->e2prom, c->sram, SIZE_DATA ); - } - - c->store = state; + if (!state && m_store) + store(); + m_store = state; } -WRITE_LINE_DEVICE_HANDLER( x2212_array_recall ) -{ - x2212_state *c = get_safe_token(device); +//------------------------------------------------- +// recall - set the state of the recall line +// (active high) +//------------------------------------------------- + +WRITE_LINE_MEMBER( x2212_device::recall ) +{ state &= 1; - if( !state && c->array_recall ) - { - memcpy( c->sram, c->e2prom, SIZE_DATA ); - } - - c->array_recall = state; + if (!state && m_array_recall) + recall(); + m_array_recall = state; } - -/*------------------------------------------------- - device start callback --------------------------------------------------*/ - -static DEVICE_START(x2212) -{ - x2212_state *c = get_safe_token(device); - - /* validate some basic stuff */ - assert(device != NULL); - assert(device->baseconfig().static_config() == NULL); - assert(downcast(device->baseconfig()).inline_config() == NULL); - assert(device->machine != NULL); - assert(device->machine->config != NULL); - - c->sram = auto_alloc_array( device->machine, UINT8, SIZE_DATA ); - c->e2prom = auto_alloc_array( device->machine, UINT8, SIZE_DATA ); - c->store = 1; - c->array_recall = 1; - - c->default_data = *device->region(); - - state_save_register_device_item_pointer( device, 0, c->sram, SIZE_DATA ); - state_save_register_device_item_pointer( device, 0, c->e2prom, SIZE_DATA ); - state_save_register_device_item( device, 0, c->store ); - state_save_register_device_item( device, 0, c->array_recall ); -} - -/*------------------------------------------------- - device reset callback --------------------------------------------------*/ - -static DEVICE_RESET(x2212) -{ -} - -static DEVICE_NVRAM(x2212) -{ - x2212_state *c = get_safe_token(device); - - if( read_or_write ) - { - mame_fwrite( file, c->sram, SIZE_DATA ); - } - else - { - if( file ) - { - mame_fread( file, c->e2prom, SIZE_DATA ); - } - else - { - if( c->default_data != NULL ) - { - memcpy( c->e2prom, c->default_data, SIZE_DATA ); - } - else - { - memset( c->e2prom, 0xff, SIZE_DATA ); - } - } - - memcpy( c->sram, c->e2prom, SIZE_DATA ); - } -} - -/*------------------------------------------------- - device definition --------------------------------------------------*/ - -static const char DEVTEMPLATE_SOURCE[] = __FILE__; - -#define DEVTEMPLATE_ID( p, s ) p##x2212##s -#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET | DT_HAS_NVRAM -#define DEVTEMPLATE_NAME "X2212" -#define DEVTEMPLATE_FAMILY "EEPROM" -#define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL -#include "devtempl.h" - - -DEFINE_LEGACY_NVRAM_DEVICE(X2212, x2212); diff --git a/src/emu/machine/x2212.h b/src/emu/machine/x2212.h index 41940d706d8..4f8b66534f8 100644 --- a/src/emu/machine/x2212.h +++ b/src/emu/machine/x2212.h @@ -1,27 +1,114 @@ -/* - * Xicor X2212 - * - * 256 x 4 bit Nonvolatile Static RAM - * - */ +/*************************************************************************** -#if !defined( X2212_H ) -#define X2212_H ( 1 ) + x2212.h -#include "devlegcy.h" + Xicor X2212 256 x 4 bit Nonvolatile Static RAM. -/* default nvram contents should be in memory region - * with the same tag as device. - */ +***************************************************************************/ -DECLARE_LEGACY_NVRAM_DEVICE(X2212, x2212); +#pragma once + +#ifndef __X2212_H__ +#define __X2212_H__ + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** #define MDRV_X2212_ADD(_tag) \ - MDRV_DEVICE_ADD(_tag, X2212, 0) + MDRV_DEVICE_ADD(_tag, X2212, 0) \ + +// some systems (like many early Atari games) wire up the /STORE signal +// to fire on power-down, effectively creating an "auto-save" functionality +#define MDRV_X2212_ADD_AUTOSAVE(_tag) \ + MDRV_DEVICE_ADD(_tag, X2212, 0) \ + x2212_device_config::static_set_auto_save(device); \ + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + + +// ======================> x2212_device_config + +class x2212_device_config : public device_config, + public device_config_memory_interface, + public device_config_nvram_interface +{ + friend class x2212_device; + + // construction/destruction + x2212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); + +public: + // allocators + static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); + virtual device_t *alloc_device(running_machine &machine) const; + + // inline configuration helpers + static void static_set_auto_save(device_config *device); + +protected: + // device_config_memory_interface overrides + virtual const address_space_config *memory_space_config(int spacenum = 0) const; + + // device-specific configuration + address_space_config m_space_config; + + // internal state + bool m_auto_save; +}; + + +// ======================> x2212_device + +class x2212_device : public device_t, + public device_memory_interface, + public device_nvram_interface +{ + friend class x2212_device_config; + + // construction/destruction + x2212_device(running_machine &_machine, const x2212_device_config &config); + +public: + // I/O operations + DECLARE_READ8_MEMBER( read ); + DECLARE_WRITE8_MEMBER( write ); + + DECLARE_WRITE_LINE_MEMBER( store ); + DECLARE_WRITE_LINE_MEMBER( recall ); + +protected: + // internal helpers + void store(); + void recall(); + + // device-level overrides + virtual void device_start(); + + // device_nvram_interface overrides + virtual void nvram_default(); + virtual void nvram_read(mame_file &file); + virtual void nvram_write(mame_file &file); + + static const int SIZE_DATA = 0x100; + + // internal state + const x2212_device_config &m_config; + + UINT8 m_e2prom[SIZE_DATA]; + bool m_store; + bool m_array_recall; +}; + + +// device type definition +extern const device_type X2212; -WRITE8_DEVICE_HANDLER( x2212_write ); -READ8_DEVICE_HANDLER( x2212_read ); -WRITE_LINE_DEVICE_HANDLER( x2212_store ); -WRITE_LINE_DEVICE_HANDLER( x2212_array_recall ); #endif diff --git a/src/mame/drivers/ccastles.c b/src/mame/drivers/ccastles.c index 472a10baaf0..6e66d49fe4a 100644 --- a/src/mame/drivers/ccastles.c +++ b/src/mame/drivers/ccastles.c @@ -192,7 +192,6 @@ static MACHINE_START( ccastles ) rectangle visarea; /* initialize globals */ - state->maincpu = machine->device("maincpu"); state->syncprom = memory_region(machine, "proms") + 0x000; /* find the start of VBLANK in the SYNC PROM */ @@ -228,7 +227,6 @@ static MACHINE_START( ccastles ) /* setup for save states */ state_save_register_global(machine, state->irq_state); state_save_register_global_array(machine, state->nvram_store); - state_save_register_global_array(machine, state->nvram); } @@ -291,36 +289,39 @@ static READ8_HANDLER( leta_r ) * *************************************/ -static NVRAM_HANDLER( ccastles ) -{ - ccastles_state *state = machine->driver_data(); - if (read_or_write) - { - /* on power down, the EAROM is implicitly stored */ - memcpy(state->nvram, state->nvram_stage, sizeof(state->nvram)); - mame_fwrite(file, state->nvram, sizeof(state->nvram)); - } - else if (file) - mame_fread(file, state->nvram, sizeof(state->nvram)); - else - memset(state->nvram, 0, sizeof(state->nvram)); -} - - static WRITE8_HANDLER( nvram_recall_w ) { ccastles_state *state = space->machine->driver_data(); - memcpy(state->nvram_stage, state->nvram, sizeof(state->nvram)); + state->nvram_4b->recall(0); + state->nvram_4b->recall(1); + state->nvram_4b->recall(0); + state->nvram_4a->recall(0); + state->nvram_4a->recall(1); + state->nvram_4a->recall(0); } static WRITE8_HANDLER( nvram_store_w ) { ccastles_state *state = space->machine->driver_data(); - state->nvram_store[offset] = data & 1; - if (!state->nvram_store[0] && state->nvram_store[1]) - memcpy(state->nvram, state->nvram_stage, sizeof(state->nvram)); + state->nvram_4b->store(~state->nvram_store[0] & state->nvram_store[1]); + state->nvram_4a->store(~state->nvram_store[0] & state->nvram_store[1]); +} + + +static READ8_HANDLER( nvram_r ) +{ + ccastles_state *state = space->machine->driver_data(); + return state->nvram_4b->read(*space, offset) | (state->nvram_4a->read(*space, offset) << 4); +} + + +static WRITE8_HANDLER( nvram_w ) +{ + ccastles_state *state = space->machine->driver_data(); + state->nvram_4b->write(*space, offset, data); + state->nvram_4a->write(*space, offset, data >> 4); } @@ -338,7 +339,7 @@ static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x7fff) AM_RAM_WRITE(ccastles_videoram_w) AM_BASE_MEMBER(ccastles_state, videoram) AM_RANGE(0x8000, 0x8fff) AM_RAM AM_RANGE(0x8e00, 0x8fff) AM_BASE_MEMBER(ccastles_state, spriteram) - AM_RANGE(0x9000, 0x90ff) AM_MIRROR(0x0300) AM_RAM AM_SHARE("nvram") + AM_RANGE(0x9000, 0x90ff) AM_MIRROR(0x0300) AM_READWRITE(nvram_r, nvram_w) AM_RANGE(0x9400, 0x9403) AM_MIRROR(0x01fc) AM_READ(leta_r) AM_RANGE(0x9600, 0x97ff) AM_READ_PORT("IN0") AM_RANGE(0x9800, 0x980f) AM_MIRROR(0x01f0) AM_DEVREADWRITE("pokey1", pokey_r, pokey_w) @@ -485,9 +486,11 @@ static MACHINE_CONFIG_START( ccastles, ccastles_state ) MDRV_MACHINE_START(ccastles) MDRV_MACHINE_RESET(ccastles) - MDRV_NVRAM_HANDLER(ccastles) MDRV_WATCHDOG_VBLANK_INIT(8) + MDRV_X2212_ADD_AUTOSAVE("nvram_4b") + MDRV_X2212_ADD_AUTOSAVE("nvram_4a") + /* video hardware */ MDRV_GFXDECODE(ccastles) MDRV_PALETTE_LENGTH(32) diff --git a/src/mame/drivers/cloud9.c b/src/mame/drivers/cloud9.c index a81679fa003..e1fc3ec6806 100644 --- a/src/mame/drivers/cloud9.c +++ b/src/mame/drivers/cloud9.c @@ -161,7 +161,6 @@ static MACHINE_START( cloud9 ) rectangle visarea; /* initialize globals */ - state->maincpu = machine->device("maincpu"); state->syncprom = memory_region(machine, "proms") + 0x000; /* find the start of VBLANK in the SYNC PROM */ @@ -193,7 +192,6 @@ static MACHINE_START( cloud9 ) /* setup for save states */ state_save_register_global(machine, state->irq_state); - state_save_register_global_array(machine, state->nvram); } @@ -248,41 +246,21 @@ static READ8_HANDLER( leta_r ) * *************************************/ -static NVRAM_HANDLER( cloud9 ) -{ - cloud9_state *state = machine->driver_data(); - if (read_or_write) - { - /* on power down, the EAROM is implicitly stored */ - memcpy(state->nvram, state->nvram_stage, sizeof(state->nvram)); - mame_fwrite(file, state->nvram, sizeof(state->nvram)); - } - else if (file) - mame_fread(file, state->nvram, sizeof(state->nvram)); - else - memset(state->nvram, 0, sizeof(state->nvram)); -} - - static WRITE8_HANDLER( nvram_recall_w ) { cloud9_state *state = space->machine->driver_data(); - memcpy(state->nvram_stage, state->nvram, sizeof(state->nvram)); + state->nvram->recall(0); + state->nvram->recall(1); + state->nvram->recall(0); } static WRITE8_HANDLER( nvram_store_w ) { cloud9_state *state = space->machine->driver_data(); - memcpy(state->nvram, state->nvram_stage, sizeof(state->nvram)); -} - - -static READ8_HANDLER( nvram_r ) -{ - /* only a single XD2212 for 4 bits of NVRAM */ - cloud9_state *state = space->machine->driver_data(); - return state->nvram_stage[offset] | 0xf0; + state->nvram->store(0); + state->nvram->store(1); + state->nvram->store(0); } @@ -311,7 +289,7 @@ static ADDRESS_MAP_START( cloud9_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x5900, 0x5903) AM_MIRROR(0x007c) AM_READ(leta_r) AM_RANGE(0x5a00, 0x5a0f) AM_MIRROR(0x00f0) AM_DEVREADWRITE("pokey1", pokey_r, pokey_w) AM_RANGE(0x5b00, 0x5b0f) AM_MIRROR(0x00f0) AM_DEVREADWRITE("pokey2", pokey_r, pokey_w) - AM_RANGE(0x5c00, 0x5cff) AM_MIRROR(0x0300) AM_RAM_READ(nvram_r) AM_SHARE("nvram") + AM_RANGE(0x5c00, 0x5cff) AM_MIRROR(0x0300) AM_DEVREADWRITE_MODERN("nvram", x2212_device, read, write) AM_RANGE(0x6000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -456,8 +434,9 @@ static MACHINE_CONFIG_START( cloud9, cloud9_state ) MDRV_MACHINE_START(cloud9) MDRV_MACHINE_RESET(cloud9) - MDRV_NVRAM_HANDLER(cloud9) MDRV_WATCHDOG_VBLANK_INIT(8) + + MDRV_X2212_ADD_AUTOSAVE("nvram") /* video hardware */ MDRV_GFXDECODE(cloud9) diff --git a/src/mame/drivers/firefox.c b/src/mame/drivers/firefox.c index 8e22606e91c..0663fa5337d 100644 --- a/src/mame/drivers/firefox.c +++ b/src/mame/drivers/firefox.c @@ -125,8 +125,8 @@ static WRITE8_HANDLER( firefox_disc_data_w ) static unsigned char *tileram; static unsigned char *tile_palette; static unsigned char *sprite_palette; -static running_device *nvram_1c; -static running_device *nvram_1d; +static x2212_device *nvram_1c; +static x2212_device *nvram_1d; static tilemap_t *bgtiles; static int control_num; @@ -351,25 +351,25 @@ static WRITE8_HANDLER( adc_select_w ) static WRITE8_HANDLER( nvram_w ) { - x2212_write( nvram_1c, offset, data >> 4 ); - x2212_write( nvram_1d, offset, data & 0xf ); + nvram_1c->write(*space, offset, data >> 4); + nvram_1d->write(*space, offset, data & 0xf); } static READ8_HANDLER( nvram_r ) { - return ( x2212_read( nvram_1c, offset ) << 4 ) | x2212_read( nvram_1d, offset ); + return (nvram_1c->read(*space, offset) << 4) | nvram_1d->read(*space, offset); } static WRITE8_HANDLER( novram_recall_w ) { - x2212_array_recall( nvram_1c, ( data >> 7 ) & 1 ); - x2212_array_recall( nvram_1d, ( data >> 7 ) & 1 ); + nvram_1c->recall((data >> 7) & 1); + nvram_1d->recall((data >> 7) & 1); } static WRITE8_HANDLER( novram_store_w ) { - x2212_store( nvram_1c, ( data >> 7 ) & 1 ); - x2212_store( nvram_1d, ( data >> 7 ) & 1 ); + nvram_1c->store((data >> 7) & 1); + nvram_1d->store((data >> 7) & 1); } @@ -430,8 +430,8 @@ static void firq_gen(running_device *device, int state) static MACHINE_START( firefox ) { memory_configure_bank(machine, "bank1", 0, 32, memory_region(machine, "maincpu") + 0x10000, 0x1000); - nvram_1c = machine->device("nvram_1c"); - nvram_1d = machine->device("nvram_1d"); + nvram_1c = machine->device("nvram_1c"); + nvram_1d = machine->device("nvram_1d"); laserdisc = machine->device("laserdisc"); vp931_set_data_ready_callback(laserdisc, firq_gen); @@ -669,8 +669,8 @@ static MACHINE_CONFIG_START( firefox, driver_device ) MDRV_LASERDISC_OVERLAY(firefox, 64*8, 525, BITMAP_FORMAT_RGB32) MDRV_LASERDISC_OVERLAY_CLIP(7*8, 53*8-1, 44, 480+44) - MDRV_X2212_ADD("nvram_1c") - MDRV_X2212_ADD("nvram_1d") + MDRV_X2212_ADD_AUTOSAVE("nvram_1c") + MDRV_X2212_ADD_AUTOSAVE("nvram_1d") MDRV_RIOT6532_ADD("riot", MASTER_XTAL/8, riot_intf) /* sound hardware */ diff --git a/src/mame/drivers/starwars.c b/src/mame/drivers/starwars.c index 1ffc7d9ad53..7be07bdc197 100644 --- a/src/mame/drivers/starwars.c +++ b/src/mame/drivers/starwars.c @@ -168,13 +168,13 @@ static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x4380, 0x439f) AM_READ(starwars_adc_r) /* a-d control result */ AM_RANGE(0x4400, 0x4400) AM_READWRITE(starwars_main_read_r, starwars_main_wr_w) AM_RANGE(0x4401, 0x4401) AM_READ(starwars_main_ready_flag_r) - AM_RANGE(0x4500, 0x45ff) AM_DEVREADWRITE("x2212", x2212_read, x2212_write) + AM_RANGE(0x4500, 0x45ff) AM_DEVREADWRITE_MODERN("x2212", x2212_device, read, write) AM_RANGE(0x4600, 0x461f) AM_WRITE(avgdvg_go_w) AM_RANGE(0x4620, 0x463f) AM_WRITE(avgdvg_reset_w) AM_RANGE(0x4640, 0x465f) AM_WRITE(watchdog_reset_w) AM_RANGE(0x4660, 0x467f) AM_WRITE(irq_ack_w) AM_RANGE(0x4680, 0x469f) AM_READNOP AM_WRITE(starwars_out_w) - AM_RANGE(0x46a0, 0x46bf) AM_DEVWRITE("x2212", starwars_nstore_w) + AM_RANGE(0x46a0, 0x46bf) AM_WRITE(starwars_nstore_w) AM_RANGE(0x46c0, 0x46c2) AM_WRITE(starwars_adc_select_w) AM_RANGE(0x46e0, 0x46e0) AM_WRITE(starwars_soundrst_w) AM_RANGE(0x4700, 0x4707) AM_WRITE(starwars_math_w) @@ -217,9 +217,6 @@ ADDRESS_MAP_END * *************************************/ - - - static INPUT_PORTS_START( starwars ) PORT_START("IN0") PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN2 ) @@ -339,7 +336,7 @@ static MACHINE_CONFIG_START( starwars, driver_device ) MDRV_RIOT6532_ADD("riot", MASTER_CLOCK / 8, starwars_riot6532_intf) - MDRV_X2212_ADD("x2212") /* nvram */ + MDRV_X2212_ADD_AUTOSAVE("x2212") /* nvram */ /* video hardware */ MDRV_SCREEN_ADD("screen", VECTOR) diff --git a/src/mame/includes/ccastles.h b/src/mame/includes/ccastles.h index d3e24b0158b..5d8ee1284e7 100644 --- a/src/mame/includes/ccastles.h +++ b/src/mame/includes/ccastles.h @@ -4,18 +4,21 @@ *************************************************************************/ +#include "cpu/m6502/m6502.h" +#include "machine/x2212.h" + class ccastles_state : public driver_device { public: ccastles_state(running_machine &machine, const driver_device_config_base &config) : driver_device(machine, config), - nvram_stage(*this, "nvram") { } + maincpu(*this, "maincpu"), + nvram_4b(*this, "nvram_4b"), + nvram_4a(*this, "nvram_4a") { } /* memory pointers */ UINT8 * videoram; UINT8 * spriteram; - required_shared_ptr nvram_stage; - UINT8 nvram[0x100]; /* video-related */ const UINT8 *syncprom; @@ -36,7 +39,9 @@ public: UINT8 nvram_store[2]; /* devices */ - running_device *maincpu; + required_device maincpu; + required_device nvram_4b; + required_device nvram_4a; }; diff --git a/src/mame/includes/cloud9.h b/src/mame/includes/cloud9.h index 3cd2eb54c19..353a727a86e 100644 --- a/src/mame/includes/cloud9.h +++ b/src/mame/includes/cloud9.h @@ -4,19 +4,21 @@ *************************************************************************/ +#include "cpu/m6502/m6502.h" +#include "machine/x2212.h" + class cloud9_state : public driver_device { public: cloud9_state(running_machine &machine, const driver_device_config_base &config) : driver_device(machine, config), - nvram_stage(*this, "nvram") { } + maincpu(*this, "maincpu"), + nvram(*this, "nvram") { } /* memory pointers */ UINT8 * videoram; UINT8 * spriteram; UINT8 * paletteram; - required_shared_ptr nvram_stage; // currently this uses generic nvram handlers - UINT8 nvram[0x100]; // currently this uses generic nvram handlers /* video-related */ const UINT8 *syncprom; @@ -34,7 +36,8 @@ public: UINT8 irq_state; /* devices */ - running_device *maincpu; + required_device maincpu; + required_device nvram; }; diff --git a/src/mame/includes/starwars.h b/src/mame/includes/starwars.h index f3e826cec6b..e2e800046dd 100644 --- a/src/mame/includes/starwars.h +++ b/src/mame/includes/starwars.h @@ -16,7 +16,7 @@ extern UINT8 starwars_is_esb; extern UINT8 *starwars_mathram; -WRITE8_DEVICE_HANDLER( starwars_nstore_w ); +WRITE8_HANDLER( starwars_nstore_w ); WRITE8_HANDLER( starwars_out_w ); CUSTOM_INPUT( matrix_flag_r ); diff --git a/src/mame/machine/starwars.c b/src/mame/machine/starwars.c index 53bfd3df563..b47bf9f1801 100644 --- a/src/mame/machine/starwars.c +++ b/src/mame/machine/starwars.c @@ -68,9 +68,10 @@ static TIMER_CALLBACK( math_run_clear ) * *************************************/ -WRITE8_DEVICE_HANDLER( starwars_nstore_w ) +WRITE8_HANDLER( starwars_nstore_w ) { - x2212_store(device, data & 0x01); + space->machine->device("x2212")->store(1); + space->machine->device("x2212")->store(0); } /************************************* @@ -112,7 +113,7 @@ WRITE8_HANDLER( starwars_out_w ) break; case 7: /* NVRAM array recall */ - x2212_array_recall(space->machine->device("x2212"), data >> 7); + space->machine->device("x2212")->recall((~data >> 7) & 1); break; } }