Exposed an address space for EEPROM devices. This has several

side-effects:
 - EEPROM memory is now visible in the debugger
 - EEPROM memory can be accessed like any CPU/device memory
    (i.e., use eeprom.b@<addr> instead of eeprom.eb@<addr>)

Removed support in the expression engine for EEPROM-specific
accesses.

Updated all systems that muck directly with EEPROM memory to
use memory accessors instead on the EEPROM address space.

Extended the devtempl.h file to support device address spaces.

Cleaned up romload a bit to make it clear that region flags are
enforced for any device with an address space, not just CPUs.
This commit is contained in:
Aaron Giles 2009-12-28 18:04:50 +00:00
parent 34f4656cca
commit f5730e89ef
10 changed files with 166 additions and 208 deletions

View File

@ -25,7 +25,6 @@
#include "debugvw.h"
#include "debugger.h"
#include "uiinput.h"
#include "machine/eeprom.h"
#include <ctype.h>
@ -101,11 +100,9 @@ static UINT32 dasm_wrapped(const device_config *device, char *buffer, offs_t pc)
static UINT64 expression_read_memory(void *param, const char *name, int space, UINT32 address, int size);
static UINT64 expression_read_program_direct(const address_space *space, int opcode, offs_t address, int size);
static UINT64 expression_read_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size);
static UINT64 expression_read_eeprom(const device_config *device, offs_t address, int size);
static void expression_write_memory(void *param, const char *name, int space, UINT32 address, int size, UINT64 data);
static void expression_write_program_direct(const address_space *space, int opcode, offs_t address, int size, UINT64 data);
static void expression_write_memory_region(running_machine *machine, const char *rgntag, offs_t address, int size, UINT64 data);
static void expression_write_eeprom(const device_config *device, offs_t address, int size, UINT64 data);
static EXPRERR expression_validate(void *param, const char *name, int space);
/* variable getters/setters */
@ -2503,13 +2500,6 @@ static UINT64 expression_read_memory(void *param, const char *name, int spacenum
result = expression_read_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size);
break;
case EXPSPACE_EEPROM:
if (name != NULL)
device = expression_get_device(machine, name);
if (device != NULL)
result = expression_read_eeprom(device, address, size);
break;
case EXPSPACE_REGION:
if (name == NULL)
break;
@ -2631,31 +2621,6 @@ static UINT64 expression_read_memory_region(running_machine *machine, const char
}
/*-------------------------------------------------
expression_read_eeprom - read EEPROM data
-------------------------------------------------*/
static UINT64 expression_read_eeprom(const device_config *device, offs_t address, int size)
{
UINT64 result = ~(UINT64)0 >> (64 - 8*size);
UINT32 eelength, eesize;
void *base;
/* make sure we get a valid base before proceeding */
base = eeprom_get_data_pointer(device, &eelength, &eesize);
if (base != NULL && address < eelength)
{
/* switch off the size */
switch (eesize)
{
case 1: result &= ((UINT8 *)base)[address]; break;
case 2: result &= BIG_ENDIANIZE_INT16(((UINT16 *)base)[address]); break;
}
}
return result;
}
/*-------------------------------------------------
expression_write_memory - write 1,2,4 or 8
bytes at the given offset in the given address
@ -2705,13 +2670,6 @@ static void expression_write_memory(void *param, const char *name, int spacenum,
expression_write_program_direct(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), (spacenum == EXPSPACE_OPCODE), address, size, data);
break;
case EXPSPACE_EEPROM:
if (name != NULL)
device = expression_get_device(machine, name);
if (device != NULL)
expression_write_eeprom(device, address, size, data);
break;
case EXPSPACE_REGION:
if (name == NULL)
break;
@ -2845,45 +2803,6 @@ static void expression_write_memory_region(running_machine *machine, const char
}
/*-------------------------------------------------
expression_write_eeprom - write EEPROM data
-------------------------------------------------*/
static void expression_write_eeprom(const device_config *device, offs_t address, int size, UINT64 data)
{
debugcpu_private *global = device->machine->debugcpu_data;
UINT32 eelength, eesize;
void *vbase = eeprom_get_data_pointer(device, &eelength, &eesize);
/* make sure we get a valid base before proceeding */
if (vbase != NULL && address < eelength)
{
UINT64 mask = ~(UINT64)0 >> (64 - 8*size);
/* switch off the size */
switch (eesize)
{
case 1:
{
UINT8 *base = (UINT8 *)vbase + address;
*base = (*base & ~mask) | (data & mask);
break;
}
case 2:
{
UINT16 *base = (UINT16 *)vbase + address;
UINT16 value = BIG_ENDIANIZE_INT16(*base);
value = (value & ~mask) | (data & mask);
*base = BIG_ENDIANIZE_INT16(value);
break;
}
}
global->memory_modified = TRUE;
}
}
/*-------------------------------------------------
expression_validate - validate that the
provided expression references an
@ -2943,15 +2862,6 @@ static EXPRERR expression_validate(void *param, const char *name, int space)
return EXPRERR_NO_SUCH_MEMORY_SPACE;
break;
case EXPSPACE_EEPROM:
if (name != NULL)
{
device = expression_get_device(machine, name);
if (device != NULL)
break;
}
return EXPRERR_INVALID_MEMORY_NAME;
case EXPSPACE_REGION:
if (name == NULL)
return EXPRERR_MISSING_MEMORY_NAME;

View File

@ -91,7 +91,6 @@ enum
TIN_MEMORY_SPACE3_PHYS = (EXPSPACE_SPACE3_PHYSICAL << TIN_MEMORY_SPACE_SHIFT),
TIN_MEMORY_OPCODE = (EXPSPACE_OPCODE << TIN_MEMORY_SPACE_SHIFT),
TIN_MEMORY_RAMWRITE = (EXPSPACE_RAMWRITE << TIN_MEMORY_SPACE_SHIFT),
TIN_MEMORY_EEPROM = (EXPSPACE_EEPROM << TIN_MEMORY_SPACE_SHIFT),
TIN_MEMORY_REGION = (EXPSPACE_REGION << TIN_MEMORY_SPACE_SHIFT),
TIN_MEMORY_INDEX_SHIFT = 16,
@ -586,7 +585,6 @@ static EXPRERR parse_memory_operator(parsed_expression *expr, int offset, const
case '3': *flags |= physical ? TIN_MEMORY_SPACE3_PHYS : TIN_MEMORY_SPACE3_LOG; break;
case 'o': *flags |= TIN_MEMORY_OPCODE; break;
case 'r': *flags |= TIN_MEMORY_RAMWRITE; break;
case 'e': *flags |= TIN_MEMORY_EEPROM; break;
case 'm': *flags |= TIN_MEMORY_REGION; break;
default: return MAKE_EXPRERR_INVALID_MEMORY_SPACE(offset + (buffer - startbuffer));
}

View File

@ -57,8 +57,7 @@
#define EXPSPACE_SPACE3_PHYSICAL (7)
#define EXPSPACE_OPCODE (8)
#define EXPSPACE_RAMWRITE (9)
#define EXPSPACE_EEPROM (10)
#define EXPSPACE_REGION (11)
#define EXPSPACE_REGION (10)

View File

@ -57,10 +57,6 @@ static const char DEVTEMPLATE_SOURCE[] = __FILE__;
DEVTEMPLATE_CREDITS - optional - the device's credit string (default
is "Copyright Nicola Salmoria and the MAME Team")
DEVTEMPLATE_INLINE_CONFIG - optional - the name of the device's
inline configuration structure; by default, it is assumed the
device does not have any inline configuration
***************************************************************************/
@ -79,6 +75,9 @@ static const char DEVTEMPLATE_SOURCE[] = __FILE__;
#define DT_HAS_MACHINE_CONFIG 0x0100
#define DT_HAS_INLINE_CONFIG 0x0200
#define DT_HAS_CONTRACT_LIST 0x0400
#define DT_HAS_PROGRAM_SPACE 0x1000
#define DT_HAS_DATA_SPACE 0x2000
#define DT_HAS_IO_SPACE 0x4000
/* verify core stuff is specified */
@ -90,7 +89,7 @@ static const char DEVTEMPLATE_SOURCE[] = __FILE__;
#error DEVTEMPLATE_FEATURES must be specified!
#endif
#if ((DEVTEMPLATE_FEATURES & DT_HAS_START) == 0)
#if (((DEVTEMPLATE_FEATURES) & DT_HAS_START) == 0)
#error Device start routine is required!
#endif
@ -102,6 +101,12 @@ static const char DEVTEMPLATE_SOURCE[] = __FILE__;
#error DEVTEMPLATE_FAMILY must be specified!
#endif
#if (((DEVTEMPLATE_FEATURES) & (DT_HAS_PROGRAM_SPACE | DT_HAS_DATA_SPACE | DT_HAS_IO_SPACE)) != 0)
#ifndef DEVTEMPLATE_ENDIANNESS
#error DEVTEMPLATE_ENDIANNESS must be specified if an address space is present!
#endif
#endif
#ifdef DEVTEMPLATE_DERIVED_FEATURES
#ifndef DEVTEMPLATE_DERIVED_NAME
#error DEVTEMPLATE_DERIVED_NAME must be specified!
@ -164,6 +169,30 @@ DEVICE_GET_INFO( DEVTEMPLATE_ID(,) )
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(DEVTEMPLATE_ID(,_config)); break;
#endif
case DEVINFO_INT_CLASS: info->i = DEVTEMPLATE_CLASS; break;
#ifdef DEVTEMPLATE_ENDIANNESS
case DEVINFO_INT_ENDIANNESS: info->i = DEVTEMPLATE_ENDIANNESS; break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_0: info->i = DEVTEMPLATE_PGM_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = DEVTEMPLATE_PGM_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_PGM_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = DEVTEMPLATE_PGM_ADDRSHIFT; break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_1: info->i = DEVTEMPLATE_DATA_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_1: info->i = DEVTEMPLATE_DATA_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_DATA_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_1: info->i = DEVTEMPLATE_DATA_ADDRSHIFT; break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_2: info->i = DEVTEMPLATE_IO_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_2: info->i = DEVTEMPLATE_IO_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_IO_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_2: info->i = DEVTEMPLATE_IO_ADDRSHIFT; break;
#endif
#endif
/* --- the following bits of info are returned as pointers --- */
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_ROM_REGION)
@ -175,6 +204,31 @@ DEVICE_GET_INFO( DEVTEMPLATE_ID(,) )
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_CONTRACT_LIST)
case DEVINFO_PTR_CONTRACT_LIST: info->contract_list = DEVTEMPLATE_ID1(DEVICE_CONTRACT_LIST_NAME()); break;
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_PROGRAM_SPACE)
#ifdef DEVTEMPLATE_PGM_INTMAP
case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_PGM_INTMAP; break;
#endif
#ifdef DEVTEMPLATE_PGM_DEFMAP
case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_PGM_DEFMAP; break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_DATA_SPACE)
#ifdef DEVTEMPLATE_DATA_INTMAP
case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_DATA_INTMAP; break;
#endif
#ifdef DEVTEMPLATE_DATA_DEFMAP
case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_DATA_DEFMAP; break;
#endif
#endif
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_IO_SPACE)
#ifdef DEVTEMPLATE_IO_INTMAP
case DEVINFO_PTR_INTERNAL_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_IO_INTMAP; break;
#endif
#ifdef DEVTEMPLATE_IO_DEFMAP
case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0: info->p = (void *)DEVTEMPLATE_IO_DEFMAP; break;
#endif
#endif
/* --- the following bits of info are returned as pointers to data or functions --- */
#if ((DEVTEMPLATE_FEATURES) & DT_HAS_START)
@ -240,6 +294,29 @@ DEVICE_GET_INFO( DEVTEMPLATE_DERIVED_ID(,) )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_PROGRAM_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_0: info->i = DEVTEMPLATE_DERIVED_PGM_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = DEVTEMPLATE_DERIVED_PGM_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_PGM_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = DEVTEMPLATE_DERIVED_PGM_ADDRSHIFT; break;
#endif
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_DATA_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_1: info->i = DEVTEMPLATE_DERIVED_DATA_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_1: info->i = DEVTEMPLATE_DERIVED_DATA_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_DATA_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_1: info->i = DEVTEMPLATE_DERIVED_DATA_ADDRSHIFT; break;
#endif
#endif
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_IO_SPACE)
case DEVINFO_INT_DATABUS_WIDTH_2: info->i = DEVTEMPLATE_DERIVED_IO_DATAWIDTH; break;
case DEVINFO_INT_ADDRBUS_WIDTH_2: info->i = DEVTEMPLATE_DERIVED_IO_ADDRWIDTH; break;
#ifdef DEVTEMPLATE_IO_ADDRSHIFT
case DEVINFO_INT_ADDRBUS_SHIFT_2: info->i = DEVTEMPLATE_DERIVED_IO_ADDRSHIFT; break;
#endif
#endif
/* --- the following bits of info are returned as pointers --- */
#if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_ROM_REGION)
case DEVINFO_PTR_ROM_REGION: info->romregion = DEVTEMPLATE_DERIVED_ID1(ROM_NAME()); break;
@ -292,6 +369,11 @@ DEVICE_GET_INFO( DEVTEMPLATE_DERIVED_ID(,) )
#undef DT_HAS_CUSTOM_CONFIG
#undef DT_HAS_ROM_REGION
#undef DT_HAS_MACHINE_CONFIG
#undef DT_HAS_INLINE_CONFIG
#undef DT_HAS_CONTRACT_LIST
#undef DT_HAS_PROGRAM_SPACE
#undef DT_HAS_DATA_SPACE
#undef DT_HAS_IO_SPACE
#undef DEVTEMPLATE_DERIVED_ID
#undef DEVTEMPLATE_DERIVED_FEATURES

