summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2008-03-10 16:00:26 +0000
committer Aaron Giles <aaron@aarongiles.com>2008-03-10 16:00:26 +0000
commit8006568b87ea09a7804343323cf14173cf0103be (patch)
treead2703803bb12f80db6c2c7dbbd0f87a53c97e5b /src
parentd146f7dabc6d764f9e5a0adcc13647508a58294b (diff)
More WIP cleanup of memory.*
Made address versus byte offsets explicit throughout. Removed some unused parameters. Consolidated initialization process. Removed maximum memory block count. Centralized bank management. Added masked handlers and change_pc to the accessors. Added memory_get_accessors() to return a pointer to the accessors for a given address space/databus width/endian configuration. More to come.
Diffstat (limited to 'src')
-rw-r--r--src/emu/memory.c1637
-rw-r--r--src/emu/memory.h174
2 files changed, 931 insertions, 880 deletions
diff --git a/src/emu/memory.c b/src/emu/memory.c
index 8e60898b85f..c68873b46fe 100644
--- a/src/emu/memory.c
+++ b/src/emu/memory.c
@@ -16,20 +16,27 @@
Next, the address is broken into two halves, an upper half and a
lower half. The number of bits in each half can be controlled via
- macros in memory.h, but they default to the upper 18 bits and the
- lower 14 bits. The upper half is then used as an index into the
- base_lookup table.
-
- If the value pulled from the table is within the range 192-255, then
- the lower half of the address is needed to resolve the final handler.
- The value from the table (192-255) is combined with the lower address
- bits to form an index into a subtable.
-
- Table values in the range 0-63 are reserved for internal handling
- (such as RAM, ROM, NOP, and banking). Table values between 64 and 192
- are assigned dynamically at startup.
-
-****************************************************************************
+ the macros in LEVEL1_BITS and LEVEL2_BITS, but they default to the
+ upper 18 bits and the lower 14 bits.
+
+ The upper half is then used as an index into a lookup table of bytes.
+ If the value pulled from the table is between SUBTABLE_BASE and 255,
+ then the lower half of the address is needed to resolve the final
+ handler. In this case, the value from the table is combined with the
+ lower address bits to form an index into a subtable.
+
+ The final result of the lookup is a value from 0 to SUBTABLE_BASE - 1.
+ These values correspond to memory handlers. The lower numbered
+ handlers (from 0 through STATIC_COUNT - 1) are fixed handlers and refer
+ to either memory banks or other special cases. The remaining handlers
+ (from STATIC_COUNT through SUBTABLE_BASE - 1) are dynamically
+ allocated to driver-specified handlers.
+
+ Thus, table entries fall into these categories:
+
+ 0 .. STATIC_COUNT - 1 = fixed handlers
+ STATIC_COUNT .. SUBTABLE_BASE - 1 = driver-specific handlers
+ SUBTABLE_BASE .. 255 = need to look up lower bits in subtable
Caveats:
@@ -114,40 +121,56 @@
#endif
+/***************************************************************************
+ DEBUGGING
+***************************************************************************/
+
#define MEM_DUMP (0)
#define VERBOSE (0)
#define ALLOW_ONLY_AUTO_MALLOC_BANKS 0
-
#define VPRINTF(x) do { if (VERBOSE) mame_printf_debug x; } while (0)
-/* ----- banking constants ----- */
-#define MAX_BANKS 66 /* maximum number of banks */
+/***************************************************************************
+ CONSTANTS
+***************************************************************************/
+
+/* banking constants */
+#define MAX_BANKS (STATIC_BANKMAX - STATIC_BANK1) /* maximum number of banks */
#define MAX_BANK_ENTRIES 256 /* maximum number of possible bank values */
#define MAX_EXPLICIT_BANKS 32 /* maximum number of explicitly-defined banks */
-/* ----- address map lookup table definitions ----- */
+/* address map lookup table definitions */
+#define LEVEL1_BITS 18 /* number of address bits in the level 1 table */
+#define LEVEL2_BITS (32 - LEVEL1_BITS) /* number of address bits in the level 2 table */
#define SUBTABLE_COUNT 64 /* number of slots reserved for subtables */
-#define SUBTABLE_BASE (256-SUBTABLE_COUNT) /* first index of a subtable */
+#define SUBTABLE_BASE (256 - SUBTABLE_COUNT) /* first index of a subtable */
#define ENTRY_COUNT (SUBTABLE_BASE) /* number of legitimate (non-subtable) entries */
#define SUBTABLE_ALLOC 8 /* number of subtables to allocate at a time */
-/* ----- bit counts ----- */
-#define LEVEL1_BITS 18 /* number of address bits in the level 1 table */
-#define LEVEL2_BITS (32 - LEVEL1_BITS) /* number of address bits in the level 2 table */
-
-/* ----- other address map constants ----- */
-#define MAX_MEMORY_BLOCKS 1024 /* maximum memory blocks we can track */
+/* other address map constants */
#define MAX_SHARED_POINTERS 256 /* maximum number of shared pointers in memory maps */
-#define MEMORY_BLOCK_SIZE 65536 /* size of allocated memory blocks */
+#define MEMORY_BLOCK_CHUNK 65536 /* minimum chunk size of allocated memory blocks */
+
+/* read or write constants */
+enum _read_or_write
+{
+ ROW_READ,
+ ROW_WRITE
+};
+typedef enum _read_or_write read_or_write;
+
+
+/***************************************************************************
+ MACROS
+***************************************************************************/
/* ----- table lookup helpers ----- */
#define LEVEL1_INDEX(a) ((a) >> LEVEL2_BITS)
#define LEVEL2_INDEX(e,a) ((1 << LEVEL1_BITS) + (((e) - SUBTABLE_BASE) << LEVEL2_BITS) + ((a) & ((1 << LEVEL2_BITS) - 1)))
-
/* macros for the profiler */
#define MEMREADSTART() do { profiler_mark(PROFILER_MEMREAD); } while (0)
#define MEMREADEND(ret) do { profiler_mark(PROFILER_END); return ret; } while (0)
@@ -164,9 +187,11 @@
#define HANDLER_TO_BANK(h) ((UINT32)(FPTR)(h))
#define BANK_TO_HANDLER(b) ((genf *)(FPTR)(b))
-#define SPACE_SHIFT(s,a) (((s)->ashift < 0) ? ((a) << -(s)->ashift) : ((a) >> (s)->ashift))
-#define SPACE_SHIFT_END(s,a) (((s)->ashift < 0) ? (((a) << -(s)->ashift) | ((1 << -(s)->ashift) - 1)) : ((a) >> (s)->ashift))
-#define INV_SPACE_SHIFT(s,a) (((s)->ashift < 0) ? ((a) >> -(s)->ashift) : ((a) << (s)->ashift))
+#undef ADDR2BYTE
+#undef BYTE2ADDR
+#define ADDR2BYTE(s,a) (((s)->ashift < 0) ? ((a) << -(s)->ashift) : ((a) >> (s)->ashift))
+#define ADDR2BYTE_END(s,a) (((s)->ashift < 0) ? (((a) << -(s)->ashift) | ((1 << -(s)->ashift) - 1)) : ((a) >> (s)->ashift))
+#define BYTE2ADDR(s,a) (((s)->ashift < 0) ? ((a) >> -(s)->ashift) : ((a) << (s)->ashift))
#define SUBTABLE_PTR(tabledata, entry) (&(tabledata)->table[(1 << LEVEL1_BITS) + (((entry) - SUBTABLE_BASE) << LEVEL2_BITS)])
@@ -179,21 +204,23 @@
#endif
-/*-------------------------------------------------
+/***************************************************************************
TYPE DEFINITIONS
--------------------------------------------------*/
+***************************************************************************/
+/* a memory block is a chunk of RAM associated with a range of memory in a CPU's address space */
typedef struct _memory_block memory_block;
struct _memory_block
{
+ memory_block * next; /* next memory block in the list */
UINT8 cpunum; /* which CPU are we associated with? */
UINT8 spacenum; /* which address space are we associated with? */
UINT8 isallocated; /* did we allocate this ourselves? */
- offs_t start, end; /* start/end for verifying a match */
+ offs_t bytestart, byteend; /* byte-normalized start/end for verifying a match */
UINT8 * data; /* pointer to the data for this block */
};
-typedef struct _bank_data bank_data;
+typedef struct _bank_data bank_info;
struct _bank_data
{
UINT8 used; /* is this bank used? */
@@ -202,8 +229,8 @@ struct _bank_data
UINT8 spacenum; /* the address space it is used for */
UINT8 read; /* is this bank used for reads? */
UINT8 write; /* is this bank used for writes? */
- offs_t base; /* the base offset */
- offs_t end; /* the end offset */
+ offs_t bytestart; /* byte-adjusted start offset */
+ offs_t byteend; /* byte-adjusted end offset */
UINT16 curentry; /* current entry */
void * entry[MAX_BANK_ENTRIES];/* array of entries for this bank */
void * entryd[MAX_BANK_ENTRIES];/* array of decrypted entries for this bank */
@@ -221,9 +248,9 @@ union _rwhandlers
struct _handler_data
{
rwhandlers handler; /* function pointer for handler */
- offs_t offset; /* base offset for handler */
- offs_t top; /* maximum offset for handler */
- offs_t mask; /* mask against the final address */
+ offs_t bytestart; /* byte-adjusted start address for handler */
+ offs_t byteend; /* byte-adjusted end address for handler */
+ offs_t bytemask; /* byte-adjusted mask against the final address */
void * object; /* object associated with the handler */
const char * name; /* name of the handler */
};
@@ -253,8 +280,8 @@ struct _addrspace_data
INT8 ashift; /* address shift */
UINT8 abits; /* address bits */
UINT8 dbits; /* data bits */
- offs_t rawmask; /* raw address mask, before adjusting to bytes */
- offs_t mask; /* address mask */
+ offs_t addrmask; /* global address mask */
+ offs_t bytemask; /* byte-converted global address mask */
UINT64 unmap; /* unmapped value */
table_data read; /* memory read lookup table */
table_data write; /* memory write lookup table */
@@ -265,7 +292,10 @@ struct _addrspace_data
typedef struct _cpu_data cpu_data;
struct _cpu_data
{
- opbase_handler_func opbase; /* opcode base handler */
+ UINT8 * region; /* pointer to memory region */
+ size_t regionsize; /* size of region, in bytes */
+
+ opbase_handler_func opbase; /* opcode base handler */
void * op_ram; /* dynamic RAM base pointer */
void * op_rom; /* dynamic ROM base pointer */
@@ -279,9 +309,10 @@ struct _cpu_data
};
-/*-------------------------------------------------
+
+/***************************************************************************
GLOBAL VARIABLES
--------------------------------------------------*/
+***************************************************************************/
UINT8 * opcode_base; /* opcode base */
UINT8 * opcode_arg_base; /* opcode argument base */
@@ -296,18 +327,17 @@ static UINT8 * bank_ptr[STATIC_COUNT]; /* array of bank pointers */
static UINT8 * bankd_ptr[STATIC_COUNT]; /* array of decrypted bank pointers */
static void * shared_ptr[MAX_SHARED_POINTERS];/* array of shared pointers */
-static memory_block memory_block_list[MAX_MEMORY_BLOCKS];/* array of memory blocks we are tracking */
-static int memory_block_count = 0; /* number of memory_block[] entries used */
+static memory_block * memory_block_list; /* head of the list of memory blocks */
static int cur_context; /* current CPU context */
-static opbase_handler_func opbasefunc; /* opcode base override */
+static opbase_handler_func opbasefunc; /* opcode base override */
-static int debugger_access; /* treat accesses as coming from the debugger */
-static int log_unmap[ADDRESS_SPACES]; /* log unmapped memory accesses */
+static UINT8 debugger_access; /* treat accesses as coming from the debugger */
+static UINT8 log_unmap[ADDRESS_SPACES]; /* log unmapped memory accesses */
static cpu_data cpudata[MAX_CPU]; /* data gathered for each CPU */
-static bank_data bankdata[STATIC_COUNT]; /* data gathered for each bank */
+static bank_info bankdata[STATIC_COUNT]; /* data gathered for each bank */
#ifdef ENABLE_DEBUGGER
static debug_hook_read_func debug_hook_read; /* pointer to debugger callback for memory reads */
@@ -319,60 +349,60 @@ static const data_accessors memory_accessors[ADDRESS_SPACES][4][2] =
/* program accessors */
{
{
- { program_read_byte_8, NULL, NULL, NULL, program_write_byte_8, NULL, NULL, NULL },
- { program_read_byte_8, NULL, NULL, NULL, program_write_byte_8, NULL, NULL, NULL }
+ { memory_set_opbase, program_read_byte_8, NULL, NULL, NULL, NULL, NULL, program_write_byte_8, NULL, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, program_read_byte_8, NULL, NULL, NULL, NULL, NULL, program_write_byte_8, NULL, NULL, NULL, NULL, NULL }
},
{
- { program_read_byte_16le, program_read_word_16le, NULL, NULL, program_write_byte_16le, program_write_word_16le, NULL, NULL },
- { program_read_byte_16be, program_read_word_16be, NULL, NULL, program_write_byte_16be, program_write_word_16be, NULL, NULL }
+ { memory_set_opbase, program_read_byte_16le, program_read_word_16le, NULL, NULL, NULL, NULL, program_write_byte_16le, program_write_word_16le, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, program_read_byte_16be, program_read_word_16be, NULL, NULL, NULL, NULL, program_write_byte_16be, program_write_word_16be, NULL, NULL, NULL, NULL }
},
{
- { program_read_byte_32le, program_read_word_32le, program_read_dword_32le, NULL, program_write_byte_32le, program_write_word_32le, program_write_dword_32le, NULL },
- { program_read_byte_32be, program_read_word_32be, program_read_dword_32be, NULL, program_write_byte_32be, program_write_word_32be, program_write_dword_32be, NULL }
+ { memory_set_opbase, program_read_byte_32le, program_read_word_32le, program_read_dword_32le, program_read_masked_32le, NULL, NULL, program_write_byte_32le, program_write_word_32le, program_write_dword_32le, program_write_masked_32le, NULL, NULL },
+ { memory_set_opbase, program_read_byte_32be, program_read_word_32be, program_read_dword_32be, program_read_masked_32be, NULL, NULL, program_write_byte_32be, program_write_word_32be, program_write_dword_32be, program_write_masked_32be, NULL, NULL }
},
{
- { program_read_byte_64le, program_read_word_64le, program_read_dword_64le, program_read_qword_64le, program_write_byte_64le, program_write_word_64le, program_write_dword_64le, program_write_qword_64le },
- { program_read_byte_64be, program_read_word_64be, program_read_dword_64be, program_read_qword_64be, program_write_byte_64be, program_write_word_64be, program_write_dword_64be, program_write_qword_64be }
+ { memory_set_opbase, program_read_byte_64le, program_read_word_64le, program_read_dword_64le, NULL, program_read_qword_64le, program_read_masked_64le, program_write_byte_64le, program_write_word_64le, program_write_dword_64le, NULL, program_write_qword_64le, program_write_masked_64le },
+ { memory_set_opbase, program_read_byte_64be, program_read_word_64be, program_read_dword_64be, NULL, program_read_qword_64be, program_read_masked_64be, program_write_byte_64be, program_write_word_64be, program_write_dword_64be, NULL, program_write_qword_64be, program_write_masked_64be }
}
},
/* data accessors */
{
{
- { data_read_byte_8, NULL, NULL, NULL, data_write_byte_8, NULL, NULL, NULL },
- { data_read_byte_8, NULL, NULL, NULL, data_write_byte_8, NULL, NULL, NULL }
+ { memory_set_opbase, data_read_byte_8, NULL, NULL, NULL, NULL, NULL, data_write_byte_8, NULL, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, data_read_byte_8, NULL, NULL, NULL, NULL, NULL, data_write_byte_8, NULL, NULL, NULL, NULL, NULL }
},
{
- { data_read_byte_16le, data_read_word_16le, NULL, NULL, data_write_byte_16le, data_write_word_16le, NULL, NULL },
- { data_read_byte_16be, data_read_word_16be, NULL, NULL, data_write_byte_16be, data_write_word_16be, NULL, NULL }
+ { memory_set_opbase, data_read_byte_16le, data_read_word_16le, NULL, NULL, NULL, NULL, data_write_byte_16le, data_write_word_16le, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, data_read_byte_16be, data_read_word_16be, NULL, NULL, NULL, NULL, data_write_byte_16be, data_write_word_16be, NULL, NULL, NULL, NULL }
},
{
- { data_read_byte_32le, data_read_word_32le, data_read_dword_32le, NULL, data_write_byte_32le, data_write_word_32le, data_write_dword_32le, NULL },
- { data_read_byte_32be, data_read_word_32be, data_read_dword_32be, NULL, data_write_byte_32be, data_write_word_32be, data_write_dword_32be, NULL }
+ { memory_set_opbase, data_read_byte_32le, data_read_word_32le, data_read_dword_32le, data_read_masked_32le, NULL, NULL, data_write_byte_32le, data_write_word_32le, data_write_dword_32le, data_write_masked_32le, NULL, NULL },
+ { memory_set_opbase, data_read_byte_32be, data_read_word_32be, data_read_dword_32be, data_read_masked_32be, NULL, NULL, data_write_byte_32be, data_write_word_32be, data_write_dword_32be, data_write_masked_32be, NULL, NULL }
},
{
- { data_read_byte_64le, data_read_word_64le, data_read_dword_64le, data_read_qword_64le, data_write_byte_64le, data_write_word_64le, data_write_dword_64le, data_write_qword_64le },
- { data_read_byte_64be, data_read_word_64be, data_read_dword_64be, data_read_qword_64be, data_write_byte_64be, data_write_word_64be, data_write_dword_64be, data_write_qword_64be }
+ { memory_set_opbase, data_read_byte_64le, data_read_word_64le, data_read_dword_64le, NULL, data_read_qword_64le, data_read_masked_64le, data_write_byte_64le, data_write_word_64le, data_write_dword_64le, NULL, data_write_qword_64le, data_write_masked_64le },
+ { memory_set_opbase, data_read_byte_64be, data_read_word_64be, data_read_dword_64be, NULL, data_read_qword_64be, data_read_masked_64be, data_write_byte_64be, data_write_word_64be, data_write_dword_64be, NULL, data_write_qword_64be, data_write_masked_64be }
}
},
/* I/O accessors */
{
{
- { io_read_byte_8, NULL, NULL, NULL, io_write_byte_8, NULL, NULL, NULL },
- { io_read_byte_8, NULL, NULL, NULL, io_write_byte_8, NULL, NULL, NULL }
+ { memory_set_opbase, io_read_byte_8, NULL, NULL, NULL, NULL, NULL, io_write_byte_8, NULL, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, io_read_byte_8, NULL, NULL, NULL, NULL, NULL, io_write_byte_8, NULL, NULL, NULL, NULL, NULL }
},
{
- { io_read_byte_16le, io_read_word_16le, NULL, NULL, io_write_byte_16le, io_write_word_16le, NULL, NULL },
- { io_read_byte_16be, io_read_word_16be, NULL, NULL, io_write_byte_16be, io_write_word_16be, NULL, NULL }
+ { memory_set_opbase, io_read_byte_16le, io_read_word_16le, NULL, NULL, NULL, NULL, io_write_byte_16le, io_write_word_16le, NULL, NULL, NULL, NULL },
+ { memory_set_opbase, io_read_byte_16be, io_read_word_16be, NULL, NULL, NULL, NULL, io_write_byte_16be, io_write_word_16be, NULL, NULL, NULL, NULL }
},
{
- { io_read_byte_32le, io_read_word_32le, io_read_dword_32le, NULL, io_write_byte_32le, io_write_word_32le, io_write_dword_32le, NULL },
- { io_read_byte_32be, io_read_word_32be, io_read_dword_32be, NULL, io_write_byte_32be, io_write_word_32be, io_write_dword_32be, NULL }
+ { memory_set_opbase, io_read_byte_32le, io_read_word_32le, io_read_dword_32le, io_read_masked_32le, NULL, NULL, io_write_byte_32le, io_write_word_32le, io_write_dword_32le, io_write_masked_32le, NULL, NULL },
+ { memory_set_opbase, io_read_byte_32be, io_read_word_32be, io_read_dword_32be, io_read_masked_32be, NULL, NULL, io_write_byte_32be, io_write_word_32be, io_write_dword_32be, io_write_masked_32be, NULL, NULL }
},
{
- { io_read_byte_64le, io_read_word_64le, io_read_dword_64le, io_read_qword_64le, io_write_byte_64le, io_write_word_64le, io_write_dword_64le, io_write_qword_64le },
- { io_read_byte_64be, io_read_word_64be, io_read_dword_64be, io_read_qword_64be, io_write_byte_64be, io_write_word_64be, io_write_dword_64be, io_write_qword_64be }
+ { memory_set_opbase, io_read_byte_64le, io_read_word_64le, io_read_dword_64le, NULL, io_read_qword_64le, io_read_masked_64le, io_write_byte_64le, io_write_word_64le, io_write_dword_64le, NULL, io_write_qword_64le, io_write_masked_64le },
+ { memory_set_opbase, io_read_byte_64be, io_read_word_64be, io_read_dword_64be, NULL, io_read_qword_64be, io_read_masked_64be, io_write_byte_64be, io_write_word_64be, io_write_dword_64be, NULL, io_write_qword_64be, io_write_masked_64be }
}
},
};
@@ -380,8 +410,47 @@ static const data_accessors memory_accessors[ADDRESS_SPACES][4][2] =
const char *const address_space_names[ADDRESS_SPACES] = { "program", "data", "I/O" };
-/*-------------------------------------------------
+
+/***************************************************************************
+ FUNCTION PROTOTYPES
+***************************************************************************/
+
+static void address_map_detokenize(address_map *map, const addrmap_token *tokens);
+
+static void memory_init_cpudata(const machine_config *config);
+static void memory_init_preflight(const machine_config *config);
+static void memory_init_populate(running_machine *machine);
+static void install_mem_handler_private(addrspace_data *space, read_or_write readorwrite, int databits, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, genf *handler, void *object, const char *handler_name);
+static void install_mem_handler(addrspace_data *space, read_or_write readorwrite, int databits, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, genf *handler, void *object, const char *handler_name);
+static void bank_assign_static(int banknum, int cpunum, int spacenum, read_or_write readorwrite, offs_t bytestart, offs_t byteend);
+static genf *bank_assign_dynamic(int cpunum, int spacenum, read_or_write readorwrite, offs_t bytestart, offs_t byteend);
+static UINT8 get_handler_index(handler_data *table, void *object, genf *handler, const char *handler_name, offs_t bytestart, offs_t byteend, offs_t bytemask);
+static void populate_table_range(addrspace_data *space, read_or_write readorwrite, offs_t bytestart, offs_t byteend, UINT8 handler);
+static UINT8 subtable_alloc(table_data *tabledata);
+static void subtable_realloc(table_data *tabledata, UINT8 subentry);
+static int subtable_merge(table_data *tabledata);
+static void subtable_release(table_data *tabledata, UINT8 subentry);
+static UINT8 *subtable_open(table_data *tabledata, offs_t l1index);
+static void subtable_close(table_data *tabledata, offs_t l1index);
+static void memory_init_allocate(const machine_config *config);
+static void *allocate_memory_block(int cpunum, int spacenum, offs_t bytestart, offs_t byteend, void *memory);
+static void register_for_save(int cpunum, int spacenum, offs_t bytestart, void *base, size_t numbytes);
+static address_map_entry *assign_intersecting_blocks(addrspace_data *space, offs_t bytestart, offs_t byteend, UINT8 *base);
+static void memory_init_locate(void);
+static void *memory_find_base(int cpunum, int spacenum, int readwrite, offs_t byteaddress);
+static genf *get_static_handler(int databits, int readorwrite, int spacenum, int which);
+static void memory_exit(running_machine *machine);
+static void mem_dump(void);
+
+
+
+/***************************************************************************
INLINE FUNCTIONS
+***************************************************************************/
+
+/*-------------------------------------------------
+ force_opbase_update - ensure that we update
+ the opcode base
-------------------------------------------------*/
INLINE void force_opbase_update(void)
@@ -392,48 +461,25 @@ INLINE void force_opbase_update(void)
/*-------------------------------------------------
- FUNCTION PROTOTYPES
+ adjust_addresses - adjust addresses for a
+ given address space in a standard fashion
-------------------------------------------------*/
-static void address_map_detokenize(address_map *map, const addrmap_token *tokens);
-
-static void init_cpudata(void);
-static void init_addrspace(UINT8 cpunum, UINT8 spacenum);
-static void preflight_memory(void);
-static void populate_memory(void);
-static void install_mem_handler_private(addrspace_data *space, int iswrite, int databits, offs_t start, offs_t end, offs_t mask, offs_t mirror, genf *handler, int isfixed, void *object, const char *handler_name);
-static void install_mem_handler(addrspace_data *space, int iswrite, int databits, offs_t start, offs_t end, offs_t mask, offs_t mirror, genf *handler, int isfixed, void *object, const char *handler_name);
-static genf *assign_dynamic_bank(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mirror, int isfixed, int ismasked);
-static UINT8 get_handler_index(handler_data *table, void *object, genf *handler, const char *handler_name, offs_t start, offs_t end, offs_t mask);
-static void populate_table_range(addrspace_data *space, int iswrite, offs_t start, offs_t stop, UINT8 handler);
-static UINT8 allocate_subtable(table_data *tabledata);
-static void reallocate_subtable(table_data *tabledata, UINT8 subentry);
-static int merge_subtables(table_data *tabledata);
-static void release_subtable(table_data *tabledata, UINT8 subentry);
-static UINT8 *open_subtable(table_data *tabledata, offs_t l1index);
-static void close_subtable(table_data *tabledata, offs_t l1index);
-static void allocate_memory(void);
-static void *allocate_memory_block(int cpunum, int spacenum, offs_t bytestart, offs_t byteend, void *memory);
-static void register_for_save(int cpunum, int spacenum, offs_t start, void *base, size_t numbytes);
-static address_map_entry *assign_intersecting_blocks(addrspace_data *space, offs_t start, offs_t end, UINT8 *base);
-static void find_memory(void);
-static void *memory_find_base(int cpunum, int spacenum, int readwrite, offs_t offset);
-static genf *get_static_handler(int databits, int readorwrite, int spacenum, int which);
-static void memory_exit(running_machine *machine);
-
-static void mem_dump(void)
+INLINE void adjust_addresses(addrspace_data *space, offs_t *start, offs_t *end, offs_t *mask, offs_t *mirror)
{
- FILE *file;
+ /* adjust start/end/mask values */
+ if (*mask == 0)
+ *mask = space->addrmask & ~*mirror;
+ else
+ *mask &= space->addrmask;
+ *start &= ~*mirror & space->addrmask;
+ *end &= ~*mirror & space->addrmask;
- if (MEM_DUMP)
- {
- file = fopen("memdump.log", "w");
- if (file)
- {
- memory_dump(file);
- fclose(file);
- }
- }
+ /* adjust to byte values */
+ *start = ADDR2BYTE(space, *start);
+ *end = ADDR2BYTE_END(space, *end);
+ *mask = ADDR2BYTE(space, *mask);
+ *mirror = ADDR2BYTE(space, *mirror);
}
@@ -447,7 +493,7 @@ void memory_init(running_machine *machine)
int i;
for (i = 0; i < ADDRESS_SPACES; i++)
- log_unmap[i] = 1;
+ log_unmap[i] = TRUE;
/* no current context to start */
cur_context = -1;
@@ -457,25 +503,22 @@ void memory_init(running_machine *machine)
memset(bank_ptr, 0, sizeof(bank_ptr));
memset(bankd_ptr, 0, sizeof(bankd_ptr));
- /* reset our hardcoded and allocated pointer tracking */
- memset(memory_block_list, 0, sizeof(memory_block_list));
- memory_block_count = 0;
-
/* init the CPUs */
- init_cpudata();
+ memory_init_cpudata(machine->config);
+
add_exit_callback(machine, memory_exit);
/* preflight the memory handlers and check banks */
- preflight_memory();
+ memory_init_preflight(machine->config);
/* then fill in the tables */
- populate_memory();
+ memory_init_populate(machine);
/* allocate any necessary memory */
- allocate_memory();
+ memory_init_allocate(machine->config);
/* find all the allocated pointers */
- find_memory();
+ memory_init_locate();
/* dump the final memory configuration */
mem_dump();
@@ -489,17 +532,26 @@ void memory_init(running_machine *machine)
static void memory_exit(running_machine *machine)
{
int cpunum, spacenum;
+
+ /* free the memory blocks */
+ while (memory_block_list != NULL)
+ {
+ memory_block *block = memory_block_list;
+ memory_block_list = block->next;
+ free(block);
+ }
/* free all the tables */
- for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
{
- if (cpudata[cpunum].space[spacenum].map != NULL)
- address_map_free(cpudata[cpunum].space[spacenum].map);
- if (cpudata[cpunum].space[spacenum].read.table != NULL)
- free(cpudata[cpunum].space[spacenum].read.table);
- if (cpudata[cpunum].space[spacenum].write.table != NULL)
- free(cpudata[cpunum].space[spacenum].write.table);
+ addrspace_data *space = &cpudata[cpunum].space[spacenum];
+ if (space->map != NULL)
+ address_map_free(space->map);
+ if (space->read.table != NULL)
+ free(space->read.table);
+ if (space->write.table != NULL)
+ free(space->write.table);
}
}
@@ -530,7 +582,7 @@ void memory_set_context(int activecpu)
opcode_entry = cpudata[activecpu].opcode_entry;
/* program address space */
- active_address_space[ADDRESS_SPACE_PROGRAM].addrmask = cpudata[activecpu].space[ADDRESS_SPACE_PROGRAM].mask;
+ active_address_space[ADDRESS_SPACE_PROGRAM].bytemask = cpudata[activecpu].space[ADDRESS_SPACE_PROGRAM].bytemask;
active_address_space[ADDRESS_SPACE_PROGRAM].readlookup = cpudata[activecpu].space[ADDRESS_SPACE_PROGRAM].read.table;
active_address_space[ADDRESS_SPACE_PROGRAM].writelookup = cpudata[activecpu].space[ADDRESS_SPACE_PROGRAM].write.table;
active_address_space[ADDRESS_SPACE_PROGRAM].readhandlers = cpudata[activecpu].space[ADDRESS_SPACE_PROGRAM].read.handlers;
@@ -540,7 +592,7 @@ void memory_set_context(int activecpu)
/* data address space */
if (cpudata[activecpu].spacemask & (1 << ADDRESS_SPACE_DATA))
{
- active_address_space[ADDRESS_SPACE_DATA].addrmask = cpudata[activecpu].space[ADDRESS_SPACE_DATA].mask;
+ active_address_space[ADDRESS_SPACE_DATA].bytemask = cpudata[activecpu].space[ADDRESS_SPACE_DATA].bytemask;
active_address_space[ADDRESS_SPACE_DATA].readlookup = cpudata[activecpu].space[ADDRESS_SPACE_DATA].read.table;
active_address_space[ADDRESS_SPACE_DATA].writelookup = cpudata[activecpu].space[ADDRESS_SPACE_DATA].write.table;
active_address_space[ADDRESS_SPACE_DATA].readhandlers = cpudata[activecpu].space[ADDRESS_SPACE_DATA].read.handlers;
@@ -551,7 +603,7 @@ void memory_set_context(int activecpu)
/* I/O address space */
if (cpudata[activecpu].spacemask & (1 << ADDRESS_SPACE_IO))
{
- active_address_space[ADDRESS_SPACE_IO].addrmask = cpudata[activecpu].space[ADDRESS_SPACE_IO].mask;
+ active_address_space[ADDRESS_SPACE_IO].bytemask = cpudata[activecpu].space[ADDRESS_SPACE_IO].bytemask;
active_address_space[ADDRESS_SPACE_IO].readlookup = cpudata[activecpu].space[ADDRESS_SPACE_IO].read.table;
active_address_space[ADDRESS_SPACE_IO].writelookup = cpudata[activecpu].space[ADDRESS_SPACE_IO].write.table;
active_address_space[ADDRESS_SPACE_IO].readhandlers = cpudata[activecpu].space[ADDRESS_SPACE_IO].read.handlers;
@@ -574,154 +626,16 @@ void memory_set_context(int activecpu)
/*-------------------------------------------------
- address_map_detokenize - detokenize an array
- of address map tokens
+ memory_get_accessors - get a pointer to the
+ set of memory accessor functions based on
+ the address space, databus width, and
+ endianness
-------------------------------------------------*/
-static void address_map_detokenize(address_map *map, const addrmap_token *tokens)
+const data_accessors *memory_get_accessors(int spacenum, int databits, int endianness)
{
- address_map_entry **entryptr;
- address_map_entry *entry;
- UINT8 spacenum, databits;
- UINT32 entrytype;
-
- /* check the first token */
- TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, spacenum, 8, databits, 8);
- if (entrytype != ADDRMAP_TOKEN_START)
- fatalerror("Address map missing ADDRMAP_TOKEN_START!");
- if (spacenum >= ADDRESS_SPACES)
- fatalerror("Invalid address space %d for memory map!", spacenum);
- if (databits != 8 && databits != 16 && databits != 32 && databits != 64)
- fatalerror("Invalid data bits %d for memory map!", databits);
- if (map->spacenum != 0 && map->spacenum != spacenum)
- fatalerror("Included a mismatched address map (space %d) for an existing map of type %d!\n", spacenum, map->spacenum);
- if (map->databits != 0 && map->databits != databits)
- fatalerror("Included a mismatched address map (databits %d) for an existing map with databits %d!\n", databits, map->databits);
-
- /* fill in the map values */
- map->spacenum = spacenum;
- map->databits = databits;
-
- /* find the end of the list */
- for (entryptr = &map->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) ;
- entry = NULL;
-
- /* loop over tokens until we hit the end */
- while (entrytype != ADDRMAP_TOKEN_END)
- {
- /* unpack the token from the first entry */
- TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8);
- switch (entrytype)
- {
- /* end */
- case ADDRMAP_TOKEN_END:
- break;
-
- /* including */
- case ADDRMAP_TOKEN_INCLUDE:
- address_map_detokenize(map, TOKEN_GET_PTR(tokens, tokenptr));
- for (entryptr = &map->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) ;
- entry = NULL;
- break;
-
- /* global flags */
- case ADDRMAP_TOKEN_GLOBAL_MASK:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, map->globalmask, 32);
- break;
-
- case ADDRMAP_TOKEN_UNMAP_VALUE:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, map->unmapval, 1);
- break;
-
- /* start a new range */
- case ADDRMAP_TOKEN_RANGE:
- entry = *entryptr = malloc_or_die(sizeof(**entryptr));
- entryptr = &entry->next;
- memset(entry, 0, sizeof(*entry));
- TOKEN_GET_UINT64_UNPACK2(tokens, entry->start, 32, entry->end, 32);
- break;
-
- case ADDRMAP_TOKEN_MASK:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, entry->mask, 32);
- break;
-
- case ADDRMAP_TOKEN_MIRROR:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, entry->mirror, 32);
- break;
-
- case ADDRMAP_TOKEN_READ:
- entry->read = TOKEN_GET_PTR(tokens, read);
- entry->read_name = TOKEN_GET_STRING(tokens);
- break;
-
- case ADDRMAP_TOKEN_WRITE:
- entry->write = TOKEN_GET_PTR(tokens, write);
- entry->write_name = TOKEN_GET_STRING(tokens);
- break;
-
- case ADDRMAP_TOKEN_DEVICE_READ:
- entry->read = TOKEN_GET_PTR(tokens, read);
- entry->read_name = TOKEN_GET_STRING(tokens);
- entry->read_devtype = TOKEN_GET_PTR(tokens, devtype);
- entry->read_devtag = TOKEN_GET_STRING(tokens);
- break;
-
- case ADDRMAP_TOKEN_DEVICE_WRITE:
- entry->write = TOKEN_GET_PTR(tokens, write);
- entry->write_name = TOKEN_GET_STRING(tokens);
- entry->write_devtype = TOKEN_GET_PTR(tokens, devtype);
- entry->write_devtag = TOKEN_GET_STRING(tokens);
- break;
-
- case ADDRMAP_TOKEN_READ_PORT:
- switch (map->databits)
- {
- case 8: entry->read.mhandler8 = port_tag_to_handler8(TOKEN_GET_STRING(tokens)); break;
- case 16: entry->read.mhandler16 = port_tag_to_handler16(TOKEN_GET_STRING(tokens)); break;
- case 32: entry->read.mhandler32 = port_tag_to_handler32(TOKEN_GET_STRING(tokens)); break;
- case 64: entry->read.mhandler64 = port_tag_to_handler64(TOKEN_GET_STRING(tokens)); break;
- }
- break;
-
- case ADDRMAP_TOKEN_REGION:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, entry->region, 24, entry->region_offs, 32);
- break;
-
- case ADDRMAP_TOKEN_SHARE:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->share, 24);
- break;
-
- case ADDRMAP_TOKEN_BASEPTR:
- entry->baseptr = (void **)TOKEN_GET_PTR(tokens, voidptr);
- break;
-
- case ADDRMAP_TOKEN_BASE_MEMBER:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->baseptroffs_plus1, 24);
- entry->baseptroffs_plus1++;
- break;
-
- case ADDRMAP_TOKEN_SIZEPTR:
- entry->sizeptr = TOKEN_GET_PTR(tokens, sizeptr);
- break;
-
- case ADDRMAP_TOKEN_SIZE_MEMBER:
- TOKEN_UNGET_UINT32(tokens);
- TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->sizeptroffs_plus1, 24);
- entry->sizeptroffs_plus1++;
- break;
-
- default:
- fatalerror("Invalid token %d in address map\n", entrytype);
- break;
- }
- }
+ int accessorindex = (databits == 8) ? 0 : (databits == 16) ? 1 : (databits == 32) ? 2 : 3;
+ return &memory_accessors[spacenum][accessorindex][(endianness == CPU_IS_LE) ? 0 : 1];
}
@@ -755,7 +669,7 @@ opbase_handler_func memory_set_opbase_handler(int cpunum, opbase_handler_func fu
memory_set_opbase - generic opcode base changer
-------------------------------------------------*/
-void memory_set_opbase(offs_t pc)
+void memory_set_opbase(offs_t byteaddress)
{
const address_space *space = &active_address_space[ADDRESS_SPACE_PROGRAM];
UINT8 *base = NULL, *based = NULL;
@@ -765,16 +679,16 @@ void memory_set_opbase(offs_t pc)
/* allow overrides */
if (opbasefunc != NULL)
{
- pc = (*opbasefunc)(Machine, pc);
- if (pc == ~0)
+ byteaddress = (*opbasefunc)(Machine, byteaddress);
+ if (byteaddress == ~0)
return;
}
/* perform the lookup */
- pc &= space->addrmask;
- entry = space->readlookup[LEVEL1_INDEX(pc)];
+ byteaddress &= space->bytemask;
+ entry = space->readlookup[LEVEL1_INDEX(byteaddress)];
if (entry >= SUBTABLE_BASE)
- entry = space->readlookup[LEVEL2_INDEX(entry,pc)];
+ entry = space->readlookup[LEVEL2_INDEX(entry,byteaddress)];
/* keep track of current entry */
opcode_entry = entry;
@@ -785,9 +699,9 @@ void memory_set_opbase(offs_t pc)
/* loop over banks and find a match */
for (entry = 1; entry < STATIC_COUNT; entry++)
{
- bank_data *bdata = &bankdata[entry];
- if (bdata->used && bdata->cpunum == cur_context && bdata->spacenum == ADDRESS_SPACE_PROGRAM &&
- bdata->base < pc && bdata->end > pc)
+ bank_info *bank = &bankdata[entry];
+ if (bank->used && bank->cpunum == cur_context && bank->spacenum == ADDRESS_SPACE_PROGRAM &&
+ bank->bytestart < byteaddress && bank->byteend > byteaddress)
break;
}
@@ -808,11 +722,11 @@ void memory_set_opbase(offs_t pc)
/* compute the adjusted base */
handlers = &active_address_space[ADDRESS_SPACE_PROGRAM].readhandlers[entry];
- opcode_mask = handlers->mask;
- opcode_arg_base = base - (handlers->offset & opcode_mask);
- opcode_base = based - (handlers->offset & opcode_mask);
- opcode_memory_min = handlers->offset;
- opcode_memory_max = handlers->top;
+ opcode_mask = handlers->bytemask;
+ opcode_arg_base = base - (handlers->bytestart & opcode_mask);
+ opcode_base = based - (handlers->bytestart & opcode_mask);
+ opcode_memory_min = handlers->bytestart;
+ opcode_memory_max = handlers->byteend;
}
@@ -821,32 +735,32 @@ void memory_set_opbase(offs_t pc)
decrypted region for the given CPU
-------------------------------------------------*/
-void memory_set_decrypted_region(int cpunum, offs_t start, offs_t end, void *base)
+void memory_set_decrypted_region(int cpunum, offs_t bytestart, offs_t byteend, void *base)
{
int banknum, found = FALSE;
/* loop over banks looking for a match */
for (banknum = 0; banknum < STATIC_COUNT; banknum++)
{
- bank_data *bdata = &bankdata[banknum];
- if (bdata->used && bdata->cpunum == cpunum && bdata->spacenum == ADDRESS_SPACE_PROGRAM && bdata->read)
+ bank_info *bank = &bankdata[banknum];
+ if (bank->used && bank->cpunum == cpunum && bank->spacenum == ADDRESS_SPACE_PROGRAM && bank->read)
{
- if (bdata->base >= start && bdata->end <= end)
+ if (bank->bytestart >= bytestart && bank->byteend <= byteend)
{
- bankd_ptr[banknum] = (UINT8 *)base + bdata->base - start;
+ bankd_ptr[banknum] = (UINT8 *)base + bank->bytestart - bytestart;
found = TRUE;
/* if this is live, adjust now */
if (cpu_getactivecpu() >= 0 && cpunum == cur_context && opcode_entry == banknum)
force_opbase_update();
}
- else if (bdata->base < end && bdata->end > start)
- fatalerror("memory_set_decrypted_region found straddled region %08X-%08X for CPU %d", start, end, cpunum);
+ else if (bank->bytestart < byteend && bank->byteend > bytestart)
+ fatalerror("memory_set_decrypted_region found straddled region %08X-%08X for CPU %d", bytestart, byteend, cpunum);
}
}
if (!found)
- fatalerror("memory_set_decrypted_region unable to find matching region %08X-%08X for CPU %d", start, end, cpunum);
+ fatalerror("memory_set_decrypted_region unable to find matching region %08X-%08X for CPU %d", bytestart, byteend, cpunum);
}
@@ -856,22 +770,23 @@ void memory_set_decrypted_region(int cpunum, offs_t start, offs_t end, void *bas
and offset
-------------------------------------------------*/
-void *memory_get_read_ptr(int cpunum, int spacenum, offs_t offset)
+void *memory_get_read_ptr(int cpunum, int spacenum, offs_t byteaddress)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
+ offs_t byteoffset;
UINT8 entry;
/* perform the lookup */
- offset &= space->mask;
- entry = space->read.table[LEVEL1_INDEX(offset)];
+ byteaddress &= space->bytemask;
+ entry = space->read.table[LEVEL1_INDEX(byteaddress)];
if (entry >= SUBTABLE_BASE)
- entry = space->read.table[LEVEL2_INDEX(entry, offset)];
+ entry = space->read.table[LEVEL2_INDEX(entry, byteaddress)];
/* 8-bit case: RAM/ROM */
if (entry >= STATIC_RAM)
return NULL;
- offset = (offset - space->read.handlers[entry].offset) & space->read.handlers[entry].mask;
- return &bank_ptr[entry][offset];
+ byteoffset = (byteaddress - space->read.handlers[entry].bytestart) & space->read.handlers[entry].bytemask;
+ return &bank_ptr[entry][byteoffset];
}
@@ -881,22 +796,23 @@ void *memory_get_read_ptr(int cpunum, int spacenum, offs_t offset)
and offset
-------------------------------------------------*/
-void *memory_get_write_ptr(int cpunum, int spacenum, offs_t offset)
+void *memory_get_write_ptr(int cpunum, int spacenum, offs_t byteaddress)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
+ offs_t byteoffset;
UINT8 entry;
/* perform the lookup */
- offset &= space->mask;
- entry = space->write.table[LEVEL1_INDEX(offset)];
+ byteaddress &= space->bytemask;
+ entry = space->write.table[LEVEL1_INDEX(byteaddress)];
if (entry >= SUBTABLE_BASE)
- entry = space->write.table[LEVEL2_INDEX(entry, offset)];
+ entry = space->write.table[LEVEL2_INDEX(entry, byteaddress)];
/* 8-bit case: RAM/ROM */
if (entry >= STATIC_RAM)
return NULL;
- offset = (offset - space->write.handlers[entry].offset) & space->write.handlers[entry].mask;
- return &bank_ptr[entry][offset];
+ byteoffset = (byteaddress - space->write.handlers[entry].bytestart) & space->write.handlers[entry].bytemask;
+ return &bank_ptr[entry][byteoffset];
}
@@ -906,9 +822,10 @@ void *memory_get_write_ptr(int cpunum, int spacenum, offs_t offset)
CPU and offset
-------------------------------------------------*/
-void *memory_get_op_ptr(int cpunum, offs_t offset, int arg)
+void *memory_get_op_ptr(int cpunum, offs_t byteaddress, int arg)
{
addrspace_data *space = &cpudata[cpunum].space[ADDRESS_SPACE_PROGRAM];
+ offs_t byteoffset;
void *ptr = NULL;
UINT8 entry;
@@ -924,15 +841,15 @@ void *memory_get_op_ptr(int cpunum, offs_t offset, int arg)
UINT8 saved_opcode_entry = opcode_entry;
/* query the handler */
- offs_t new_offset = (*cpudata[cpunum].opbase)(Machine, offset);
+ offs_t new_byteaddress = (*cpudata[cpunum].opbase)(Machine, byteaddress);
/* if it returns ~0, we use whatever data the handler set */
- if (new_offset == ~0)
- ptr = arg ? &opcode_arg_base[offset] : &opcode_base[offset];
+ if (new_byteaddress == ~0)
+ ptr = arg ? &opcode_arg_base[byteaddress] : &opcode_base[byteaddress];
/* otherwise, we use the new offset in the generic case below */
else
- offset = new_offset;
+ byteaddress = new_byteaddress;
/* restore opcode info */
opcode_base = saved_opcode_base;
@@ -948,18 +865,18 @@ void *memory_get_op_ptr(int cpunum, offs_t offset, int arg)
}
/* perform the lookup */
- offset &= space->mask;
- entry = space->read.table[LEVEL1_INDEX(offset)];
+ byteaddress &= space->bytemask;
+ entry = space->read.table[LEVEL1_INDEX(byteaddress)];
if (entry >= SUBTABLE_BASE)
- entry = space->read.table[LEVEL2_INDEX(entry, offset)];
+ entry = space->read.table[LEVEL2_INDEX(entry, byteaddress)];
/* if a non-RAM area, return NULL */
if (entry >= STATIC_RAM)
return NULL;
/* adjust the offset */
- offset = (offset - space->read.handlers[entry].offset) & space->read.handlers[entry].mask;
- return (!arg && bankd_ptr[entry]) ? &bankd_ptr[entry][offset] : &bank_ptr[entry][offset];
+ byteoffset = (byteaddress - space->read.handlers[entry].bytestart) & space->read.handlers[entry].bytemask;
+ return (!arg && bankd_ptr[entry]) ? &bankd_ptr[entry][byteoffset] : &bank_ptr[entry][byteoffset];
}
@@ -1074,7 +991,7 @@ void memory_set_bankptr(int banknum, void *base)
if (base == NULL)
fatalerror("memory_set_bankptr called NULL base");
if (ALLOW_ONLY_AUTO_MALLOC_BANKS)
- validate_auto_malloc_memory(base, bankdata[banknum].end - bankdata[banknum].base + 1);
+ validate_auto_malloc_memory(base, bankdata[banknum].byteend - bankdata[banknum].bytestart + 1);
/* set the base */
bank_ptr[banknum] = base;
@@ -1122,46 +1039,46 @@ int memory_get_log_unmap(int spacenum)
read handler for X-bit case
-------------------------------------------------*/
-void *_memory_install_read_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR handler, const char *handler_name)
+void *_memory_install_read_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
if (handler >= STATIC_COUNT)
fatalerror("fatal: can only use static banks with memory_install_read_handler()");
- install_mem_handler(space, 0, space->dbits, start, end, mask, mirror, (genf *)(FPTR)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_READ, space->dbits, addrstart, addrend, addrmask, addrmirror, (genf *)(FPTR)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT8 *_memory_install_read8_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read8_machine_func handler, const char *handler_name)
+UINT8 *_memory_install_read8_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read8_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 8, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_READ, 8, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT16 *_memory_install_read16_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read16_machine_func handler, const char *handler_name)
+UINT16 *_memory_install_read16_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read16_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 16, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_READ, 16, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT32 *_memory_install_read32_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read32_machine_func handler, const char *handler_name)
+UINT32 *_memory_install_read32_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read32_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 32, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_READ, 32, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT64 *_memory_install_read64_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read64_machine_func handler, const char *handler_name)
+UINT64 *_memory_install_read64_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read64_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 64, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_READ, 64, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
@@ -1170,46 +1087,46 @@ UINT64 *_memory_install_read64_handler(int cpunum, int spacenum, offs_t start, o
write handler for X-bit case
-------------------------------------------------*/
-void *_memory_install_write_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR handler, const char *handler_name)
+void *_memory_install_write_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
if (handler >= STATIC_COUNT)
fatalerror("fatal: can only use static banks with memory_install_write_handler()");
- install_mem_handler(space, 1, space->dbits, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_WRITE, space->dbits, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 1, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 1, ADDR2BYTE(space, addrstart));
}
-UINT8 *_memory_install_write8_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write8_machine_func handler, const char *handler_name)
+UINT8 *_memory_install_write8_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write8_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 1, 8, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_WRITE, 8, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 1, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 1, ADDR2BYTE(space, addrstart));
}
-UINT16 *_memory_install_write16_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write16_machine_func handler, const char *handler_name)
+UINT16 *_memory_install_write16_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write16_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 1, 16, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_WRITE, 16, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 1, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 1, ADDR2BYTE(space, addrstart));
}
-UINT32 *_memory_install_write32_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write32_machine_func handler, const char *handler_name)
+UINT32 *_memory_install_write32_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write32_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 1, 32, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_WRITE, 32, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 1, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 1, ADDR2BYTE(space, addrstart));
}
-UINT64 *_memory_install_write64_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write64_machine_func handler, const char *handler_name)
+UINT64 *_memory_install_write64_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write64_machine_func handler, const char *handler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 1, 64, start, end, mask, mirror, (genf *)handler, 0, Machine, handler_name);
+ install_mem_handler(space, ROW_WRITE, 64, addrstart, addrend, addrmask, addrmirror, (genf *)handler, Machine, handler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 1, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 1, ADDR2BYTE(space, addrstart));
}
@@ -1218,51 +1135,51 @@ UINT64 *_memory_install_write64_handler(int cpunum, int spacenum, offs_t start,
dynamic read and write handlers for X-bit case
-------------------------------------------------*/
-void *_memory_install_readwrite_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR rhandler, FPTR whandler, const char *rhandler_name, const char *whandler_name)
+void *_memory_install_readwrite_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR rhandler, FPTR whandler, const char *rhandler_name, const char *whandler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
if (rhandler >= STATIC_COUNT || whandler >= STATIC_COUNT)
fatalerror("fatal: can only use static banks with memory_install_readwrite_handler()");
- install_mem_handler(space, 0, space->dbits, start, end, mask, mirror, (genf *)(FPTR)rhandler, 0, Machine, rhandler_name);
- install_mem_handler(space, 1, space->dbits, start, end, mask, mirror, (genf *)(FPTR)whandler, 0, Machine, whandler_name);
+ install_mem_handler(space, ROW_READ, space->dbits, addrstart, addrend, addrmask, addrmirror, (genf *)(FPTR)rhandler, Machine, rhandler_name);
+ install_mem_handler(space, ROW_WRITE, space->dbits, addrstart, addrend, addrmask, addrmirror, (genf *)(FPTR)whandler, Machine, whandler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT8 *_memory_install_readwrite8_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read8_machine_func rhandler, write8_machine_func whandler, const char *rhandler_name, const char *whandler_name)
+UINT8 *_memory_install_readwrite8_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read8_machine_func rhandler, write8_machine_func whandler, const char *rhandler_name, const char *whandler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 8, start, end, mask, mirror, (genf *)rhandler, 0, Machine, rhandler_name);
- install_mem_handler(space, 1, 8, start, end, mask, mirror, (genf *)whandler, 0, Machine, whandler_name);
+ install_mem_handler(space, ROW_READ, 8, addrstart, addrend, addrmask, addrmirror, (genf *)rhandler, Machine, rhandler_name);
+ install_mem_handler(space, ROW_WRITE, 8, addrstart, addrend, addrmask, addrmirror, (genf *)whandler, Machine, whandler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT16 *_memory_install_readwrite16_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read16_machine_func rhandler, write16_machine_func whandler, const char *rhandler_name, const char *whandler_name)
+UINT16 *_memory_install_readwrite16_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read16_machine_func rhandler, write16_machine_func whandler, const char *rhandler_name, const char *whandler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 16, start, end, mask, mirror, (genf *)rhandler, 0, Machine, rhandler_name);
- install_mem_handler(space, 1, 16, start, end, mask, mirror, (genf *)whandler, 0, Machine, whandler_name);
+ install_mem_handler(space, ROW_READ, 16, addrstart, addrend, addrmask, addrmirror, (genf *)rhandler, Machine, rhandler_name);
+ install_mem_handler(space, ROW_WRITE, 16, addrstart, addrend, addrmask, addrmirror, (genf *)whandler, Machine, whandler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT32 *_memory_install_readwrite32_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read32_machine_func rhandler, write32_machine_func whandler, const char *rhandler_name, const char *whandler_name)
+UINT32 *_memory_install_readwrite32_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read32_machine_func rhandler, write32_machine_func whandler, const char *rhandler_name, const char *whandler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 32, start, end, mask, mirror, (genf *)rhandler, 0, Machine, rhandler_name);
- install_mem_handler(space, 1, 32, start, end, mask, mirror, (genf *)whandler, 0, Machine, whandler_name);
+ install_mem_handler(space, ROW_READ, 32, addrstart, addrend, addrmask, addrmirror, (genf *)rhandler, Machine, rhandler_name);
+ install_mem_handler(space, ROW_WRITE, 32, addrstart, addrend, addrmask, addrmirror, (genf *)whandler, Machine, whandler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
-UINT64 *_memory_install_readwrite64_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read64_machine_func rhandler, write64_machine_func whandler, const char *rhandler_name, const char *whandler_name)
+UINT64 *_memory_install_readwrite64_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read64_machine_func rhandler, write64_machine_func whandler, const char *rhandler_name, const char *whandler_name)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
- install_mem_handler(space, 0, 64, start, end, mask, mirror, (genf *)rhandler, 0, Machine, rhandler_name);
- install_mem_handler(space, 1, 64, start, end, mask, mirror, (genf *)whandler, 0, Machine, whandler_name);
+ install_mem_handler(space, ROW_READ, 64, addrstart, addrend, addrmask, addrmirror, (genf *)rhandler, Machine, rhandler_name);
+ install_mem_handler(space, ROW_WRITE, 64, addrstart, addrend, addrmask, addrmirror, (genf *)whandler, Machine, whandler_name);
mem_dump();
- return memory_find_base(cpunum, spacenum, 0, SPACE_SHIFT(space, start));
+ return memory_find_base(cpunum, spacenum, 0, ADDR2BYTE(space, addrstart));
}
@@ -1310,244 +1227,338 @@ void address_map_free(address_map *map)
/*-------------------------------------------------
- init_cpudata - initialize the cpudata
- structure for each CPU
+ address_map_detokenize - detokenize an array
+ of address map tokens
-------------------------------------------------*/
-static void init_cpudata(void)
+static void address_map_detokenize(address_map *map, const addrmap_token *tokens)
{
- int cpunum, spacenum;
+ address_map_entry **entryptr;
+ address_map_entry *entry;
+ UINT8 spacenum, databits;
+ UINT32 entrytype;
+
+ /* check the first token */
+ TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, spacenum, 8, databits, 8);
+ if (entrytype != ADDRMAP_TOKEN_START)
+ fatalerror("Address map missing ADDRMAP_TOKEN_START!");
+ if (spacenum >= ADDRESS_SPACES)
+ fatalerror("Invalid address space %d for memory map!", spacenum);
+ if (databits != 8 && databits != 16 && databits != 32 && databits != 64)
+ fatalerror("Invalid data bits %d for memory map!", databits);
+ if (map->spacenum != 0 && map->spacenum != spacenum)
+ fatalerror("Included a mismatched address map (space %d) for an existing map of type %d!\n", spacenum, map->spacenum);
+ if (map->databits != 0 && map->databits != databits)
+ fatalerror("Included a mismatched address map (databits %d) for an existing map with databits %d!\n", databits, map->databits);
+
+ /* fill in the map values */
+ map->spacenum = spacenum;
+ map->databits = databits;
- /* zap the cpudata structure */
- memset(&cpudata, 0, sizeof(cpudata));
+ /* find the end of the list */
+ for (entryptr = &map->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) ;
+ entry = NULL;
- /* loop over CPUs */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ /* loop over tokens until we hit the end */
+ while (entrytype != ADDRMAP_TOKEN_END)
{
- /* set the RAM/ROM base */
- cpudata[cpunum].op_ram = cpudata[cpunum].op_rom = memory_region(REGION_CPU1 + cpunum);
- cpudata[cpunum].op_mem_max = memory_region_length(REGION_CPU1 + cpunum);
- cpudata[cpunum].op_mem_min = 0;
- cpudata[cpunum].opcode_entry = STATIC_UNMAP;
- cpudata[cpunum].opbase = NULL;
-
- /* TODO: make this dynamic */
- cpudata[cpunum].spacemask = 0;
- for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
- init_addrspace(cpunum, spacenum);
- cpudata[cpunum].op_mask = cpudata[cpunum].space[ADDRESS_SPACE_PROGRAM].mask;
- }
-}
+ /* unpack the token from the first entry */
+ TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8);
+ switch (entrytype)
+ {
+ /* end */
+ case ADDRMAP_TOKEN_END:
+ break;
+ /* including */
+ case ADDRMAP_TOKEN_INCLUDE:
+ address_map_detokenize(map, TOKEN_GET_PTR(tokens, tokenptr));
+ for (entryptr = &map->entrylist; *entryptr != NULL; entryptr = &(*entryptr)->next) ;
+ entry = NULL;
+ break;
-/*-------------------------------------------------
- adjust_addresses - adjust addresses for a
- given address space in a standard fashion
--------------------------------------------------*/
+ /* global flags */
+ case ADDRMAP_TOKEN_GLOBAL_MASK:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, map->globalmask, 32);
+ break;
+
+ case ADDRMAP_TOKEN_UNMAP_VALUE:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, map->unmapval, 1);
+ break;
-INLINE void adjust_addresses(addrspace_data *space, offs_t *start, offs_t *end, offs_t *mask, offs_t *mirror)
-{
- /* adjust start/end/mask values */
- if (*mask == 0)
- *mask = space->rawmask & ~*mirror;
- else
- *mask &= space->rawmask;
- *start &= ~*mirror & space->rawmask;
- *end &= ~*mirror & space->rawmask;
+ /* start a new range */
+ case ADDRMAP_TOKEN_RANGE:
+ entry = *entryptr = malloc_or_die(sizeof(**entryptr));
+ entryptr = &entry->next;
+ memset(entry, 0, sizeof(*entry));
+ TOKEN_GET_UINT64_UNPACK2(tokens, entry->addrstart, 32, entry->addrend, 32);
+ break;
+
+ case ADDRMAP_TOKEN_MASK:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, entry->addrmask, 32);
+ break;
+
+ case ADDRMAP_TOKEN_MIRROR:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, entry->addrmirror, 32);
+ break;
+
+ case ADDRMAP_TOKEN_READ:
+ entry->read = TOKEN_GET_PTR(tokens, read);
+ entry->read_name = TOKEN_GET_STRING(tokens);
+ break;
- /* adjust to byte values */
- *mask = SPACE_SHIFT(space, *mask);
- *start = SPACE_SHIFT(space, *start);
- *end = SPACE_SHIFT_END(space, *end);
- *mirror = SPACE_SHIFT(space, *mirror);
+ case ADDRMAP_TOKEN_WRITE:
+ entry->write = TOKEN_GET_PTR(tokens, write);
+ entry->write_name = TOKEN_GET_STRING(tokens);
+ break;
+
+ case ADDRMAP_TOKEN_DEVICE_READ:
+ entry->read = TOKEN_GET_PTR(tokens, read);
+ entry->read_name = TOKEN_GET_STRING(tokens);
+ entry->read_devtype = TOKEN_GET_PTR(tokens, devtype);
+ entry->read_devtag = TOKEN_GET_STRING(tokens);
+ break;
+
+ case ADDRMAP_TOKEN_DEVICE_WRITE:
+ entry->write = TOKEN_GET_PTR(tokens, write);
+ entry->write_name = TOKEN_GET_STRING(tokens);
+ entry->write_devtype = TOKEN_GET_PTR(tokens, devtype);
+ entry->write_devtag = TOKEN_GET_STRING(tokens);
+ break;
+
+ case ADDRMAP_TOKEN_READ_PORT:
+ switch (map->databits)
+ {
+ case 8: entry->read.mhandler8 = port_tag_to_handler8(TOKEN_GET_STRING(tokens)); break;
+ case 16: entry->read.mhandler16 = port_tag_to_handler16(TOKEN_GET_STRING(tokens)); break;
+ case 32: entry->read.mhandler32 = port_tag_to_handler32(TOKEN_GET_STRING(tokens)); break;
+ case 64: entry->read.mhandler64 = port_tag_to_handler64(TOKEN_GET_STRING(tokens)); break;
+ }
+ break;
+
+ case ADDRMAP_TOKEN_REGION:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT64_UNPACK3(tokens, entrytype, 8, entry->region, 24, entry->region_offs, 32);
+ break;
+
+ case ADDRMAP_TOKEN_SHARE:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->share, 24);
+ break;
+
+ case ADDRMAP_TOKEN_BASEPTR:
+ entry->baseptr = (void **)TOKEN_GET_PTR(tokens, voidptr);
+ break;
+
+ case ADDRMAP_TOKEN_BASE_MEMBER:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->baseptroffs_plus1, 24);
+ entry->baseptroffs_plus1++;
+ break;
+
+ case ADDRMAP_TOKEN_SIZEPTR:
+ entry->sizeptr = TOKEN_GET_PTR(tokens, sizeptr);
+ break;
+
+ case ADDRMAP_TOKEN_SIZE_MEMBER:
+ TOKEN_UNGET_UINT32(tokens);
+ TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, entry->sizeptroffs_plus1, 24);
+ entry->sizeptroffs_plus1++;
+ break;
+
+ default:
+ fatalerror("Invalid token %d in address map\n", entrytype);
+ break;
+ }
+ }
}
/*-------------------------------------------------
- init_addrspace - initialize the address space
- data structure
+ memory_init_cpudata - initialize the cpudata
+ structure for each CPU
-------------------------------------------------*/
-static void init_addrspace(UINT8 cpunum, UINT8 spacenum)
+static void memory_init_cpudata(const machine_config *config)
{
- addrspace_data *space = &cpudata[cpunum].space[spacenum];
- cpu_type cputype = Machine->config->cpu[cpunum].type;
- int abits = cputype_addrbus_width(cputype, spacenum);
- int dbits = cputype_databus_width(cputype, spacenum);
- int accessorindex = (dbits == 8) ? 0 : (dbits == 16) ? 1 : (dbits == 32) ? 2 : 3;
- int entrynum;
+ int cpunum, spacenum;
- /* determine the address and data bits */
- space->cpunum = cpunum;
- space->spacenum = spacenum;
- space->ashift = cputype_addrbus_shift(cputype, spacenum);
- space->abits = abits - space->ashift;
- space->dbits = dbits;
- space->rawmask = 0xffffffffUL >> (32 - abits);
- space->mask = SPACE_SHIFT_END(space, space->rawmask);
- space->accessors = &memory_accessors[spacenum][accessorindex][cputype_endianness(cputype) == CPU_IS_LE ? 0 : 1];
- space->map = NULL;
-
- /* if there's nothing here, just punt */
- if (space->abits == 0)
- return;
- cpudata[cpunum].spacemask |= 1 << spacenum;
+ /* zap the cpudata structure */
+ memset(&cpudata, 0, sizeof(cpudata));
- /* construct the combined memory map */
+ /* loop over CPUs */
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
{
- address_map_entry *entry;
-
- /* allocate the address map */
- space->map = address_map_alloc(Machine->config, cpunum, spacenum);
+ cpu_type cputype = config->cpu[cpunum].type;
+ cpu_data *cpu = &cpudata[cpunum];
- /* convert implicit ROM entries to map to the memory region */
- if (spacenum == ADDRESS_SPACE_PROGRAM && memory_region(REGION_CPU1 + cpunum))
- for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
- if (HANDLER_IS_ROM(entry->read.handler) && entry->region == 0)
- {
- offs_t end = SPACE_SHIFT_END(space, entry->end);
-
- /* make sure they fit within the memory region before doing so, however */
- if (end < memory_region_length(REGION_CPU1 + cpunum))
- {
- entry->region = REGION_CPU1 + cpunum;
- entry->region_offs = SPACE_SHIFT(space, entry->start);
- }
- }
-
- /* convert region-relative entries to their memory pointers */
- for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
- if (entry->region != 0)
- entry->memory = memory_region(entry->region) + entry->region_offs;
+ /* get pointers to the CPU's memory region */
+ cpu->region = memory_region(REGION_CPU1 + cpunum);
+ cpu->regionsize = memory_region_length(REGION_CPU1 + cpunum);
- /* make the adjusted map */
- for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
+ /* initialize each address space, and build up a mask of spaces */
+ for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
{
- entry->bytestart = entry->start;
- entry->byteend = entry->end;
- entry->bytemirror = entry->mirror;
- entry->bytemask = entry->mask;
- adjust_addresses(space, &entry->bytestart, &entry->byteend, &entry->bytemask, &entry->bytemirror);
- }
+ addrspace_data *space = &cpu->space[spacenum];
+ int entrynum;
+
+ /* determine the address and data bits */
+ space->cpunum = cpunum;
+ space->spacenum = spacenum;
+ space->ashift = cputype_addrbus_shift(cputype, spacenum);
+ space->abits = cputype_addrbus_width(cputype, spacenum);
+ space->dbits = cputype_databus_width(cputype, spacenum);
+ space->addrmask = 0xffffffffUL >> (32 - space->abits);
+ space->bytemask = ADDR2BYTE_END(space, space->addrmask);
+ space->accessors = memory_get_accessors(spacenum, space->dbits, cputype_endianness(cputype));
+ space->map = NULL;
+
+ /* if there's nothing here, just punt */
+ if (space->abits == 0)
+ continue;
+ cpu->spacemask |= 1 << spacenum;
- /* validate adjusted addresses against implicit regions */
- for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
- if (entry->region != 0 && entry->share == 0 && entry->baseptr == NULL)
+ /* init the static handlers */
+ memset(space->read.handlers, 0, sizeof(space->read.handlers));
+ memset(space->write.handlers, 0, sizeof(space->write.handlers));
+ for (entrynum = 0; entrynum < ENTRY_COUNT; entrynum++)
{
- UINT8 *base = memory_region(entry->region);
- offs_t length = memory_region_length(entry->region);
-
- /* validate the region */
- if (base == NULL)
- fatalerror("Error: CPU %d space %d memory map entry %X-%X references non-existant region %d", cpunum, spacenum, entry->start, entry->end, entry->region);
- if (entry->region_offs + (entry->byteend - entry->bytestart + 1) > length)
- fatalerror("Error: CPU %d space %d memory map entry %X-%X extends beyond region %d size (%X)", cpunum, spacenum, entry->start, entry->end, entry->region, length);
+ space->read.handlers[entrynum].handler.generic = get_static_handler(space->dbits, 0, spacenum, entrynum);
+ space->write.handlers[entrynum].handler.generic = get_static_handler(space->dbits, 1, spacenum, entrynum);
}
- }
- /* init the static handlers */
- memset(space->read.handlers, 0, sizeof(space->read.handlers));
- memset(space->write.handlers, 0, sizeof(space->write.handlers));
- for (entrynum = 0; entrynum < ENTRY_COUNT; entrynum++)
- {
- space->read.handlers[entrynum].handler.generic = get_static_handler(dbits, 0, spacenum, entrynum);
- space->read.handlers[entrynum].mask = space->mask;
- space->write.handlers[entrynum].handler.generic = get_static_handler(dbits, 1, spacenum, entrynum);
- space->write.handlers[entrynum].mask = space->mask;
- }
+ /* allocate memory */
+ space->read.table = malloc_or_die(1 << LEVEL1_BITS);
+ space->write.table = malloc_or_die(1 << LEVEL1_BITS);
- /* allocate memory */
- space->read.table = malloc_or_die(1 << LEVEL1_BITS);
- space->write.table = malloc_or_die(1 << LEVEL1_BITS);
+ /* initialize everything to unmapped */
+ memset(space->read.table, STATIC_UNMAP, 1 << LEVEL1_BITS);
+ memset(space->write.table, STATIC_UNMAP, 1 << LEVEL1_BITS);
+ }
- /* initialize everything to unmapped */
- memset(space->read.table, STATIC_UNMAP, 1 << LEVEL1_BITS);
- memset(space->write.table, STATIC_UNMAP, 1 << LEVEL1_BITS);
+ /* set the RAM/ROM base */
+ cpu->op_ram = cpu->op_rom = memory_region(REGION_CPU1 + cpunum);
+ cpu->op_mask = cpu->space[ADDRESS_SPACE_PROGRAM].bytemask;
+ cpu->op_mem_min = 0;
+ cpu->op_mem_max = memory_region_length(REGION_CPU1 + cpunum);
+ cpu->opcode_entry = STATIC_UNMAP;
+ cpu->opbase = NULL;
+ }
}
/*-------------------------------------------------
- preflight_memory - verify the memory structs
+ memory_init_preflight - verify the memory structs
and track which banks are referenced
-------------------------------------------------*/
-static void preflight_memory(void)
+static void memory_init_preflight(const machine_config *config)
{
- int cpunum, spacenum, entrynum;
+ int cpunum;
/* zap the bank data */
memset(&bankdata, 0, sizeof(bankdata));
/* loop over CPUs */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
+ {
+ cpu_data *cpu = &cpudata[cpunum];
+ int spacenum;
+
+ /* loop over valid address spaces */
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
- if (cpudata[cpunum].spacemask & (1 << spacenum))
+ if (cpu->spacemask & (1 << spacenum))
{
- addrspace_data *space = &cpudata[cpunum].space[spacenum];
- const address_map_entry *entry;
+ addrspace_data *space = &cpu->space[spacenum];
+ address_map_entry *entry;
+ int entrynum;
+ /* allocate the address map */
+ space->map = address_map_alloc(config, cpunum, spacenum);
+
+ /* extract global parameters specified by the map */
+ space->unmap = (space->map->unmapval == 0) ? 0 : ~0;
if (space->map->globalmask != 0)
{
- space->rawmask = space->map->globalmask;
- space->mask = SPACE_SHIFT_END(space, space->rawmask);
+ space->addrmask = space->map->globalmask;
+ space->bytemask = ADDR2BYTE_END(space, space->addrmask);
}
- space->unmap = (space->map->unmapval == 0) ? 0 : ~0;
- /* scan the adjusted map */
+ /* make a pass over the address map, adjusting for the CPU and getting memory pointers */
for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
{
- int bank = -1;
-
- /* look for a bank handler in eithe read or write */
- if (HANDLER_IS_BANK(entry->read.handler))
- bank = HANDLER_TO_BANK(entry->read.handler);
- else if (HANDLER_IS_BANK(entry->write.handler))
- bank = HANDLER_TO_BANK(entry->write.handler);
+ read_or_write bankaccess = 0;
+ int banknum = -1;
+
+ /* computed adjusted addresses first */
+ entry->bytestart = entry->addrstart;
+ entry->byteend = entry->addrend;
+ entry->bytemirror = entry->addrmirror;
+ entry->bytemask = entry->addrmask;
+ adjust_addresses(space, &entry->bytestart, &entry->byteend, &entry->bytemask, &entry->bytemirror);
+
+ /* if this is a ROM handler without a specified region, attach it to the implicit region */
+ if (spacenum == ADDRESS_SPACE_PROGRAM && HANDLER_IS_ROM(entry->read.handler) && entry->region == 0)
+ {
+ /* make sure it fits within the memory region before doing so, however */
+ if (entry->byteend < cpu->regionsize)
+ {
+ entry->region = REGION_CPU1 + cpunum;
+ entry->region_offs = entry->bytestart;
+ }
+ }
- /* if we got one, add the data */
- if (bank >= 1 && bank <= MAX_EXPLICIT_BANKS)
+ /* validate adjusted addresses against implicit regions */
+ if (entry->region != 0 && entry->share == 0 && entry->baseptr == NULL)
{
- bank_data *bdata = &bankdata[bank];
-
- /* wire up state saving for the entry the first time we see it */
- if (!bdata->used)
- state_save_register_item("memory", bank, bdata->curentry);
-
- bdata->used = TRUE;
- bdata->dynamic = FALSE;
- bdata->cpunum = cpunum;
- bdata->spacenum = spacenum;
- if (bank == HANDLER_TO_BANK(entry->read.handler))
- bdata->read = TRUE;
- if (bank == HANDLER_TO_BANK(entry->write.handler))
- bdata->write = TRUE;
- bdata->base = entry->bytestart;
- bdata->end = entry->byteend;
- bdata->curentry = MAX_BANK_ENTRIES;
+ UINT8 *base = memory_region(entry->region);
+ offs_t length = memory_region_length(entry->region);
+
+ /* validate the region */
+ if (base == NULL)
+ fatalerror("Error: CPU %d space %d memory map entry %X-%X references non-existant region %d", cpunum, spacenum, entry->addrstart, entry->addrend, entry->region);
+ if (entry->region_offs + (entry->byteend - entry->bytestart + 1) > length)
+ fatalerror("Error: CPU %d space %d memory map entry %X-%X extends beyond region %d size (%X)", cpunum, spacenum, entry->addrstart, entry->addrend, entry->region, length);
}
+
+ /* convert any region-relative entries to their memory pointers */
+ if (entry->region != 0)
+ entry->memory = memory_region(entry->region) + entry->region_offs;
+
+ /* assign static banks for explicitly specified entries */
+ if (HANDLER_IS_BANK(entry->read.handler))
+ bank_assign_static(HANDLER_TO_BANK(entry->read.handler), cpunum, spacenum, ROW_READ, entry->bytestart, entry->byteend);
+ if (HANDLER_IS_BANK(entry->write.handler))
+ bank_assign_static(HANDLER_TO_BANK(entry->write.handler), cpunum, spacenum, ROW_WRITE, entry->bytestart, entry->byteend);
}
- /* now loop over all the handlers and enforce the address mask (which may have changed) */
+ /* now loop over all the handlers and enforce the address mask */
+ /* we don't loop over map entries because the mask applies to static handlers as well */
for (entrynum = 0; entrynum < ENTRY_COUNT; entrynum++)
{
- space->read.handlers[entrynum].mask &= space->mask;
- space->write.handlers[entrynum].mask &= space->mask;
+ space->read.handlers[entrynum].bytemask &= space->bytemask;
+ space->write.handlers[entrynum].bytemask &= space->bytemask;
}
}
+ }
}
/*-------------------------------------------------
- populate_memory - populate the memory mapping
- tables with entries
+ memory_init_populate - populate the memory
+ mapping tables with entries
-------------------------------------------------*/
-static void populate_memory(void)
+static void memory_init_populate(running_machine *machine)
{
int cpunum, spacenum;
/* loop over CPUs and address spaces */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
if (cpudata[cpunum].spacemask & (1 << spacenum))
{
@@ -1561,35 +1572,32 @@ static void populate_memory(void)
while (last_entry != space->map->entrylist)
{
const address_map_entry *entry;
- int isfixed;
/* find the entry before the last one we processed */
for (entry = space->map->entrylist; entry->next != last_entry; entry = entry->next) ;
last_entry = entry;
- isfixed = (entry->memory != NULL) || (entry->share != 0);
-
if (entry->read.handler != NULL)
{
- void *object = Machine;
+ void *object = machine;
if (entry->read_devtype != NULL)
{
- object = (void *)device_list_find_by_tag(Machine->config->devicelist, entry->read_devtype, entry->read_devtag);
+ object = (void *)device_list_find_by_tag(machine->config->devicelist, entry->read_devtype, entry->read_devtag);
if (object == NULL)
fatalerror("Unidentified object in memory map: type=%s tag=%s\n", devtype_name(entry->read_devtype), entry->read_devtag);
}
- install_mem_handler_private(space, 0, space->dbits, entry->start, entry->end, entry->mask, entry->mirror, entry->read.handler, isfixed, object, entry->read_name);
+ install_mem_handler_private(space, ROW_READ, space->dbits, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, entry->read.handler, object, entry->read_name);
}
if (entry->write.handler != NULL)
{
- void *object = Machine;
+ void *object = machine;
if (entry->write_devtype != NULL)
{
- object = (void *)device_list_find_by_tag(Machine->config->devicelist, entry->write_devtype, entry->write_devtag);
+ object = (void *)device_list_find_by_tag(machine->config->devicelist, entry->write_devtype, entry->write_devtag);
if (object == NULL)
fatalerror("Unidentified object in memory map: type=%s tag=%s\n", devtype_name(entry->write_devtype), entry->write_devtag);
}
- install_mem_handler_private(space, 1, space->dbits, entry->start, entry->end, entry->mask, entry->mirror, entry->write.handler, isfixed, object, entry->write_name);
+ install_mem_handler_private(space, ROW_WRITE, space->dbits, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, entry->write.handler, object, entry->write_name);
}
}
}
@@ -1604,32 +1612,31 @@ static void populate_memory(void)
banks to dynamically assigned banks
-------------------------------------------------*/
-static void install_mem_handler_private(addrspace_data *space, int iswrite, int databits, offs_t start, offs_t end, offs_t mask, offs_t mirror, genf *handler, int isfixed, void *object, const char *handler_name)
+static void install_mem_handler_private(addrspace_data *space, read_or_write readorwrite, int databits, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, genf *handler, void *object, const char *handler_name)
{
/* translate ROM to RAM/UNMAP here */
if (HANDLER_IS_ROM(handler))
- handler = iswrite ? (genf *)STATIC_UNMAP : (genf *)SMH_RAM;
+ handler = (readorwrite == ROW_WRITE) ? (genf *)STATIC_UNMAP : (genf *)SMH_RAM;
/* assign banks for RAM/ROM areas */
if (HANDLER_IS_RAM(handler))
{
- int ismasked = (mask != 0);
- offs_t temp_start = start;
- offs_t temp_end = end;
- offs_t temp_mask = mask;
- offs_t temp_mirror = mirror;
+ offs_t bytestart = addrstart;
+ offs_t byteend = addrend;
+ offs_t bytemask = addrmask;
+ offs_t bytemirror = addrmirror;
/* adjust the incoming addresses (temporarily) */
- adjust_addresses(space, &temp_start, &temp_end, &temp_mask, &temp_mirror);
+ adjust_addresses(space, &bytestart, &byteend, &bytemask, &bytemirror);
/* assign a bank to the adjusted addresses */
- handler = (genf *)assign_dynamic_bank(space->cpunum, space->spacenum, temp_start, temp_end, temp_mirror, isfixed, ismasked);
+ handler = (genf *)bank_assign_dynamic(space->cpunum, space->spacenum, readorwrite, bytestart, byteend);
if (bank_ptr[HANDLER_TO_BANK(handler)] == NULL)
- bank_ptr[HANDLER_TO_BANK(handler)] = memory_find_base(space->cpunum, space->spacenum, iswrite, temp_start);
+ bank_ptr[HANDLER_TO_BANK(handler)] = memory_find_base(space->cpunum, space->spacenum, readorwrite, bytestart);
}
/* then do a normal installation */
- install_mem_handler(space, iswrite, databits, start, end, mask, mirror, handler, isfixed, object, handler_name);
+ install_mem_handler(space, readorwrite, databits, addrstart, addrend, addrmask, addrmirror, handler, object, handler_name);
}
@@ -1638,10 +1645,11 @@ static void install_mem_handler_private(addrspace_data *space, int iswrite, int
memory operations
-------------------------------------------------*/
-static void install_mem_handler(addrspace_data *space, int iswrite, int databits, offs_t start, offs_t end, offs_t mask, offs_t mirror, genf *handler, int isfixed, void *object, const char *handler_name)
+static void install_mem_handler(addrspace_data *space, read_or_write readorwrite, int databits, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, genf *handler, void *object, const char *handler_name)
{
offs_t lmirrorbit[LEVEL2_BITS], lmirrorbits, hmirrorbit[32 - LEVEL2_BITS], hmirrorbits, lmirrorcount, hmirrorcount;
- table_data *tabledata = iswrite ? &space->write : &space->read;
+ table_data *tabledata = (readorwrite == ROW_WRITE) ? &space->write : &space->read;
+ offs_t bytestart, byteend, bytemask, bytemirror;
UINT8 idx, prev_entry = STATIC_INVALID;
int cur_index, prev_index = 0;
int i;
@@ -1651,59 +1659,31 @@ static void install_mem_handler(addrspace_data *space, int iswrite, int databits
fatalerror("fatal: install_mem_handler called with ROM or RAM after initialization");
if (space->dbits != databits)
fatalerror("fatal: install_mem_handler called with a %d-bit handler for a %d-bit address space", databits, space->dbits);
- if (start > end)
+ if (addrstart > addrend)
fatalerror("fatal: install_mem_handler called with start greater than end");
- /* if we're installing a new bank, make sure we mark it */
- if (HANDLER_IS_BANK(handler))
- {
- bank_data *bdata = &bankdata[HANDLER_TO_BANK(handler)];
-
- /* if this is the first time we've seen this bank, create a new entry */
- if (!bdata->used)
- {
- bdata->used = TRUE;
- bdata->dynamic = FALSE;
- bdata->cpunum = space->cpunum;
- bdata->spacenum = space->spacenum;
- bdata->base = start;
- bdata->end = end;
- bdata->curentry = MAX_BANK_ENTRIES;
-
- /* if we're allowed to, wire up state saving for the entry */
- if (state_save_registration_allowed())
- state_save_register_item("memory", HANDLER_TO_BANK(handler), bdata->curentry);
-
- VPRINTF(("Allocated new bank %d\n", HANDLER_TO_BANK(handler)));
- }
- }
-
/* adjust the incoming addresses */
- adjust_addresses(space, &start, &end, &mask, &mirror);
+ bytestart = addrstart;
+ byteend = addrend;
+ bytemirror = addrmirror;
+ bytemask = addrmask;
+ adjust_addresses(space, &bytestart, &byteend, &bytemask, &bytemirror);
- /* if this ended up a bank handler, tag it for reads or writes */
+ /* if we're installing a new bank, make sure we mark it */
if (HANDLER_IS_BANK(handler))
- {
- bank_data *bdata = &bankdata[HANDLER_TO_BANK(handler)];
-
- /* track whether reads or writes are going here */
- if (!iswrite)
- bdata->read = TRUE;
- else
- bdata->write = TRUE;
- }
+ bank_assign_static(HANDLER_TO_BANK(handler), space->cpunum, space->spacenum, readorwrite, bytestart, byteend);
/* determine the mirror bits */
hmirrorbits = lmirrorbits = 0;
for (i = 0; i < LEVEL2_BITS; i++)
- if (mirror & (1 << i))
+ if (bytemirror & (1 << i))
lmirrorbit[lmirrorbits++] = 1 << i;
for (i = LEVEL2_BITS; i < 32; i++)
- if (mirror & (1 << i))
+ if (bytemirror & (1 << i))
hmirrorbit[hmirrorbits++] = 1 << i;
/* get the final handler index */
- idx = get_handler_index(tabledata->handlers, object, handler, handler_name, start, end, mask);
+ idx = get_handler_index(tabledata->handlers, object, handler, handler_name, bytestart, byteend, bytemask);
/* loop over mirrors in the level 2 table */
for (hmirrorcount = 0; hmirrorcount < (1 << hmirrorbits); hmirrorcount++)
@@ -1717,8 +1697,8 @@ static void install_mem_handler(addrspace_data *space, int iswrite, int databits
/* if this is not our first time through, and the level 2 entry matches the previous
level 2 entry, just do a quick map and get out; note that this only works for entries
which don't span multiple level 1 table entries */
- cur_index = LEVEL1_INDEX(start + hmirrorbase);
- if (cur_index == LEVEL1_INDEX(end + hmirrorbase))
+ cur_index = LEVEL1_INDEX(bytestart + hmirrorbase);
+ if (cur_index == LEVEL1_INDEX(byteend + hmirrorbase))
{
if (hmirrorcount != 0 && prev_entry == tabledata->table[cur_index])
{
@@ -1726,11 +1706,11 @@ static void install_mem_handler(addrspace_data *space, int iswrite, int databits
/* release the subtable if the old value was a subtable */
if (tabledata->table[cur_index] >= SUBTABLE_BASE)
- release_subtable(tabledata, tabledata->table[cur_index]);
+ subtable_release(tabledata, tabledata->table[cur_index]);
/* reallocate the subtable if the new value is a subtable */
if (tabledata->table[prev_index] >= SUBTABLE_BASE)
- reallocate_subtable(tabledata, tabledata->table[prev_index]);
+ subtable_realloc(tabledata, tabledata->table[prev_index]);
/* set the new value and short-circuit the mapping step */
tabledata->table[cur_index] = tabledata->table[prev_index];
@@ -1750,7 +1730,7 @@ static void install_mem_handler(addrspace_data *space, int iswrite, int databits
lmirrorbase |= lmirrorbit[i];
/* populate the tables */
- populate_table_range(space, iswrite, start + lmirrorbase, end + lmirrorbase, idx);
+ populate_table_range(space, readorwrite, bytestart + lmirrorbase, byteend + lmirrorbase, idx);
}
}
@@ -1761,27 +1741,64 @@ static void install_mem_handler(addrspace_data *space, int iswrite, int databits
/*-------------------------------------------------
- assign_dynamic_bank - finds a free or exact
+ bank_assign_static - assign and tag a static
+ bank
+-------------------------------------------------*/
+
+static void bank_assign_static(int banknum, int cpunum, int spacenum, read_or_write readorwrite, offs_t bytestart, offs_t byteend)
+{
+ bank_info *bank = &bankdata[banknum];
+
+ /* if we're not yet used, fill in the data */
+ if (!bank->used)
+ {
+ /* if we're allowed to, wire up state saving for the entry */
+ if (state_save_registration_allowed())
+ state_save_register_item("memory", banknum, bank->curentry);
+
+ /* fill in information about the bank */
+ bank->used = TRUE;
+ bank->dynamic = FALSE;
+ bank->cpunum = cpunum;
+ bank->spacenum = spacenum;
+ bank->bytestart = bytestart;
+ bank->byteend = byteend;
+ bank->curentry = MAX_BANK_ENTRIES;
+ }
+
+ /* update the read/write status of the bank */
+ if (readorwrite == ROW_READ)
+ bank->read = TRUE;
+ else
+ bank->write = TRUE;
+}
+
+
+/*-------------------------------------------------
+ bank_assign_dynamic - finds a free or exact
matching bank
-------------------------------------------------*/
-static genf *assign_dynamic_bank(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mirror, int isfixed, int ismasked)
+static genf *bank_assign_dynamic(int cpunum, int spacenum, read_or_write readorwrite, offs_t bytestart, offs_t byteend)
{
- int bank;
+ int banknum;
/* loop over banks, searching for an exact match or an empty */
- for (bank = MAX_BANKS; bank >= 1; bank--)
- if (!bankdata[bank].used || (bankdata[bank].dynamic && bankdata[bank].cpunum == cpunum && bankdata[bank].spacenum == spacenum && bankdata[bank].base == start))
+ for (banknum = MAX_BANKS; banknum >= 1; banknum--)
+ {
+ bank_info *bank = &bankdata[banknum];
+ if (!bank->used || (bank->dynamic && bank->cpunum == cpunum && bank->spacenum == spacenum && bank->bytestart == bytestart))
{
- bankdata[bank].used = TRUE;
- bankdata[bank].dynamic = TRUE;
- bankdata[bank].cpunum = cpunum;
- bankdata[bank].spacenum = spacenum;
- bankdata[bank].base = start;
- bankdata[bank].end = end;
- VPRINTF(("Assigned bank %d to %d,%d,%08X\n", bank, cpunum, spacenum, start));
- return BANK_TO_HANDLER(bank);
+ bank->used = TRUE;
+ bank->dynamic = TRUE;
+ bank->cpunum = cpunum;
+ bank->spacenum = spacenum;
+ bank->bytestart = bytestart;
+ bank->byteend = byteend;
+ VPRINTF(("Assigned bank %d to %d,%d,%08X\n", bank, cpunum, spacenum, bytestart));
+ return BANK_TO_HANDLER(banknum);
}
+ }
/* if we got here, we failed */
fatalerror("cpu #%d: ran out of banks for RAM/ROM regions!", cpunum);
@@ -1794,11 +1811,11 @@ static genf *assign_dynamic_bank(int cpunum, int spacenum, offs_t start, offs_t
handler, or allocates a new one as necessary
-------------------------------------------------*/
-static UINT8 get_handler_index(handler_data *table, void *object, genf *handler, const char *handler_name, offs_t start, offs_t end, offs_t mask)
+static UINT8 get_handler_index(handler_data *table, void *object, genf *handler, const char *handler_name, offs_t bytestart, offs_t byteend, offs_t bytemask)
{
int i;
- start &= mask;
+ bytestart &= bytemask;
/* all static handlers are hardcoded */
if (HANDLER_IS_STATIC(handler))
@@ -1806,9 +1823,9 @@ static UINT8 get_handler_index(handler_data *table, void *object, genf *handler,
i = (FPTR)handler;
if (HANDLER_IS_BANK(handler))
{
- table[i].offset = start;
- table[i].top = end;
- table[i].mask = mask;
+ table[i].bytestart = bytestart;
+ table[i].byteend = byteend;
+ table[i].bytemask = bytemask;
table[i].name = handler_name;
table[i].object = object;
}
@@ -1821,14 +1838,14 @@ static UINT8 get_handler_index(handler_data *table, void *object, genf *handler,
if (table[i].handler.generic == NULL)
{
table[i].handler.generic = handler;
- table[i].offset = start;
- table[i].top = end;
- table[i].mask = mask;
+ table[i].bytestart = bytestart;
+ table[i].byteend = byteend;
+ table[i].bytemask = bytemask;
table[i].name = handler_name;
table[i].object = object;
return i;
}
- if (table[i].handler.generic == handler && table[i].offset == start && table[i].mask == mask && table[i].object == object)
+ if (table[i].handler.generic == handler && table[i].bytestart == bytestart && table[i].bytemask == bytemask && table[i].object == object)
return i;
}
return 0;
@@ -1840,47 +1857,47 @@ static UINT8 get_handler_index(handler_data *table, void *object, genf *handler,
to a range of addresses
-------------------------------------------------*/
-static void populate_table_range(addrspace_data *space, int iswrite, offs_t start, offs_t stop, UINT8 handler)
+static void populate_table_range(addrspace_data *space, read_or_write readorwrite, offs_t bytestart, offs_t byteend, UINT8 handler)
{
- table_data *tabledata = iswrite ? &space->write : &space->read;
+ table_data *tabledata = (readorwrite == ROW_WRITE) ? &space->write : &space->read;
offs_t l2mask = (1 << LEVEL2_BITS) - 1;
- offs_t l1start = start >> LEVEL2_BITS;
- offs_t l2start = start & l2mask;
- offs_t l1stop = stop >> LEVEL2_BITS;
- offs_t l2stop = stop & l2mask;
+ offs_t l1start = bytestart >> LEVEL2_BITS;
+ offs_t l2start = bytestart & l2mask;
+ offs_t l1stop = byteend >> LEVEL2_BITS;
+ offs_t l2stop = byteend & l2mask;
offs_t l1index;
/* sanity check */
- if (start > stop)
+ if (bytestart > byteend)
return;
/* handle the starting edge if it's not on a block boundary */
if (l2start != 0)
{
- UINT8 *subtable = open_subtable(tabledata, l1start);
+ UINT8 *subtable = subtable_open(tabledata, l1start);
/* if the start and stop end within the same block, handle that */
if (l1start == l1stop)
{
memset(&subtable[l2start], handler, l2stop - l2start + 1);
- close_subtable(tabledata, l1start);
+ subtable_close(tabledata, l1start);
return;
}
/* otherwise, fill until the end */
memset(&subtable[l2start], handler, (1 << LEVEL2_BITS) - l2start);
- close_subtable(tabledata, l1start);
+ subtable_close(tabledata, l1start);
if (l1start != (offs_t)~0) l1start++;
}
/* handle the trailing edge if it's not on a block boundary */
if (l2stop != l2mask)
{
- UINT8 *subtable = open_subtable(tabledata, l1stop);
+ UINT8 *subtable = subtable_open(tabledata, l1stop);
/* fill from the beginning */
memset(&subtable[0], handler, l2stop + 1);
- close_subtable(tabledata, l1stop);
+ subtable_close(tabledata, l1stop);
/* if the start and stop end within the same block, handle that */
if (l1start == l1stop)
@@ -1893,18 +1910,18 @@ static void populate_table_range(addrspace_data *space, int iswrite, offs_t star
{
/* if we have a subtable here, release it */
if (tabledata->table[l1index] >= SUBTABLE_BASE)
- release_subtable(tabledata, tabledata->table[l1index]);
+ subtable_release(tabledata, tabledata->table[l1index]);
tabledata->table[l1index] = handler;
}
}
/*-------------------------------------------------
- allocate_subtable - allocate a fresh subtable
+ subtable_alloc - allocate a fresh subtable
and set its usecount to 1
-------------------------------------------------*/
-static UINT8 allocate_subtable(table_data *tabledata)
+static UINT8 subtable_alloc(table_data *tabledata)
{
/* loop */
while (1)
@@ -1930,7 +1947,7 @@ static UINT8 allocate_subtable(table_data *tabledata)
}
/* merge any subtables we can */
- if (!merge_subtables(tabledata))
+ if (!subtable_merge(tabledata))
fatalerror("Ran out of subtables!");
}
@@ -1938,17 +1955,17 @@ static UINT8 allocate_subtable(table_data *tabledata)
/*-------------------------------------------------
- reallocate_subtable - increment the usecount on
+ subtable_realloc - increment the usecount on
a subtable
-------------------------------------------------*/
-static void reallocate_subtable(table_data *tabledata, UINT8 subentry)
+static void subtable_realloc(table_data *tabledata, UINT8 subentry)
{
UINT8 subindex = subentry - SUBTABLE_BASE;
/* sanity check */
if (tabledata->subtable[subindex].usecount <= 0)
- fatalerror("Called reallocate_subtable on a table with a usecount of 0");
+ fatalerror("Called subtable_realloc on a table with a usecount of 0");
/* increment the usecount */
tabledata->subtable[subindex].usecount++;
@@ -1956,11 +1973,11 @@ static void reallocate_subtable(table_data *tabledata, UINT8 subentry)
/*-------------------------------------------------
- merge_subtables - merge any duplicate
+ subtable_merge - merge any duplicate
subtables
-------------------------------------------------*/
-static int merge_subtables(table_data *tabledata)
+static int subtable_merge(table_data *tabledata)
{
int merged = 0;
UINT8 subindex;
@@ -2003,8 +2020,8 @@ static int merge_subtables(table_data *tabledata)
for (l1index = 0; l1index <= (0xffffffffUL >> LEVEL2_BITS); l1index++)
if (tabledata->table[l1index] == sumindex + SUBTABLE_BASE)
{
- release_subtable(tabledata, sumindex + SUBTABLE_BASE);
- reallocate_subtable(tabledata, subindex + SUBTABLE_BASE);
+ subtable_release(tabledata, sumindex + SUBTABLE_BASE);
+ subtable_realloc(tabledata, subindex + SUBTABLE_BASE);
tabledata->table[l1index] = subindex + SUBTABLE_BASE;
merged++;
}
@@ -2016,17 +2033,17 @@ static int merge_subtables(table_data *tabledata)
/*-------------------------------------------------
- release_subtable - decrement the usecount on
+ subtable_release - decrement the usecount on
a subtable and free it if we're done
-------------------------------------------------*/
-static void release_subtable(table_data *tabledata, UINT8 subentry)
+static void subtable_release(table_data *tabledata, UINT8 subentry)
{
UINT8 subindex = subentry - SUBTABLE_BASE;
/* sanity check */
if (tabledata->subtable[subindex].usecount <= 0)
- fatalerror("Called release_subtable on a table with a usecount of 0");
+ fatalerror("Called subtable_release on a table with a usecount of 0");
/* decrement the usecount and clear the checksum if we're at 0 */
tabledata->subtable[subindex].usecount--;
@@ -2036,18 +2053,18 @@ static void release_subtable(table_data *tabledata, UINT8 subentry)
/*-------------------------------------------------
- open_subtable - gain access to a subtable for
+ subtable_open - gain access to a subtable for
modification
-------------------------------------------------*/
-static UINT8 *open_subtable(table_data *tabledata, offs_t l1index)
+static UINT8 *subtable_open(table_data *tabledata, offs_t l1index)
{
UINT8 subentry = tabledata->table[l1index];
/* if we don't have a subtable yet, allocate a new one */
if (subentry < SUBTABLE_BASE)
{
- UINT8 newentry = allocate_subtable(tabledata);
+ UINT8 newentry = subtable_alloc(tabledata);
memset(SUBTABLE_PTR(tabledata, newentry), subentry, 1 << LEVEL2_BITS);
tabledata->table[l1index] = newentry;
tabledata->subtable[newentry - SUBTABLE_BASE].checksum = (subentry + (subentry << 8) + (subentry << 16) + (subentry << 24)) * ((1 << LEVEL2_BITS)/4);
@@ -2057,7 +2074,7 @@ static UINT8 *open_subtable(table_data *tabledata, offs_t l1index)
/* if we're sharing this subtable, we also need to allocate a fresh copy */
else if (tabledata->subtable[subentry - SUBTABLE_BASE].usecount > 1)
{
- UINT8 newentry = allocate_subtable(tabledata);
+ UINT8 newentry = subtable_alloc(tabledata);
/* allocate may cause some additional merging -- look up the subentry again */
/* when we're done; it should still require a split */
@@ -2066,7 +2083,7 @@ static UINT8 *open_subtable(table_data *tabledata, offs_t l1index)
assert(tabledata->subtable[subentry - SUBTABLE_BASE].usecount > 1);
memcpy(SUBTABLE_PTR(tabledata, newentry), SUBTABLE_PTR(tabledata, subentry), 1 << LEVEL2_BITS);
- release_subtable(tabledata, subentry);
+ subtable_release(tabledata, subentry);
tabledata->table[l1index] = newentry;
tabledata->subtable[newentry - SUBTABLE_BASE].checksum = tabledata->subtable[subentry - SUBTABLE_BASE].checksum;
subentry = newentry;
@@ -2081,10 +2098,10 @@ static UINT8 *open_subtable(table_data *tabledata, offs_t l1index)
/*-------------------------------------------------
- close_subtable - stop access to a subtable
+ subtable_close - stop access to a subtable
-------------------------------------------------*/
-static void close_subtable(table_data *tabledata, offs_t l1index)
+static void subtable_close(table_data *tabledata, offs_t l1index)
{
/* defer any merging until we run out of tables */
}
@@ -2117,7 +2134,7 @@ static int amentry_needs_backing_store(int cpunum, int spacenum, const address_m
{
if (handler != STATIC_INVALID &&
(handler < STATIC_BANK1 || handler > STATIC_BANK1 + MAX_BANKS - 1) &&
- (handler != STATIC_ROM || spacenum != ADDRESS_SPACE_PROGRAM || entry->start >= memory_region_length(REGION_CPU1 + cpunum)) &&
+ (handler != STATIC_ROM || spacenum != ADDRESS_SPACE_PROGRAM || entry->addrstart >= memory_region_length(REGION_CPU1 + cpunum)) &&
handler != STATIC_NOP &&
handler != STATIC_UNMAP)
return 1;
@@ -2128,24 +2145,24 @@ static int amentry_needs_backing_store(int cpunum, int spacenum, const address_m
/*-------------------------------------------------
- allocate_memory - allocate memory for
+ memory_init_allocate - allocate memory for
CPU address spaces
-------------------------------------------------*/
-static void allocate_memory(void)
+static void memory_init_allocate(const machine_config *config)
{
int cpunum, spacenum;
/* loop over all CPUs and memory spaces */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
if (cpudata[cpunum].spacemask & (1 << spacenum))
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
address_map_entry *unassigned = NULL;
address_map_entry *entry;
- int start_count = memory_block_count;
- int i;
+ memory_block *prev_memblock_head = memory_block_list;
+ memory_block *memblock;
/* make a first pass over the memory map and track blocks with hardcoded pointers */
/* we do this to make sure they are found by memory_find_base first */
@@ -2154,28 +2171,28 @@ static void allocate_memory(void)
allocate_memory_block(cpunum, spacenum, entry->bytestart, entry->byteend, entry->memory);
/* loop over all blocks just allocated and assign pointers from them */
- for (i = start_count; i < memory_block_count; i++)
- unassigned = assign_intersecting_blocks(space, memory_block_list[i].start, memory_block_list[i].end, memory_block_list[i].data);
+ for (memblock = memory_block_list; memblock != prev_memblock_head; memblock = memblock->next)
+ unassigned = assign_intersecting_blocks(space, memblock->bytestart, memblock->byteend, memblock->data);
/* if we don't have an unassigned pointer yet, try to find one */
if (unassigned == NULL)
unassigned = assign_intersecting_blocks(space, ~0, 0, NULL);
/* loop until we've assigned all memory in this space */
- while (unassigned)
+ while (unassigned != NULL)
{
- offs_t curstart, curend;
+ offs_t curbytestart, curbyteend;
int changed;
void *block;
- /* work in MEMORY_BLOCK_SIZE-sized chunks */
- curstart = unassigned->bytestart / MEMORY_BLOCK_SIZE;
- curend = unassigned->byteend / MEMORY_BLOCK_SIZE;
+ /* work in MEMORY_BLOCK_CHUNK-sized chunks */
+ offs_t curblockstart = unassigned->bytestart / MEMORY_BLOCK_CHUNK;
+ offs_t curblockend = unassigned->byteend / MEMORY_BLOCK_CHUNK;
- /* loop while we keep finding unassigned blocks in neighboring MEMORY_BLOCK_SIZE chunks */
+ /* loop while we keep finding unassigned blocks in neighboring MEMORY_BLOCK_CHUNK chunks */
do
{
- changed = 0;
+ changed = FALSE;
/* scan for unmapped blocks in the adjusted map */
for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
@@ -2184,27 +2201,27 @@ static void allocate_memory(void)
offs_t blockstart, blockend;
/* get block start/end blocks for this block */
- blockstart = entry->bytestart / MEMORY_BLOCK_SIZE;
- blockend = entry->byteend / MEMORY_BLOCK_SIZE;
+ blockstart = entry->bytestart / MEMORY_BLOCK_CHUNK;
+ blockend = entry->byteend / MEMORY_BLOCK_CHUNK;
/* if we intersect or are adjacent, adjust the start/end */
- if (blockstart <= curend + 1 && blockend >= curstart - 1)
+ if (blockstart <= curblockend + 1 && blockend >= curblockstart - 1)
{
- if (blockstart < curstart)
- curstart = blockstart, changed = 1;
- if (blockend > curend)
- curend = blockend, changed = 1;
+ if (blockstart < curblockstart)
+ curblockstart = blockstart, changed = TRUE;
+ if (blockend > curblockend)
+ curblockend = blockend, changed = TRUE;
}
}
} while (changed);
/* we now have a block to allocate; do it */
- curstart = curstart * MEMORY_BLOCK_SIZE;
- curend = curend * MEMORY_BLOCK_SIZE + (MEMORY_BLOCK_SIZE - 1);
- block = allocate_memory_block(cpunum, spacenum, curstart, curend, NULL);
+ curbytestart = curblockstart * MEMORY_BLOCK_CHUNK;
+ curbyteend = curblockend * MEMORY_BLOCK_CHUNK + (MEMORY_BLOCK_CHUNK - 1);
+ block = allocate_memory_block(cpunum, spacenum, curbytestart, curbyteend, NULL);
/* assign memory that intersected the new block */
- unassigned = assign_intersecting_blocks(space, curstart, curend, block);
+ unassigned = assign_intersecting_blocks(space, curbytestart, curbyteend, block);
}
}
}
@@ -2217,18 +2234,23 @@ static void allocate_memory(void)
static void *allocate_memory_block(int cpunum, int spacenum, offs_t bytestart, offs_t byteend, void *memory)
{
- memory_block *block = &memory_block_list[memory_block_count];
int allocatemem = (memory == NULL);
+ memory_block *block;
+ size_t bytestoalloc;
int region;
VPRINTF(("allocate_memory_block(%d,%d,%08X,%08X,%p)\n", cpunum, spacenum, bytestart, byteend, memory));
-
- /* if we weren't passed a memory block, allocate one and clear it to zero */
+
+ /* determine how much memory to allocate for this */
+ bytestoalloc = sizeof(*block);
if (allocatemem)
- {
- memory = auto_malloc(byteend - bytestart + 1);
- memset(memory, 0, byteend - bytestart + 1);
- }
+ bytestoalloc += byteend - bytestart + 1;
+
+ /* allocate and clear the memory */
+ block = malloc_or_die(bytestoalloc);
+ memset(block, 0, bytestoalloc);
+ if (allocatemem)
+ memory = block + 1;
/* register for saving, but only if we're not part of a memory region */
for (region = 0; region < MAX_MEMORY_REGIONS; region++)
@@ -2248,10 +2270,14 @@ static void *allocate_memory_block(int cpunum, int spacenum, offs_t bytestart, o
block->cpunum = cpunum;
block->spacenum = spacenum;
block->isallocated = allocatemem;
- block->start = bytestart;
- block->end = byteend;
+ block->bytestart = bytestart;
+ block->byteend = byteend;
block->data = memory;
- memory_block_count++;
+
+ /* attach us to the head of the list */
+ block->next = memory_block_list;
+ memory_block_list = block;
+
return memory;
}
@@ -2261,12 +2287,12 @@ static void *allocate_memory_block(int cpunum, int spacenum, offs_t bytestart, o
memory for save states
-------------------------------------------------*/
-static void register_for_save(int cpunum, int spacenum, offs_t start, void *base, size_t numbytes)
+static void register_for_save(int cpunum, int spacenum, offs_t bytestart, void *base, size_t numbytes)
{
int bytes_per_element = cpudata[cpunum].space[spacenum].dbits/8;
char name[256];
- sprintf(name, "%d.%08x-%08x", spacenum, start, (int)(start + numbytes - 1));
+ sprintf(name, "%d.%08x-%08x", spacenum, bytestart, (int)(bytestart + numbytes - 1));
state_save_register_memory("memory", cpunum, name, base, bytes_per_element, (UINT32)numbytes / bytes_per_element);
}
@@ -2276,7 +2302,7 @@ static void register_for_save(int cpunum, int spacenum, offs_t start, void *base
intersecting blocks and assign their pointers
-------------------------------------------------*/
-static address_map_entry *assign_intersecting_blocks(addrspace_data *space, offs_t start, offs_t end, UINT8 *base)
+static address_map_entry *assign_intersecting_blocks(addrspace_data *space, offs_t bytestart, offs_t byteend, UINT8 *base)
{
address_map_entry *entry, *unassigned = NULL;
@@ -2290,14 +2316,14 @@ static address_map_entry *assign_intersecting_blocks(addrspace_data *space, offs
if (entry->share != 0 && shared_ptr[entry->share] != NULL)
{
entry->memory = shared_ptr[entry->share];
- VPRINTF(("memory range %08X-%08X -> shared_ptr[%d] [%p]\n", entry->start, entry->end, entry->share, entry->memory));
+ VPRINTF(("memory range %08X-%08X -> shared_ptr[%d] [%p]\n", entry->addrstart, entry->addrend, entry->share, entry->memory));
}
/* otherwise, look for a match in this block */
- else if (entry->bytestart >= start && entry->byteend <= end)
+ else if (entry->bytestart >= bytestart && entry->byteend <= byteend)
{
- entry->memory = base + (entry->bytestart - start);
- VPRINTF(("memory range %08X-%08X -> found in block from %08X-%08X [%p]\n", entry->start, entry->end, start, end, entry->memory));
+ entry->memory = base + (entry->bytestart - bytestart);
+ VPRINTF(("memory range %08X-%08X -> found in block from %08X-%08X [%p]\n", entry->addrstart, entry->addrend, bytestart, byteend, entry->memory));
}
}
@@ -2334,16 +2360,16 @@ static void reattach_banks(void)
/*-------------------------------------------------
- find_memory - find all the requested pointers
+ memory_init_locate - find all the requested pointers
into the final allocated memory
-------------------------------------------------*/
-static void find_memory(void)
+static void memory_init_locate(void)
{
int cpunum, spacenum, banknum;
/* loop over CPUs and address spaces */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
if (cpudata[cpunum].spacemask & (1 << spacenum))
{
@@ -2373,10 +2399,10 @@ static void find_memory(void)
/* set the initial bank pointer */
for (entry = cpudata[bankdata[banknum].cpunum].space[bankdata[banknum].spacenum].map->entrylist; entry != NULL; entry = entry->next)
- if (entry->bytestart == bankdata[banknum].base)
+ if (entry->bytestart == bankdata[banknum].bytestart)
{
bank_ptr[banknum] = entry->memory;
- VPRINTF(("assigned bank %d pointer to memory from range %08X-%08X [%p]\n", banknum, entry->start, entry->end, entry->memory));
+ VPRINTF(("assigned bank %d pointer to memory from range %08X-%08X [%p]\n", banknum, entry->addrstart, entry->addrend, entry->memory));
break;
}
@@ -2396,32 +2422,31 @@ static void find_memory(void)
and offset
-------------------------------------------------*/
-static void *memory_find_base(int cpunum, int spacenum, int readwrite, offs_t offset)
+static void *memory_find_base(int cpunum, int spacenum, int readwrite, offs_t byteaddress)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
address_map_entry *entry;
memory_block *block;
- int blocknum;
- VPRINTF(("memory_find_base(%d,%d,%d,%08X) -> ", cpunum, spacenum, readwrite, offset));
+ VPRINTF(("memory_find_base(%d,%d,%d,%08X) -> ", cpunum, spacenum, readwrite, byteaddress));
- /* look in the adjusted map */
+ /* look in the address map first */
for (entry = space->map->entrylist; entry != NULL; entry = entry->next)
{
- offs_t maskoffs = offset & entry->bytemask;
+ offs_t maskoffs = byteaddress & entry->bytemask;
if (maskoffs >= entry->bytestart && maskoffs <= entry->byteend)
{
- VPRINTF(("found in entry %08X-%08X [%p]\n", entry->start, entry->end, (UINT8 *)entry->memory + (maskoffs - entry->bytestart)));
+ VPRINTF(("found in entry %08X-%08X [%p]\n", entry->addrstart, entry->addrend, (UINT8 *)entry->memory + (maskoffs - entry->bytestart)));
return (UINT8 *)entry->memory + (maskoffs - entry->bytestart);
}
}
/* if not found there, look in the allocated blocks */
- for (blocknum = 0, block = memory_block_list; blocknum < memory_block_count; blocknum++, block++)
- if (block->cpunum == cpunum && block->spacenum == spacenum && block->start <= offset && block->end > offset)
+ for (block = memory_block_list; block != NULL; block = block->next)
+ if (block->cpunum == cpunum && block->spacenum == spacenum && block->bytestart <= byteaddress && block->byteend > byteaddress)
{
- VPRINTF(("found in allocated memory block %08X-%08X [%p]\n", block->start, block->end, block->data + (offset - block->start)));
- return block->data + offset - block->start;
+ VPRINTF(("found in allocated memory block %08X-%08X [%p]\n", block->bytestart, block->byteend, block->data + (byteaddress - block->bytestart)));
+ return block->data + byteaddress - block->bytestart;
}
VPRINTF(("did not find\n"));
@@ -2435,7 +2460,7 @@ static void *memory_find_base(int cpunum, int spacenum, int readwrite, offs_t of
#define PERFORM_LOOKUP(lookup,handlers,spacenum,extraand) \
/* perform lookup */ \
- address &= active_address_space[spacenum].addrmask & extraand; \
+ address &= active_address_space[spacenum].bytemask & extraand; \
entry = active_address_space[spacenum].lookup[LEVEL1_INDEX(address)]; \
if (entry >= SUBTABLE_BASE) \
entry = active_address_space[spacenum].lookup[LEVEL2_INDEX(entry,address)]; \
@@ -2457,7 +2482,7 @@ UINT8 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 1, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(bank_ptr[entry][address]); \
\
@@ -2477,7 +2502,7 @@ UINT8 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 1, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(bank_ptr[entry][xormacro(address)]); \
\
@@ -2513,7 +2538,7 @@ UINT16 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 2, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT16 *)&bank_ptr[entry][address]); \
\
@@ -2533,7 +2558,7 @@ UINT16 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 2, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT16 *)&bank_ptr[entry][xormacro(address)]); \
\
@@ -2567,7 +2592,7 @@ UINT32 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 4, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT32 *)&bank_ptr[entry][address]); \
\
@@ -2587,7 +2612,7 @@ UINT32 name(offs_t original_address, UINT32 mem_mask) \
DEBUG_HOOK_READ(spacenum, 4, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT32 *)&bank_ptr[entry][address]); \
\
@@ -2607,7 +2632,7 @@ UINT32 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 4, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT32 *)&bank_ptr[entry][xormacro(address)]); \
\
@@ -2639,7 +2664,7 @@ UINT64 name(offs_t original_address) \
DEBUG_HOOK_READ(spacenum, 8, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT64 *)&bank_ptr[entry][address]); \
\
@@ -2659,7 +2684,7 @@ UINT64 name(offs_t original_address, UINT64 mem_mask) \
DEBUG_HOOK_READ(spacenum, 8, address); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMREADEND(*(UINT64 *)&bank_ptr[entry][address]); \
\
@@ -2684,7 +2709,7 @@ void name(offs_t original_address, UINT8 data) \
DEBUG_HOOK_WRITE(spacenum, 1, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(bank_ptr[entry][address] = data); \
\
@@ -2704,7 +2729,7 @@ void name(offs_t original_address, UINT8 data) \
DEBUG_HOOK_WRITE(spacenum, 1, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(bank_ptr[entry][xormacro(address)] = data); \
\
@@ -2740,7 +2765,7 @@ void name(offs_t original_address, UINT16 data) \
DEBUG_HOOK_WRITE(spacenum, 2, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(*(UINT16 *)&bank_ptr[entry][address] = data); \
\
@@ -2760,7 +2785,7 @@ void name(offs_t original_address, UINT16 data) \
DEBUG_HOOK_WRITE(spacenum, 2, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(*(UINT16 *)&bank_ptr[entry][xormacro(address)] = data); \
\
@@ -2794,7 +2819,7 @@ void name(offs_t original_address, UINT32 data) \
DEBUG_HOOK_WRITE(spacenum, 4, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(*(UINT32 *)&bank_ptr[entry][address] = data); \
\
@@ -2814,7 +2839,7 @@ void name(offs_t original_address, UINT32 data, UINT32 mem_mask) \
DEBUG_HOOK_WRITE(spacenum, 4, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
{ \
UINT32 *dest = (UINT32 *)&bank_ptr[entry][address]; \
@@ -2837,7 +2862,7 @@ void name(offs_t original_address, UINT32 data) \
DEBUG_HOOK_WRITE(spacenum, 4, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(*(UINT32 *)&bank_ptr[entry][xormacro(address)] = data); \
\
@@ -2869,7 +2894,7 @@ void name(offs_t original_address, UINT64 data) \
DEBUG_HOOK_WRITE(spacenum, 8, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
MEMWRITEEND(*(UINT64 *)&bank_ptr[entry][address] = data); \
\
@@ -2889,7 +2914,7 @@ void name(offs_t original_address, UINT64 data, UINT64 mem_mask) \
DEBUG_HOOK_WRITE(spacenum, 8, address, data); \
\
/* handle banks inline */ \
- address = (address - handler->offset) & handler->mask; \
+ address = (address - handler->bytestart) & handler->bytemask; \
if (entry < STATIC_RAM) \
{ \
UINT64 *dest = (UINT64 *)&bank_ptr[entry][address]; \
@@ -3080,52 +3105,52 @@ WRITEDWORD64LE(io_write_dword_64le, ADDRESS_SPACE_IO)
safe opcode reading
-------------------------------------------------*/
-UINT8 cpu_readop_safe(offs_t offset)
+UINT8 cpu_readop_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop_unsafe(byteaddress);
}
-UINT16 cpu_readop16_safe(offs_t offset)
+UINT16 cpu_readop16_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop16_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop16_unsafe(byteaddress);
}
-UINT32 cpu_readop32_safe(offs_t offset)
+UINT32 cpu_readop32_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop32_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop32_unsafe(byteaddress);
}
-UINT64 cpu_readop64_safe(offs_t offset)
+UINT64 cpu_readop64_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop64_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop64_unsafe(byteaddress);
}
-UINT8 cpu_readop_arg_safe(offs_t offset)
+UINT8 cpu_readop_arg_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop_arg_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop_arg_unsafe(byteaddress);
}
-UINT16 cpu_readop_arg16_safe(offs_t offset)
+UINT16 cpu_readop_arg16_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop_arg16_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop_arg16_unsafe(byteaddress);
}
-UINT32 cpu_readop_arg32_safe(offs_t offset)
+UINT32 cpu_readop_arg32_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop_arg32_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop_arg32_unsafe(byteaddress);
}
-UINT64 cpu_readop_arg64_safe(offs_t offset)
+UINT64 cpu_readop_arg64_safe(offs_t byteaddress)
{
- activecpu_set_opbase(offset);
- return cpu_readop_arg64_unsafe(offset);
+ activecpu_set_opbase(byteaddress);
+ return cpu_readop_arg64_unsafe(byteaddress);
}
@@ -3135,116 +3160,116 @@ UINT64 cpu_readop_arg64_safe(offs_t offset)
static READ8_HANDLER( mrh8_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset));
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset));
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM].unmap;
}
static READ16_HANDLER( mrh16_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*2), mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*2), mem_mask ^ 0xffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM].unmap;
}
static READ32_HANDLER( mrh32_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*4), mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*4), mem_mask ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM].unmap;
}
static READ64_HANDLER( mrh64_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM].unmap;
}
static WRITE8_HANDLER( mwh8_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset), data);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset), data);
}
static WRITE16_HANDLER( mwh16_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*2), data, mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*2), data, mem_mask ^ 0xffff);
}
static WRITE32_HANDLER( mwh32_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*4), data, mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*4), data, mem_mask ^ 0xffffffff);
}
static WRITE64_HANDLER( mwh64_unmap_program )
{
- if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_PROGRAM] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped program memory qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_PROGRAM], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
}
static READ8_HANDLER( mrh8_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset));
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset));
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA].unmap;
}
static READ16_HANDLER( mrh16_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*2), mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*2), mem_mask ^ 0xffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA].unmap;
}
static READ32_HANDLER( mrh32_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*4), mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*4), mem_mask ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA].unmap;
}
static READ64_HANDLER( mrh64_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA].unmap;
}
static WRITE8_HANDLER( mwh8_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset), data);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset), data);
}
static WRITE16_HANDLER( mwh16_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*2), data, mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*2), data, mem_mask ^ 0xffff);
}
static WRITE32_HANDLER( mwh32_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*4), data, mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*4), data, mem_mask ^ 0xffffffff);
}
static WRITE64_HANDLER( mwh64_unmap_data )
{
- if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_DATA] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped data memory qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_DATA], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
}
static READ8_HANDLER( mrh8_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset));
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O byte read from %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset));
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO].unmap;
}
static READ16_HANDLER( mrh16_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*2), mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O word read from %08X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*2), mem_mask ^ 0xffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO].unmap;
}
static READ32_HANDLER( mrh32_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*4), mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O dword read from %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*4), mem_mask ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO].unmap;
}
static READ64_HANDLER( mrh64_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O qword read from %08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*8), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
return cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO].unmap;
}
static WRITE8_HANDLER( mwh8_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset), data);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O byte write to %08X = %02X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset), data);
}
static WRITE16_HANDLER( mwh16_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*2), data, mem_mask ^ 0xffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O word write to %08X = %04X & %04X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*2), data, mem_mask ^ 0xffff);
}
static WRITE32_HANDLER( mwh32_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*4), data, mem_mask ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O dword write to %08X = %08X & %08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*4), data, mem_mask ^ 0xffffffff);
}
static WRITE64_HANDLER( mwh64_unmap_io )
{
- if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), INV_SPACE_SHIFT(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
+ if (log_unmap[ADDRESS_SPACE_IO] && !debugger_access) logerror("cpu #%d (PC=%08X): unmapped I/O qword write to %08X = %08X%08X & %08X%08X\n", cpu_getactivecpu(), activecpu_get_pc(), BYTE2ADDR(&cpudata[cpu_getactivecpu()].space[ADDRESS_SPACE_IO], offset*8), (int)(data >> 32), (int)(data & 0xffffffff), (int)(mem_mask >> 32) ^ 0xffffffff, (int)(mem_mask & 0xffffffff) ^ 0xffffffff);
}
@@ -3376,7 +3401,7 @@ static void dump_map(FILE *file, const addrspace_data *space, const table_data *
fprintf(file, " Data bits = %d\n", space->dbits);
fprintf(file, " L1 bits = %d\n", LEVEL1_BITS);
fprintf(file, " L2 bits = %d\n", LEVEL2_BITS);
- fprintf(file, " Address mask = %X\n", space->mask);
+ fprintf(file, " Address mask = %X\n", space->bytemask);
fprintf(file, "\n");
/* loop over level 1 entries */
@@ -3398,7 +3423,7 @@ static void dump_map(FILE *file, const addrspace_data *space, const table_data *
(i << LEVEL2_BITS) - 1,
lastentry,
handler_to_string(table, lastentry),
- table->handlers[lastentry].offset);
+ table->handlers[lastentry].bytestart);
/* start counting with this entry */
lastentry = entry;
@@ -3430,7 +3455,7 @@ static void dump_map(FILE *file, const addrspace_data *space, const table_data *
((i << LEVEL2_BITS) | (j - 1)),
lastentry2,
handler_to_string(table, lastentry2),
- table->handlers[lastentry2].offset);
+ table->handlers[lastentry2].bytestart);
/* start counting with this entry */
lastentry2 = entry2;
@@ -3444,7 +3469,7 @@ static void dump_map(FILE *file, const addrspace_data *space, const table_data *
((i << LEVEL2_BITS) | (j - 1)),
lastentry2,
handler_to_string(table, lastentry2),
- table->handlers[lastentry2].offset);
+ table->handlers[lastentry2].bytestart);
}
}
@@ -3455,7 +3480,7 @@ static void dump_map(FILE *file, const addrspace_data *space, const table_data *
(i << LEVEL2_BITS) - 1,
lastentry,
handler_to_string(table, lastentry),
- table->handlers[lastentry].offset);
+ table->handlers[lastentry].bytestart);
}
void memory_dump(FILE *file)
@@ -3467,9 +3492,9 @@ void memory_dump(FILE *file)
return;
/* loop over CPUs */
- for (cpunum = 0; cpunum < MAX_CPU && Machine->config->cpu[cpunum].type != CPU_DUMMY; cpunum++)
+ for (cpunum = 0; cpunum < ARRAY_LENGTH(cpudata); cpunum++)
for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
- if (cpudata[cpunum].space[spacenum].abits)
+ if (cpudata[cpunum].spacemask & (1 << spacenum))
{
fprintf(file, "\n\n"
"=========================================\n"
@@ -3491,18 +3516,34 @@ void memory_dump(FILE *file)
describing the handler at a particular offset
-------------------------------------------------*/
-const char *memory_get_handler_string(int read0_or_write1, int cpunum, int spacenum, offs_t offset)
+const char *memory_get_handler_string(int read0_or_write1, int cpunum, int spacenum, offs_t byteaddress)
{
addrspace_data *space = &cpudata[cpunum].space[spacenum];
const table_data *table = read0_or_write1 ? &space->write : &space->read;
UINT8 entry;
/* perform the lookup */
- offset &= space->mask;
- entry = table->table[LEVEL1_INDEX(offset)];
+ byteaddress &= space->bytemask;
+ entry = table->table[LEVEL1_INDEX(byteaddress)];
if (entry >= SUBTABLE_BASE)
- entry = table->table[LEVEL2_INDEX(entry, offset)];
+ entry = table->table[LEVEL2_INDEX(entry, byteaddress)];
/* 8-bit case: RAM/ROM */
return handler_to_string(table, entry);
}
+
+
+static void mem_dump(void)
+{
+ FILE *file;
+
+ if (MEM_DUMP)
+ {
+ file = fopen("memdump.log", "w");
+ if (file)
+ {
+ memory_dump(file);
+ fclose(file);
+ }
+ }
+}
diff --git a/src/emu/memory.h b/src/emu/memory.h
index 3a94e752a01..a744bc5e7a5 100644
--- a/src/emu/memory.h
+++ b/src/emu/memory.h
@@ -52,15 +52,21 @@ typedef offs_t (*opbase_handler_func) (ATTR_UNUSED running_machine *machine, A
typedef struct _data_accessors data_accessors;
struct _data_accessors
{
- UINT8 (*read_byte)(offs_t offset);
- UINT16 (*read_word)(offs_t offset);
- UINT32 (*read_dword)(offs_t offset);
- UINT64 (*read_qword)(offs_t offset);
-
- void (*write_byte)(offs_t offset, UINT8 data);
- void (*write_word)(offs_t offset, UINT16 data);
- void (*write_dword)(offs_t offset, UINT32 data);
- void (*write_qword)(offs_t offset, UINT64 data);
+ void (*change_pc)(offs_t byteaddress);
+
+ UINT8 (*read_byte)(offs_t byteaddress);
+ UINT16 (*read_word)(offs_t byteaddress);
+ UINT32 (*read_dword)(offs_t byteaddress);
+ UINT32 (*read_dword_masked)(offs_t byteaddress, UINT32 mask);
+ UINT64 (*read_qword)(offs_t byteaddress);
+ UINT64 (*read_qword_masked)(offs_t byteaddress, UINT64 mask);
+
+ void (*write_byte)(offs_t byteaddress, UINT8 data);
+ void (*write_word)(offs_t byteaddress, UINT16 data);
+ void (*write_dword)(offs_t byteaddress, UINT32 data);
+ void (*write_dword_masked)(offs_t byteaddress, UINT32 data, UINT32 mask);
+ void (*write_qword)(offs_t byteaddress, UINT64 data);
+ void (*write_qword_masked)(offs_t byteaddress, UINT64 data, UINT64 mask);
};
@@ -247,9 +253,10 @@ struct _address_map_entry
{
address_map_entry * next; /* pointer to the next entry */
- offs_t start, end; /* start/end values */
- offs_t mirror; /* mirror bits */
- offs_t mask; /* mask bits */
+ offs_t addrstart; /* start address */
+ offs_t addrend; /* end address */
+ offs_t addrmirror; /* mirror bits */
+ offs_t addrmask; /* mask bits */
read_handlers read; /* read handler callback */
const char * read_name; /* read handler callback name */
device_type read_devtype; /* read device type for device references */
@@ -267,7 +274,8 @@ struct _address_map_entry
offs_t region_offs; /* offset within the region */
void * memory; /* pointer to memory backing this entry */
- offs_t bytestart, byteend; /* byte-adjusted start/end values */
+ offs_t bytestart; /* byte-adjusted start address */
+ offs_t byteend; /* byte-adjusted end address */
offs_t bytemirror; /* byte-adjusted mirror bits */
offs_t bytemask; /* byte-adjusted mask bits */
};
@@ -286,7 +294,7 @@ struct _address_map
typedef struct _address_space address_space;
struct _address_space
{
- offs_t addrmask; /* address mask */
+ offs_t bytemask; /* byte-adjusted address mask */
UINT8 * readlookup; /* read table lookup */
UINT8 * writelookup; /* write table lookup */
handler_data * readhandlers; /* read handlers */
@@ -722,15 +730,15 @@ const address_map *memory_get_map(int cpunum, int spacenum);
/* ----- opcode base control ---- */
opbase_handler_func memory_set_opbase_handler(int cpunum, opbase_handler_func function);
-void memory_set_opbase(offs_t offset);
+void memory_set_opbase(offs_t byteaddress);
/* ----- separate opcode/data encryption helper ---- */
-void memory_set_decrypted_region(int cpunum, offs_t start, offs_t end, void *base);
+void memory_set_decrypted_region(int cpunum, offs_t bytestart, offs_t byteend, void *base);
/* ----- return a base pointer to memory ---- */
-void * memory_get_read_ptr(int cpunum, int spacenum, offs_t offset);
-void * memory_get_write_ptr(int cpunum, int spacenum, offs_t offset);
-void * memory_get_op_ptr(int cpunum, offs_t offset, int arg);
+void * memory_get_read_ptr(int cpunum, int spacenum, offs_t byteaddress);
+void * memory_get_write_ptr(int cpunum, int spacenum, offs_t byteaddress);
+void * memory_get_op_ptr(int cpunum, offs_t byteaddress, int arg);
/* ----- memory banking ----- */
void memory_configure_bank(int banknum, int startentry, int numentries, void *base, offs_t stride);
@@ -739,31 +747,33 @@ void memory_set_bank(int banknum, int entrynum);
int memory_get_bank(int banknum);
void memory_set_bankptr(int banknum, void *base);
+const data_accessors *memory_get_accessors(int spacenum, int databits, int endianness);
+
/* ----- debugging ----- */
void memory_set_debugger_access(int debugger);
void memory_set_log_unmap(int spacenum, int log);
int memory_get_log_unmap(int spacenum);
/* ----- dynamic address space mapping ----- */
-void * _memory_install_read_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR handler, const char *handler_name);
-UINT8 * _memory_install_read8_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read8_machine_func handler, const char *handler_name);
-UINT16 * _memory_install_read16_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read16_machine_func handler, const char *handler_name);
-UINT32 * _memory_install_read32_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read32_machine_func handler, const char *handler_name);
-UINT64 * _memory_install_read64_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read64_machine_func handler, const char *handler_name);
-void * _memory_install_write_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR handler, const char *handler_name);
-UINT8 * _memory_install_write8_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write8_machine_func handler, const char *handler_name);
-UINT16 * _memory_install_write16_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write16_machine_func handler, const char *handler_name);
-UINT32 * _memory_install_write32_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write32_machine_func handler, const char *handler_name);
-UINT64 * _memory_install_write64_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, write64_machine_func handler, const char *handler_name);
-void * _memory_install_readwrite_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, FPTR rhandler, FPTR whandler, const char *rhandler_name, const char *whandler_name);
-UINT8 * _memory_install_readwrite8_handler (int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read8_machine_func rhandler, write8_machine_func whandler, const char *rhandler_name, const char *whandler_name);
-UINT16 * _memory_install_readwrite16_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read16_machine_func rhandler, write16_machine_func whandler, const char *rhandler_name, const char *whandler_name);
-UINT32 * _memory_install_readwrite32_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read32_machine_func rhandler, write32_machine_func whandler, const char *rhandler_name, const char *whandler_name);
-UINT64 * _memory_install_readwrite64_handler(int cpunum, int spacenum, offs_t start, offs_t end, offs_t mask, offs_t mirror, read64_machine_func rhandler, write64_machine_func whandler, const char *rhandler_name, const char *whandler_name);
+void * _memory_install_read_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR handler, const char *handler_name);
+UINT8 * _memory_install_read8_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read8_machine_func handler, const char *handler_name);
+UINT16 * _memory_install_read16_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read16_machine_func handler, const char *handler_name);
+UINT32 * _memory_install_read32_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read32_machine_func handler, const char *handler_name);
+UINT64 * _memory_install_read64_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read64_machine_func handler, const char *handler_name);
+void * _memory_install_write_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR handler, const char *handler_name);
+UINT8 * _memory_install_write8_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write8_machine_func handler, const char *handler_name);
+UINT16 * _memory_install_write16_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write16_machine_func handler, const char *handler_name);
+UINT32 * _memory_install_write32_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write32_machine_func handler, const char *handler_name);
+UINT64 * _memory_install_write64_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, write64_machine_func handler, const char *handler_name);
+void * _memory_install_readwrite_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, FPTR rhandler, FPTR whandler, const char *rhandler_name, const char *whandler_name);
+UINT8 * _memory_install_readwrite8_handler (int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read8_machine_func rhandler, write8_machine_func whandler, const char *rhandler_name, const char *whandler_name);
+UINT16 * _memory_install_readwrite16_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read16_machine_func rhandler, write16_machine_func whandler, const char *rhandler_name, const char *whandler_name);
+UINT32 * _memory_install_readwrite32_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read32_machine_func rhandler, write32_machine_func whandler, const char *rhandler_name, const char *whandler_name);
+UINT64 * _memory_install_readwrite64_handler(int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read64_machine_func rhandler, write64_machine_func whandler, const char *rhandler_name, const char *whandler_name);
/* ----- memory debugging ----- */
void memory_dump(FILE *file);
-const char *memory_get_handler_string(int read0_or_write1, int cpunum, int spacenum, offs_t offset);
+const char *memory_get_handler_string(int read0_or_write1, int cpunum, int spacenum, offs_t byteaddress);
@@ -839,45 +849,45 @@ extern const char *const address_space_names[ADDRESS_SPACES];
_memory_install_readwrite64_handler(cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler)
/* ----- generic memory access ----- */
-INLINE UINT8 program_read_byte (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_byte)(offset); }
-INLINE UINT16 program_read_word (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_word)(offset); }
-INLINE UINT32 program_read_dword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_dword)(offset); }
-INLINE UINT64 program_read_qword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_qword)(offset); }
-
-INLINE void program_write_byte (offs_t offset, UINT8 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_byte)(offset, data); }
-INLINE void program_write_word (offs_t offset, UINT16 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_word)(offset, data); }
-INLINE void program_write_dword(offs_t offset, UINT32 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_dword)(offset, data); }
-INLINE void program_write_qword(offs_t offset, UINT64 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_qword)(offset, data); }
-
-INLINE UINT8 data_read_byte (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_byte)(offset); }
-INLINE UINT16 data_read_word (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_word)(offset); }
-INLINE UINT32 data_read_dword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_dword)(offset); }
-INLINE UINT64 data_read_qword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_qword)(offset); }
-
-INLINE void data_write_byte (offs_t offset, UINT8 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_byte)(offset, data); }
-INLINE void data_write_word (offs_t offset, UINT16 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_word)(offset, data); }
-INLINE void data_write_dword(offs_t offset, UINT32 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_dword)(offset, data); }
-INLINE void data_write_qword(offs_t offset, UINT64 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_qword)(offset, data); }
-
-INLINE UINT8 io_read_byte (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_byte)(offset); }
-INLINE UINT16 io_read_word (offs_t offset) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_word)(offset); }
-INLINE UINT32 io_read_dword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_dword)(offset); }
-INLINE UINT64 io_read_qword(offs_t offset) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_qword)(offset); }
-
-INLINE void io_write_byte (offs_t offset, UINT8 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_byte)(offset, data); }
-INLINE void io_write_word (offs_t offset, UINT16 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_word)(offset, data); }
-INLINE void io_write_dword(offs_t offset, UINT32 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_dword)(offset, data); }
-INLINE void io_write_qword(offs_t offset, UINT64 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_qword)(offset, data); }
+INLINE UINT8 program_read_byte (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_byte)(byteaddress); }
+INLINE UINT16 program_read_word (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_word)(byteaddress); }
+INLINE UINT32 program_read_dword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_dword)(byteaddress); }
+INLINE UINT64 program_read_qword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->read_qword)(byteaddress); }
+
+INLINE void program_write_byte (offs_t byteaddress, UINT8 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_byte)(byteaddress, data); }
+INLINE void program_write_word (offs_t byteaddress, UINT16 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_word)(byteaddress, data); }
+INLINE void program_write_dword(offs_t byteaddress, UINT32 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_dword)(byteaddress, data); }
+INLINE void program_write_qword(offs_t byteaddress, UINT64 data) { (*active_address_space[ADDRESS_SPACE_PROGRAM].accessors->write_qword)(byteaddress, data); }
+
+INLINE UINT8 data_read_byte (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_byte)(byteaddress); }
+INLINE UINT16 data_read_word (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_word)(byteaddress); }
+INLINE UINT32 data_read_dword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_dword)(byteaddress); }
+INLINE UINT64 data_read_qword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_DATA].accessors->read_qword)(byteaddress); }
+
+INLINE void data_write_byte (offs_t byteaddress, UINT8 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_byte)(byteaddress, data); }
+INLINE void data_write_word (offs_t byteaddress, UINT16 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_word)(byteaddress, data); }
+INLINE void data_write_dword(offs_t byteaddress, UINT32 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_dword)(byteaddress, data); }
+INLINE void data_write_qword(offs_t byteaddress, UINT64 data) { (*active_address_space[ADDRESS_SPACE_DATA].accessors->write_qword)(byteaddress, data); }
+
+INLINE UINT8 io_read_byte (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_byte)(byteaddress); }
+INLINE UINT16 io_read_word (offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_word)(byteaddress); }
+INLINE UINT32 io_read_dword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_dword)(byteaddress); }
+INLINE UINT64 io_read_qword(offs_t byteaddress) { return (*active_address_space[ADDRESS_SPACE_IO].accessors->read_qword)(byteaddress); }
+
+INLINE void io_write_byte (offs_t byteaddress, UINT8 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_byte)(byteaddress, data); }
+INLINE void io_write_word (offs_t byteaddress, UINT16 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_word)(byteaddress, data); }
+INLINE void io_write_dword(offs_t byteaddress, UINT32 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_dword)(byteaddress, data); }
+INLINE void io_write_qword(offs_t byteaddress, UINT64 data) { (*active_address_space[ADDRESS_SPACE_IO].accessors->write_qword)(byteaddress, data); }
/* ----- safe opcode and opcode argument reading ----- */
-UINT8 cpu_readop_safe(offs_t offset);
-UINT16 cpu_readop16_safe(offs_t offset);
-UINT32 cpu_readop32_safe(offs_t offset);
-UINT64 cpu_readop64_safe(offs_t offset);
-UINT8 cpu_readop_arg_safe(offs_t offset);
-UINT16 cpu_readop_arg16_safe(offs_t offset);
-UINT32 cpu_readop_arg32_safe(offs_t offset);
-UINT64 cpu_readop_arg64_safe(offs_t offset);
+UINT8 cpu_readop_safe(offs_t byteaddress);
+UINT16 cpu_readop16_safe(offs_t byteaddress);
+UINT32 cpu_readop32_safe(offs_t byteaddress);
+UINT64 cpu_readop64_safe(offs_t byteaddress);
+UINT8 cpu_readop_arg_safe(offs_t byteaddress);
+UINT16 cpu_readop_arg16_safe(offs_t byteaddress);
+UINT32 cpu_readop_arg32_safe(offs_t byteaddress);
+UINT64 cpu_readop_arg64_safe(offs_t byteaddress);
/* ----- unsafe opcode and opcode argument reading ----- */
#define cpu_opptr_unsafe(A) ((void *)&opcode_base[(A) & opcode_mask])
@@ -891,18 +901,18 @@ UINT64 cpu_readop_arg64_safe(offs_t offset);
#define cpu_readop_arg64_unsafe(A) (*(UINT64 *)&opcode_arg_base[(A) & opcode_mask])
/* ----- opcode and opcode argument reading ----- */
-INLINE void * cpu_opptr(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_opptr_unsafe(A); }
-INLINE UINT8 cpu_readop(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop_unsafe(A); }
-INLINE UINT16 cpu_readop16(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop16_unsafe(A); }
-INLINE UINT32 cpu_readop32(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop32_unsafe(A); }
-INLINE UINT64 cpu_readop64(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop64_unsafe(A); }
-INLINE UINT8 cpu_readop_arg(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop_arg_unsafe(A); }
-INLINE UINT16 cpu_readop_arg16(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop_arg16_unsafe(A); }
-INLINE UINT32 cpu_readop_arg32(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop_arg32_unsafe(A); }
-INLINE UINT64 cpu_readop_arg64(offs_t A) { if (address_is_unsafe(A)) { memory_set_opbase(A); } return cpu_readop_arg64_unsafe(A); }
+INLINE void * cpu_opptr(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_opptr_unsafe(byteaddress); }
+INLINE UINT8 cpu_readop(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_unsafe(byteaddress); }
+INLINE UINT16 cpu_readop16(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop16_unsafe(byteaddress); }
+INLINE UINT32 cpu_readop32(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop32_unsafe(byteaddress); }
+INLINE UINT64 cpu_readop64(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop64_unsafe(byteaddress); }
+INLINE UINT8 cpu_readop_arg(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg_unsafe(byteaddress); }
+INLINE UINT16 cpu_readop_arg16(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg16_unsafe(byteaddress); }
+INLINE UINT32 cpu_readop_arg32(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg32_unsafe(byteaddress); }
+INLINE UINT64 cpu_readop_arg64(offs_t byteaddress) { if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg64_unsafe(byteaddress); }
/* ----- bank switching for CPU cores ----- */
-#define change_pc(pc) do { memory_set_opbase(pc); } while (0)
+#define change_pc(byteaddress) do { memory_set_opbase(byteaddress); } while (0)
/* ----- forces the next branch to generate a call to the opbase handler ----- */
#define catch_nextBranch() do { opcode_entry = 0xff; } while (0)