View File

@ -10,7 +10,6 @@
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
#define SERIAL_BUFFER_LENGTH 40
#define MEMORY_SIZE 1024
typedef struct _eeprom_state eeprom_state;
struct _eeprom_state
@ -18,7 +17,6 @@ struct _eeprom_state
const eeprom_interface *intf;
int serial_count;
UINT8 serial_buffer[SERIAL_BUFFER_LENGTH];
UINT8 data[MEMORY_SIZE];
int data_bits;
int read_address;
int clock_count;
@ -127,8 +125,10 @@ const eeprom_interface eeprom_interface_93C66B =
// "*10010xxxxxx", /* erase all */
};
static void eeprom_write(eeprom_state *eestate, int bit)
static void eeprom_write(const device_config *device, int bit)
{
eeprom_state *eestate = get_safe_token(device);
LOG(("EEPROM write bit %d\n",bit));
if (eestate->serial_count >= SERIAL_BUFFER_LENGTH-1)
@ -152,9 +152,9 @@ static void eeprom_write(eeprom_state *eestate, int bit)
if (eestate->serial_buffer[i] == '1') address |= 1;
}
if (eestate->intf->data_bits == 16)
eestate->data_bits = (eestate->data[2*address+0] << 8) + eestate->data[2*address+1];
eestate->data_bits = memory_read_word(device->space[0], address * 2);
else
eestate->data_bits = eestate->data[address];
eestate->data_bits = memory_read_byte(device->space[0], address);
eestate->read_address = address;
eestate->clock_count = 0;
eestate->sending = 1;
@ -176,12 +176,9 @@ logerror("EEPROM erase address %02x\n",address);
if (eestate->locked == 0)
{
if (eestate->intf->data_bits == 16)
{
eestate->data[2*address+0] = 0x00;
eestate->data[2*address+1] = 0x00;
}
memory_write_word(device->space[0], address * 2, 0x0000);
else
eestate->data[address] = 0x00;
memory_write_byte(device->space[0], address, 0x00);
}
else
logerror("Error: EEPROM is locked\n");
@ -208,12 +205,9 @@ logerror("EEPROM write %04x to address %02x\n",data,address);
if (eestate->locked == 0)
{
if (eestate->intf->data_bits == 16)
{
eestate->data[2*address+0] = data >> 8;
eestate->data[2*address+1] = data & 0xff;
}
memory_write_word(device->space[0], address * 2, data);
else
eestate->data[address] = data;
memory_write_byte(device->space[0], address, 0x00);
}
else
logerror("Error: EEPROM is locked\n");
@ -302,9 +296,9 @@ WRITE_LINE_DEVICE_HANDLER( eeprom_set_clock_line )
{
eestate->read_address = (eestate->read_address + 1) & ((1 << eestate->intf->address_bits) - 1);
if (eestate->intf->data_bits == 16)
eestate->data_bits = (eestate->data[2*eestate->read_address+0] << 8) + eestate->data[2*eestate->read_address+1];
eestate->data_bits = memory_read_word(device->space[0], eestate->read_address * 2);
else
eestate->data_bits = eestate->data[eestate->read_address];
eestate->data_bits = memory_read_byte(device->space[0], eestate->read_address);
eestate->clock_count = 0;
logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,eestate->read_address);
}
@ -312,7 +306,7 @@ logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,eestate->read
eestate->clock_count++;
}
else
eeprom_write(eestate,eestate->latch);
eeprom_write(device,eestate->latch);
}
}
@ -320,44 +314,29 @@ logerror("EEPROM read %04x from address %02x\n",eestate->data_bits,eestate->read
}
void eeprom_set_data(const device_config *device, const UINT8 *data, int length)
{
eeprom_state *eestate = get_safe_token(device);
assert(length <= ((1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8));
memcpy(eestate->data, data, length);
/* temporary: write data to eeprom.bin when this happens so we capture it
for adding to a region */
{
char filename[40];
FILE *f;
sprintf(filename, "eeprom-%s.bin", device->machine->gamedrv->name);
f = fopen(filename, "wb");
fwrite(eestate->data, 1, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8, f);
fclose(f);
}
}
void *eeprom_get_data_pointer(const device_config *device, UINT32 *length, UINT32 *size)
{
eeprom_state *eestate = get_safe_token(device);
if (length != NULL && eestate->intf != NULL)
*length = 1 << eestate->intf->address_bits;
if (size != NULL && eestate->intf != NULL)
*size = eestate->intf->data_bits / 8;
return eestate->data;
}
static DEVICE_NVRAM( eeprom )
{
eeprom_state *eestate = get_safe_token(device);
UINT32 eeprom_length = 1 << eestate->intf->address_bits;
UINT32 eeprom_bytes = eeprom_length * eestate->intf->data_bits / 8;
UINT32 offs;
if (read_or_write)
mame_fwrite(file, eestate->data, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8);
{
UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes);
for (offs = 0; offs < eeprom_bytes; offs++)
buffer[offs] = memory_read_byte(device->space[0], offs);
mame_fwrite(file, buffer, eeprom_bytes);
free(buffer);
}
else if (file != NULL)
mame_fread(file, eestate->data, (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8);
{
UINT8 *buffer = alloc_array_or_die(UINT8, eeprom_bytes);
mame_fread(file, buffer, eeprom_bytes);
for (offs = 0; offs < eeprom_bytes; offs++)
memory_write_byte(device->space[0], offs, buffer[offs]);
free(buffer);
}
else
{
const eeprom_config *config = (const eeprom_config *)device->inline_config;
@ -367,49 +346,39 @@ static DEVICE_NVRAM( eeprom )
/* initialize to the default value */
if (config->default_value != 0)
default_value = config->default_value;
for (offs = 0; offs < (1 << eestate->intf->address_bits); offs++)
for (offs = 0; offs < eeprom_length; offs++)
if (eestate->intf->data_bits == 8)
eestate->data[offs] = (UINT8)default_value;
memory_write_byte(device->space[0], offs, default_value);
else
{
eestate->data[offs * 2 + 0] = default_value >> 8;
eestate->data[offs * 2 + 1] = default_value & 0xff;
}
memory_write_word(device->space[0], offs * 2, default_value);
/* handle hard-coded data from the driver */
if (config->default_data != NULL)
memcpy(eestate->data, config->default_data, config->default_data_size);
for (offs = 0; offs < config->default_data_size; offs++)
memory_write_byte(device->space[0], offs, config->default_data[offs]);
/* populate from a memory region if present */
if (device->region != NULL)
{
UINT32 eeprom_length = (1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8;
UINT32 region_flags = memory_region_flags(device->machine, device->tag);
if (device->regionbytes != eeprom_length)
fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)", device->tag, eeprom_length);
if (device->regionbytes != eeprom_bytes)
fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)", device->tag, eeprom_bytes);
if (eestate->intf->data_bits == 8 && (region_flags & ROMREGION_WIDTHMASK) != ROMREGION_8BIT)
fatalerror("eeprom region '%s' needs to be an 8-bit region", device->tag);
if (eestate->intf->data_bits == 16 && ((region_flags & ROMREGION_WIDTHMASK) != ROMREGION_16BIT || (region_flags & ROMREGION_ENDIANMASK) != ROMREGION_BE))
fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region (flags=%08x)", device->tag, region_flags);
if (eestate->intf->data_bits == 8)
memcpy(eestate->data, device->region, eeprom_length);
else
{
int offs;
for (offs = 0; offs < eeprom_length; offs += 2)
{
UINT16 data = *(UINT16 *)&device->region[offs];
eestate->data[offs + 0] = data >> 8;
eestate->data[offs + 1] = data & 0xff;
}
}
for (offs = 0; offs < eeprom_length; offs++)
if (eestate->intf->data_bits == 8)
memory_write_byte(device->space[0], offs, device->region[offs]);
else
memory_write_word(device->space[0], offs * 2, ((UINT16 *)device->region)[offs]);
}
}
}
static DEVICE_START(eeprom)
static DEVICE_START( eeprom )
{
eeprom_state *eestate = get_safe_token(device);
const eeprom_config *config;
@ -424,9 +393,6 @@ static DEVICE_START(eeprom)
eestate->intf = config->pinterface;
if ((1 << eestate->intf->address_bits) * eestate->intf->data_bits / 8 > MEMORY_SIZE)
fatalerror("EEPROM larger than eepromdev.c allows");
eestate->serial_count = 0;
eestate->latch = 0;
eestate->reset_line = ASSERT_LINE;
@ -436,7 +402,6 @@ static DEVICE_START(eeprom)
if (eestate->intf->cmd_unlock) eestate->locked = 1;
else eestate->locked = 0;
state_save_register_device_item_pointer( device, 0, eestate->data, MEMORY_SIZE);
state_save_register_device_item_pointer( device, 0, eestate->serial_buffer, SERIAL_BUFFER_LENGTH);
state_save_register_device_item( device, 0, eestate->clock_line);
state_save_register_device_item( device, 0, eestate->reset_line);
@ -449,10 +414,23 @@ static DEVICE_START(eeprom)
state_save_register_device_item( device, 0, eestate->read_address);
}
static ADDRESS_MAP_START( eeprom_map8, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x0fff) AM_RAM
ADDRESS_MAP_END
static ADDRESS_MAP_START( eeprom_map16, ADDRESS_SPACE_PROGRAM, 16 )
AM_RANGE(0x0000, 0x07ff) AM_RAM
ADDRESS_MAP_END
static const char DEVTEMPLATE_SOURCE[] = __FILE__;
#define DEVTEMPLATE_ID(p,s) p##eeprom##s
#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_NVRAM | DT_HAS_INLINE_CONFIG
#define DEVTEMPLATE_NAME "EEPROM"
#define DEVTEMPLATE_FAMILY "EEPROM"
#define DEVTEMPLATE_ID(p,s) p##eeprom##s
#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_NVRAM | DT_HAS_INLINE_CONFIG | DT_HAS_PROGRAM_SPACE
#define DEVTEMPLATE_NAME "EEPROM"
#define DEVTEMPLATE_FAMILY "EEPROM"
#define DEVTEMPLATE_ENDIANNESS ENDIANNESS_BIG
#define DEVTEMPLATE_PGM_DATAWIDTH (((const eeprom_config *)device->inline_config)->pinterface->data_bits)
#define DEVTEMPLATE_PGM_ADDRWIDTH (((const eeprom_config *)device->inline_config)->pinterface->address_bits)
#define DEVTEMPLATE_PGM_ADDRSHIFT (((const eeprom_config *)device->inline_config)->pinterface->data_bits == 8 ? 0 : -1)
#define DEVTEMPLATE_PGM_DEFMAP (((const eeprom_config *)device->inline_config)->pinterface->data_bits == 8 ? (const void *)ADDRESS_MAP_NAME(eeprom_map8) : (const void *)ADDRESS_MAP_NAME(eeprom_map16))
#include "devtempl.h"

View File

@ -61,7 +61,4 @@ READ_LINE_DEVICE_HANDLER( eeprom_read_bit );
WRITE_LINE_DEVICE_HANDLER( eeprom_set_cs_line );
WRITE_LINE_DEVICE_HANDLER( eeprom_set_clock_line );
void eeprom_set_data( const device_config *device, const UINT8 *data, int length );
void *eeprom_get_data_pointer( const device_config *device, UINT32 *length, UINT32 *size );
#endif

View File

@ -1235,27 +1235,27 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag,
/*-------------------------------------------------
normalize_flags_for_cpu - modify the region
flags for the given CPU index
normalize_flags_for_device - modify the region
flags for the given device
-------------------------------------------------*/
static UINT32 normalize_flags_for_cpu(running_machine *machine, UINT32 startflags, const char *rgntag)
static UINT32 normalize_flags_for_device(running_machine *machine, UINT32 startflags, const char *rgntag)
{
const device_config *device = cputag_get_cpu(machine, rgntag);
if (device != NULL && cpu_get_databus_width(device, ADDRESS_SPACE_PROGRAM) != 0)
const device_config *device = devtag_get_device(machine, rgntag);
if (device != NULL && device_get_databus_width(device, ADDRESS_SPACE_0) != 0)
{
int buswidth;
/* set the endianness */
startflags &= ~ROMREGION_ENDIANMASK;
if (cpu_get_endianness(device) == ENDIANNESS_LITTLE)
if (device_get_endianness(device) == ENDIANNESS_LITTLE)
startflags |= ROMREGION_LE;
else
startflags |= ROMREGION_BE;
/* set the width */
startflags &= ~ROMREGION_WIDTHMASK;
buswidth = cpu_get_databus_width(device, ADDRESS_SPACE_PROGRAM);
buswidth = device_get_databus_width(device, ADDRESS_SPACE_0);
if (buswidth <= 8)
startflags |= ROMREGION_8BIT;
else if (buswidth <= 16)
@ -1292,9 +1292,9 @@ static void process_region_list(rom_load_data *romdata)
/* the first entry must be a region */
assert(ROMENTRY_ISREGION(region));
/* if this is a CPU region, override with the CPU width and endianness */
if (cputag_get_cpu(romdata->machine, astring_c(regiontag)) != NULL)
regionflags = normalize_flags_for_cpu(romdata->machine, regionflags, astring_c(regiontag));
/* if this is a device region, override with the device width and endianness */
if (devtag_get_device(romdata->machine, astring_c(regiontag)) != NULL)
regionflags = normalize_flags_for_device(romdata->machine, regionflags, astring_c(regiontag));
/* remember the base and length */
romdata->regionbase = memory_region_alloc(romdata->machine, astring_c(regiontag), regionlength, regionflags);

View File

@ -1625,7 +1625,7 @@ static MACHINE_RESET( cave )
/* modify the eeprom on a reset with the desired region for the games that have the
region factory set in eeprom */
if (cave_region_byte >= 0)
((UINT8 *)eeprom_get_data_pointer(devtag_get_device(machine, "eeprom"),NULL,NULL))[cave_region_byte] = input_port_read(machine, "EEPROM");
memory_write_byte(cputag_get_address_space(machine, "eeprom", ADDRESS_SPACE_0), cave_region_byte, input_port_read(machine, "EEPROM"));
}
static const ymz280b_interface ymz280b_intf =

View File

@ -482,7 +482,7 @@ static WRITE32_HANDLER( tattass_control_w )
static int pendingCommand=0; /* 1 = read, 2 = write */
static int readBitCount=0;
static int byteAddr=0;
UINT8 *eeprom=(UINT8 *)eeprom_get_data_pointer(devtag_get_device(space->machine, "eeprom"), NULL,NULL);
const address_space *eeprom_space = cputag_get_address_space(space->machine, "eeprom", ADDRESS_SPACE_0);
/* Eprom in low byte */
if (mem_mask==0x000000ff) { /* Byte write to low byte only (different from word writing including low byte) */
@ -532,7 +532,7 @@ static WRITE32_HANDLER( tattass_control_w )
int d=readBitCount/8;
int m=7-(readBitCount%8);
int a=(byteAddr+d)%1024;
int b=eeprom[a];
int b=memory_read_byte(eeprom_space, a);
tattass_eprom_bit=(b>>m)&1;
@ -549,7 +549,7 @@ static WRITE32_HANDLER( tattass_control_w )
int b=(buffer[24]<<7)|(buffer[25]<<6)|(buffer[26]<<5)|(buffer[27]<<4)
|(buffer[28]<<3)|(buffer[29]<<2)|(buffer[30]<<1)|(buffer[31]<<0);
eeprom[byteAddr]=b;
memory_write_byte(eeprom_space, byteAddr, b);
}
lastClock=data&0x20;
return;
@ -564,7 +564,7 @@ static WRITE32_HANDLER( tattass_control_w )
/* Check for read command */
if (buffer[0] && buffer[1]) {
tattass_eprom_bit=(eeprom[byteAddr]>>7)&1;
tattass_eprom_bit=(memory_read_byte(eeprom_space, byteAddr)>>7)&1;
readBitCount=1;
pendingCommand=1;
}

View File

@ -1814,14 +1814,11 @@ static int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* d
//printf("save to eeprom\n");
{
UINT32 length, size;
UINT8 *dat;
dat = (UINT8 *)eeprom_get_data_pointer(devtag_get_device(space->machine, "eeprom"), &length, &size);
const address_space *eeprom_space = cputag_get_address_space(space->machine, "eeprom", ADDRESS_SPACE_0);
for (i=0;i<0x80;i++)
{
dat[i] = memory_read_byte(space, calc3_eeprom_addr+0x200000+i);
memory_write_byte(eeprom_space, i, memory_read_byte(space, calc3_eeprom_addr+0x200000+i));
}
}
@ -2164,14 +2161,11 @@ void calc3_mcu_run(running_machine *machine)
*/
{
UINT32 length, size;
UINT8 *dat;
dat = (UINT8 *)eeprom_get_data_pointer(devtag_get_device(space->machine, "eeprom"), &length, &size);
const address_space *eeprom_space = cputag_get_address_space(space->machine, "eeprom", ADDRESS_SPACE_0);
for (i=0;i<0x80;i++)
{
memory_write_byte(space, calc3_eeprom_addr+0x200000+i, dat[i]);
memory_write_byte(space, calc3_eeprom_addr+0x200000+i, memory_read_byte(eeprom_space, i));
}
}