From a0f4554285d9d14786779603f68672ea3847379f Mon Sep 17 00:00:00 2001 From: jensadne Date: Tue, 2 Sep 2008 20:35:06 +0000 Subject: [PATCH] Vi har lekt. Og kanskje kommet litt lengre. --- TIKI-100_emul-src/messaudio/ay8910.c | 6 +- TIKI-100_emul-src/messaudio/ay8910.h | 19 +- TIKI-100_emul-src/messaudio/bitmap.h | 169 +++ TIKI-100_emul-src/messaudio/corefile.h | 116 ++ TIKI-100_emul-src/messaudio/corestr.h | 60 ++ TIKI-100_emul-src/messaudio/coreutil.h | 44 + TIKI-100_emul-src/messaudio/cpuintrf.h | 543 ++++++++++ TIKI-100_emul-src/messaudio/deprecat.h | 70 ++ TIKI-100_emul-src/messaudio/devintrf.h | 320 ++++++ TIKI-100_emul-src/messaudio/mamecore.h | 348 ++++++ TIKI-100_emul-src/messaudio/memory.h | 1335 ++++++++++++++++++++++++ TIKI-100_emul-src/messaudio/osdcomm.h | 187 ++++ TIKI-100_emul-src/messaudio/osdcore.h | 802 ++++++++++++++ TIKI-100_emul-src/messaudio/palette.h | 259 +++++ TIKI-100_emul-src/messaudio/sndintrf.h | 298 ++++++ TIKI-100_emul-src/messaudio/streams.h | 96 ++ TIKI-100_emul-src/messaudio/tokenize.h | 245 +++++ 17 files changed, 4912 insertions(+), 5 deletions(-) create mode 100644 TIKI-100_emul-src/messaudio/bitmap.h create mode 100644 TIKI-100_emul-src/messaudio/corefile.h create mode 100644 TIKI-100_emul-src/messaudio/corestr.h create mode 100644 TIKI-100_emul-src/messaudio/coreutil.h create mode 100644 TIKI-100_emul-src/messaudio/cpuintrf.h create mode 100644 TIKI-100_emul-src/messaudio/deprecat.h create mode 100644 TIKI-100_emul-src/messaudio/devintrf.h create mode 100644 TIKI-100_emul-src/messaudio/mamecore.h create mode 100644 TIKI-100_emul-src/messaudio/memory.h create mode 100644 TIKI-100_emul-src/messaudio/osdcomm.h create mode 100644 TIKI-100_emul-src/messaudio/osdcore.h create mode 100644 TIKI-100_emul-src/messaudio/palette.h create mode 100644 TIKI-100_emul-src/messaudio/sndintrf.h create mode 100644 TIKI-100_emul-src/messaudio/streams.h create mode 100644 TIKI-100_emul-src/messaudio/tokenize.h diff --git a/TIKI-100_emul-src/messaudio/ay8910.c b/TIKI-100_emul-src/messaudio/ay8910.c index 289def7..c597eb4 100644 --- a/TIKI-100_emul-src/messaudio/ay8910.c +++ b/TIKI-100_emul-src/messaudio/ay8910.c @@ -100,10 +100,10 @@ has twice the steps, happening twice as fast. ***************************************************************************/ -#include "sndintrf.h" +//#include "sndintrf.h" #include "deprecat.h" -#include "streams.h" -#include "cpuintrf.h" +//#include "streams.h" +//#include "cpuintrf.h" #include "ay8910.h" /************************************* diff --git a/TIKI-100_emul-src/messaudio/ay8910.h b/TIKI-100_emul-src/messaudio/ay8910.h index 560807c..03e30c2 100644 --- a/TIKI-100_emul-src/messaudio/ay8910.h +++ b/TIKI-100_emul-src/messaudio/ay8910.h @@ -1,8 +1,23 @@ -#pragma once - #ifndef __AY8910_H__ #define __AY8910_H__ +//#include "osdcomm.h" +#include "mamecore.h" +#include "memory.h" +//typedef UINT32 offs_t; + +//typedef UINT8 (*read8_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset); + +/* machine read/write handler function macros */ +#define READ8_HANDLER(name) UINT8 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset) +#define WRITE8_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data) +#define READ16_HANDLER(name) UINT16 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 mem_mask) +#define WRITE16_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) +#define READ32_HANDLER(name) UINT32 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 mem_mask) +#define WRITE32_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 data, ATTR_UNUSED UINT32 mem_mask) +#define READ64_HANDLER(name) UINT64 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 mem_mask) +#define WRITE64_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 data, ATTR_UNUSED UINT64 mem_mask) + /* AY-3-8910A: 2 I/O ports AY-3-8912A: 1 I/O port diff --git a/TIKI-100_emul-src/messaudio/bitmap.h b/TIKI-100_emul-src/messaudio/bitmap.h new file mode 100644 index 0000000..ab484a0 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/bitmap.h @@ -0,0 +1,169 @@ +/*************************************************************************** + + bitmap.h + + Core bitmap routines. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __BITMAP_H__ +#define __BITMAP_H__ + +#include "osdcore.h" +#include "palette.h" + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* bitmap_format describes the various bitmap formats we use */ +enum _bitmap_format +{ + BITMAP_FORMAT_INVALID = 0, /* invalid format */ + BITMAP_FORMAT_INDEXED8, /* 8bpp indexed */ + BITMAP_FORMAT_INDEXED16, /* 16bpp indexed */ + BITMAP_FORMAT_INDEXED32, /* 32bpp indexed */ + BITMAP_FORMAT_RGB15, /* 15bpp 5-5-5 RGB */ + BITMAP_FORMAT_RGB32, /* 32bpp 8-8-8 RGB */ + BITMAP_FORMAT_ARGB32, /* 32bpp 8-8-8-8 ARGB */ + BITMAP_FORMAT_YUY16, /* 16bpp 8-8 Y/Cb, Y/Cr in sequence */ + BITMAP_FORMAT_LAST +}; +typedef enum _bitmap_format bitmap_format; + + +/* rectangles describe a bitmap portion */ +typedef struct _rectangle rectangle; +struct _rectangle +{ + int min_x; /* minimum X, or left coordinate */ + int max_x; /* maximum X, or right coordinate (inclusive) */ + int min_y; /* minimum Y, or top coordinate */ + int max_y; /* maximum Y, or bottom coordinate (inclusive) */ +}; + + +/* bitmaps describe a rectangular array of pixels */ +typedef struct _bitmap_t bitmap_t; +struct _bitmap_t +{ + void * alloc; /* pointer to allocated pixel memory */ + void * base; /* pointer to pixel (0,0) (adjusted for padding) */ + int rowpixels; /* pixels per row (including padding) */ + int width; /* width of the bitmap */ + int height; /* height of the bitmap */ + bitmap_format format; /* format of the bitmap */ + int bpp; /* bits per pixel */ + palette_t * palette; /* optional palette */ +}; + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +/* Macros for accessing bitmap pixels */ +#define BITMAP_ADDR(bitmap, type, y, x) \ + ((type *)(bitmap)->base + (y) * (bitmap)->rowpixels + (x)) + +#define BITMAP_ADDR8(bitmap, y, x) BITMAP_ADDR(bitmap, UINT8, y, x) +#define BITMAP_ADDR16(bitmap, y, x) BITMAP_ADDR(bitmap, UINT16, y, x) +#define BITMAP_ADDR32(bitmap, y, x) BITMAP_ADDR(bitmap, UINT32, y, x) + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + + +/* ----- bitmap allocation ----- */ + +/* allocate a new bitmap of the given dimensions and format */ +bitmap_t *bitmap_alloc(int width, int height, bitmap_format format); + +/* allocate a new bitmap with additional slop on the borders */ +bitmap_t *bitmap_alloc_slop(int width, int height, int xslop, int yslop, bitmap_format format); + +/* wrap a bitmap object around an existing array of data */ +bitmap_t *bitmap_wrap(void *base, int width, int height, int rowpixels, bitmap_format format); + +/* associate a palette with a bitmap */ +void bitmap_set_palette(bitmap_t *bitmap, palette_t *palette); + +/* free allocated data for a bitmap */ +void bitmap_free(bitmap_t *bitmap); + + + +/* ----- bitmap drawing ----- */ + +/* fill a bitmap with a single color, clipping to the given rectangle */ +void bitmap_fill(bitmap_t *dest, const rectangle *clip, rgb_t color); + + + +/* ----- bitmap utilities ----- */ + +/* return the number of bits per pixel for a given bitmap format */ +int bitmap_format_to_bpp(bitmap_format format); + + + + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +/*------------------------------------------------- + sect_rect - compute the intersection of two + rectangles +-------------------------------------------------*/ + +INLINE void sect_rect(rectangle *dst, const rectangle *src) +{ + if (src->min_x > dst->min_x) dst->min_x = src->min_x; + if (src->max_x < dst->max_x) dst->max_x = src->max_x; + if (src->min_y > dst->min_y) dst->min_y = src->min_y; + if (src->max_y < dst->max_y) dst->max_y = src->max_y; +} + + +/*------------------------------------------------- + union_rect - compute the union of two + rectangles +-------------------------------------------------*/ + +INLINE void union_rect(rectangle *dst, const rectangle *src) +{ + if (src->min_x < dst->min_x) dst->min_x = src->min_x; + if (src->max_x > dst->max_x) dst->max_x = src->max_x; + if (src->min_y < dst->min_y) dst->min_y = src->min_y; + if (src->max_y > dst->max_y) dst->max_y = src->max_y; +} + + +/*------------------------------------------------- + plot_box - draw a filled rectangle into a + bitmap of arbitrary depth +-------------------------------------------------*/ + +INLINE void plot_box(bitmap_t *bitmap, int x, int y, int width, int height, UINT32 color) +{ + rectangle clip; + clip.min_x = x; + clip.min_y = y; + clip.max_x = x + width - 1; + clip.max_y = y + height - 1; + bitmap_fill(bitmap, &clip, color); +} + + +#endif /* __BITMAP_H__ */ diff --git a/TIKI-100_emul-src/messaudio/corefile.h b/TIKI-100_emul-src/messaudio/corefile.h new file mode 100644 index 0000000..c2dda7e --- /dev/null +++ b/TIKI-100_emul-src/messaudio/corefile.h @@ -0,0 +1,116 @@ +/*************************************************************************** + + corefile.h + + Core file I/O interface functions and definitions. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __COREFILE_H__ +#define __COREFILE_H__ + +#include +#include "osdcore.h" +#include "astring.h" + + + +/*************************************************************************** + ADDITIONAL OPEN FLAGS +***************************************************************************/ + +#define OPEN_FLAG_NO_BOM 0x0100 /* don't output BOM */ + + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +typedef struct _core_file core_file; + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + + +/* ----- file open/close ----- */ + +/* open a file with the specified filename */ +file_error core_fopen(const char *filename, UINT32 openflags, core_file **file); + +/* open a RAM-based "file" using the given data and length (read-only) */ +file_error core_fopen_ram(const void *data, size_t length, UINT32 openflags, core_file **file); + +/* close an open file */ +void core_fclose(core_file *file); + + + +/* ----- file positioning ----- */ + +/* adjust the file pointer within the file */ +int core_fseek(core_file *file, INT64 offset, int whence); + +/* return the current file pointer */ +UINT64 core_ftell(core_file *file); + +/* return true if we are at the EOF */ +int core_feof(core_file *file); + +/* return the total size of the file */ +UINT64 core_fsize(core_file *file); + + + +/* ----- file read ----- */ + +/* standard binary read from a file */ +UINT32 core_fread(core_file *file, void *buffer, UINT32 length); + +/* read one character from the file */ +int core_fgetc(core_file *file); + +/* put back one character from the file */ +int core_ungetc(int c, core_file *file); + +/* read a full line of text from the file */ +char *core_fgets(char *s, int n, core_file *file); + +/* get a pointer to a buffer that holds the full file data in RAM */ +/* this function may cause the full file data to be read */ +const void *core_fbuffer(core_file *file); + + + +/* ----- file write ----- */ + +/* standard binary write to a file */ +UINT32 core_fwrite(core_file *file, const void *buffer, UINT32 length); + +/* write a line of text to the file */ +int core_fputs(core_file *f, const char *s); + +/* printf-style text write to a file */ +int core_vfprintf(core_file *f, const char *fmt, va_list va); +int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...) ATTR_PRINTF(2,3); + + + +/* ----- filename utilities ----- */ + +/* extract the base part of a filename (remove extensions and paths) */ +astring *core_filename_extract_base(astring *result, const char *name, int strip_extension); + +/* true if the given filename ends with a particular extension */ +int core_filename_ends_with(const char *filename, const char *extension); + + +#endif /* __COREFILE_H__ */ diff --git a/TIKI-100_emul-src/messaudio/corestr.h b/TIKI-100_emul-src/messaudio/corestr.h new file mode 100644 index 0000000..aa5fe21 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/corestr.h @@ -0,0 +1,60 @@ +/*************************************************************************** + + corestr.h + + Core string functions used throughout MAME. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __CORESTR_H__ +#define __CORESTR_H__ + +#include + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + +/* since stricmp is not part of the standard, we use this instead */ +int core_stricmp(const char *s1, const char *s2); + +/* this macro prevents people from using stricmp directly */ +#undef stricmp +#define stricmp !MUST_USE_CORE_STRICMP_INSTEAD! + +/* this macro prevents people from using strcasecmp directly */ +#undef strcasecmp +#define strcasecmp !MUST_USE_CORE_STRICMP_INSTEAD! + + +/* since strnicmp is not part of the standard, we use this instead */ +int core_strnicmp(const char *s1, const char *s2, size_t n); + +/* this macro prevents people from using strnicmp directly */ +#undef strnicmp +#define strnicmp !MUST_USE_CORE_STRNICMP_INSTEAD! + +/* this macro prevents people from using strncasecmp directly */ +#undef strncasecmp +#define strncasecmp !MUST_USE_CORE_STRNICMP_INSTEAD! + + +/* since strdup is not part of the standard, we use this instead */ +char *core_strdup(const char *str); + +/* this macro prevents people from using strdup directly */ +#undef strdup +#define strdup !MUST_USE_CORE_STRDUP_INSTEAD! + + +/* additional string compare helper */ +int core_strwildcmp(const char *sp1, const char *sp2); + + +#endif /* __CORESTR_H__ */ diff --git a/TIKI-100_emul-src/messaudio/coreutil.h b/TIKI-100_emul-src/messaudio/coreutil.h new file mode 100644 index 0000000..b6d4bb1 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/coreutil.h @@ -0,0 +1,44 @@ +/*************************************************************************** + + coreutil.h + + Miscellaneous utility code + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __COREUTIL_H__ +#define __COREUTIL_H__ + +#include "osdcomm.h" + + +/*************************************************************************** + BINARY CODED DECIMAL HELPERS +***************************************************************************/ + +int bcd_adjust(int value); +UINT32 dec_2_bcd(UINT32 a); +UINT32 bcd_2_dec(UINT32 a); + + +/*************************************************************************** + GREGORIAN CALENDAR HELPERS +***************************************************************************/ + +int gregorian_is_leap_year(int year); +int gregorian_days_in_month(int month, int year); + + +/*************************************************************************** + MISC +***************************************************************************/ + +void rand_memory(void *memory, size_t length); + + +#endif /* __COREUTIL_H__ */ diff --git a/TIKI-100_emul-src/messaudio/cpuintrf.h b/TIKI-100_emul-src/messaudio/cpuintrf.h new file mode 100644 index 0000000..f319066 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/cpuintrf.h @@ -0,0 +1,543 @@ +/*************************************************************************** + + cpuintrf.h + + Core CPU interface functions and definitions. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __CPUINTRF_H__ +#define __CPUINTRF_H__ + +#include "cpuint.h" +#include "cpuexec.h" +#include "watchdog.h" +#include "mame.h" +#include "state.h" + + +/*************************************************************************** + CONSTANTS +***************************************************************************/ + +#define MAX_CPU 8 + + +/* Interrupt line constants */ +enum +{ + /* line states */ + CLEAR_LINE = 0, /* clear (a fired, held or pulsed) line */ + ASSERT_LINE, /* assert an interrupt immediately */ + HOLD_LINE, /* hold interrupt line until acknowledged */ + PULSE_LINE, /* pulse interrupt line for one instruction */ + + /* internal flags (not for use by drivers!) */ + INTERNAL_CLEAR_LINE = 100 + CLEAR_LINE, + INTERNAL_ASSERT_LINE = 100 + ASSERT_LINE, + + /* input lines */ + MAX_INPUT_LINES = 32+3, + INPUT_LINE_IRQ0 = 0, + INPUT_LINE_IRQ1 = 1, + INPUT_LINE_IRQ2 = 2, + INPUT_LINE_IRQ3 = 3, + INPUT_LINE_IRQ4 = 4, + INPUT_LINE_IRQ5 = 5, + INPUT_LINE_IRQ6 = 6, + INPUT_LINE_IRQ7 = 7, + INPUT_LINE_IRQ8 = 8, + INPUT_LINE_IRQ9 = 9, + INPUT_LINE_NMI = MAX_INPUT_LINES - 3, + + /* special input lines that are implemented in the core */ + INPUT_LINE_RESET = MAX_INPUT_LINES - 2, + INPUT_LINE_HALT = MAX_INPUT_LINES - 1, + + /* output lines */ + MAX_OUTPUT_LINES = 32 +}; + + +/* Maximum number of registers of any CPU */ +enum +{ + MAX_REGS = 256 +}; + + +/* CPU information constants */ +enum +{ + /* --- the following bits of info are returned as 64-bit signed integers --- */ + CPUINFO_INT_FIRST = 0x00000, + + CPUINFO_INT_CONTEXT_SIZE = CPUINFO_INT_FIRST, /* R/O: size of CPU context in bytes */ + CPUINFO_INT_INPUT_LINES, /* R/O: number of input lines */ + CPUINFO_INT_OUTPUT_LINES, /* R/O: number of output lines */ + CPUINFO_INT_DEFAULT_IRQ_VECTOR, /* R/O: default IRQ vector */ + CPUINFO_INT_ENDIANNESS, /* R/O: either CPU_IS_BE or CPU_IS_LE */ + CPUINFO_INT_CLOCK_MULTIPLIER, /* R/O: internal clock multiplier */ + CPUINFO_INT_CLOCK_DIVIDER, /* R/O: internal clock divider */ + CPUINFO_INT_MIN_INSTRUCTION_BYTES, /* R/O: minimum bytes per instruction */ + CPUINFO_INT_MAX_INSTRUCTION_BYTES, /* R/O: maximum bytes per instruction */ + CPUINFO_INT_MIN_CYCLES, /* R/O: minimum cycles for a single instruction */ + CPUINFO_INT_MAX_CYCLES, /* R/O: maximum cycles for a single instruction */ + + CPUINFO_INT_DATABUS_WIDTH, /* R/O: data bus size for each address space (8,16,32,64) */ + CPUINFO_INT_DATABUS_WIDTH_LAST = CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACES - 1, + CPUINFO_INT_ADDRBUS_WIDTH, /* R/O: address bus size for each address space (12-32) */ + CPUINFO_INT_ADDRBUS_WIDTH_LAST = CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACES - 1, + CPUINFO_INT_ADDRBUS_SHIFT, /* R/O: shift applied to addresses each address space (+3 means >>3, -1 means <<1) */ + CPUINFO_INT_ADDRBUS_SHIFT_LAST = CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACES - 1, + CPUINFO_INT_LOGADDR_WIDTH, /* R/O: address bus size for logical accesses in each space (0=same as physical) */ + CPUINFO_INT_LOGADDR_WIDTH_LAST = CPUINFO_INT_LOGADDR_WIDTH + ADDRESS_SPACES - 1, + CPUINFO_INT_PAGE_SHIFT, /* R/O: size of a page log 2 (i.e., 12=4096), or 0 if paging not supported */ + CPUINFO_INT_PAGE_SHIFT_LAST = CPUINFO_INT_PAGE_SHIFT + ADDRESS_SPACES - 1, + + CPUINFO_INT_SP, /* R/W: the current stack pointer value */ + CPUINFO_INT_PC, /* R/W: the current PC value */ + CPUINFO_INT_PREVIOUSPC, /* R/W: the previous PC value */ + CPUINFO_INT_INPUT_STATE, /* R/W: states for each input line */ + CPUINFO_INT_INPUT_STATE_LAST = CPUINFO_INT_INPUT_STATE + MAX_INPUT_LINES - 1, + CPUINFO_INT_OUTPUT_STATE, /* R/W: states for each output line */ + CPUINFO_INT_OUTPUT_STATE_LAST = CPUINFO_INT_OUTPUT_STATE + MAX_OUTPUT_LINES - 1, + CPUINFO_INT_REGISTER, /* R/W: values of up to MAX_REGs registers */ + CPUINFO_INT_REGISTER_LAST = CPUINFO_INT_REGISTER + MAX_REGS - 1, + + CPUINFO_INT_CPU_SPECIFIC = 0x08000, /* R/W: CPU-specific values start here */ + + /* --- the following bits of info are returned as pointers to data or functions --- */ + CPUINFO_PTR_FIRST = 0x10000, + + CPUINFO_PTR_SET_INFO = CPUINFO_PTR_FIRST, /* R/O: void (*set_info)(UINT32 state, INT64 data, void *ptr) */ + CPUINFO_PTR_GET_CONTEXT, /* R/O: void (*get_context)(void *buffer) */ + CPUINFO_PTR_SET_CONTEXT, /* R/O: void (*set_context)(void *buffer) */ + CPUINFO_PTR_INIT, /* R/O: void (*init)(int index, int clock, const void *config, int (*irqcallback)(int)) */ + CPUINFO_PTR_RESET, /* R/O: void (*reset)(void) */ + CPUINFO_PTR_EXIT, /* R/O: void (*exit)(void) */ + CPUINFO_PTR_EXECUTE, /* R/O: int (*execute)(int cycles) */ + CPUINFO_PTR_BURN, /* R/O: void (*burn)(int cycles) */ + CPUINFO_PTR_DISASSEMBLE, /* R/O: offs_t (*disassemble)(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) */ + CPUINFO_PTR_TRANSLATE, /* R/O: int (*translate)(int space, int intention, offs_t *address) */ + CPUINFO_PTR_READ, /* R/O: int (*read)(int space, UINT32 offset, int size, UINT64 *value) */ + CPUINFO_PTR_WRITE, /* R/O: int (*write)(int space, UINT32 offset, int size, UINT64 value) */ + CPUINFO_PTR_READOP, /* R/O: int (*readop)(UINT32 offset, int size, UINT64 *value) */ + CPUINFO_PTR_DEBUG_SETUP_COMMANDS, /* R/O: void (*setup_commands)(void) */ + CPUINFO_PTR_INSTRUCTION_COUNTER, /* R/O: int *icount */ + CPUINFO_PTR_INTERNAL_MEMORY_MAP, /* R/O: const addrmap_token *map */ + CPUINFO_PTR_INTERNAL_MEMORY_MAP_LAST = CPUINFO_PTR_INTERNAL_MEMORY_MAP + ADDRESS_SPACES - 1, + CPUINFO_PTR_DEBUG_REGISTER_LIST, /* R/O: int *list: list of registers for the debugger */ + CPUINFO_PTR_VALIDITY_CHECK, /* R/O: int (*validity_check)(const void *config) */ + + CPUINFO_PTR_CPU_SPECIFIC = 0x18000, /* R/W: CPU-specific values start here */ + + /* --- the following bits of info are returned as NULL-terminated strings --- */ + CPUINFO_STR_FIRST = 0x20000, + + CPUINFO_STR_NAME = CPUINFO_STR_FIRST, /* R/O: name of the CPU */ + CPUINFO_STR_CORE_FAMILY, /* R/O: family of the CPU */ + CPUINFO_STR_CORE_VERSION, /* R/O: version of the CPU core */ + CPUINFO_STR_CORE_FILE, /* R/O: file containing the CPU core */ + CPUINFO_STR_CORE_CREDITS, /* R/O: credits for the CPU core */ + CPUINFO_STR_FLAGS, /* R/O: string representation of the main flags value */ + CPUINFO_STR_REGISTER, /* R/O: string representation of up to MAX_REGs registers */ + CPUINFO_STR_REGISTER_LAST = CPUINFO_STR_REGISTER + MAX_REGS - 1, + + CPUINFO_STR_CPU_SPECIFIC = 0x28000 /* R/W: CPU-specific values start here */ +}; + + +/* get_reg/set_reg constants */ +enum +{ + /* This value is passed to activecpu_get_reg to retrieve the previous + * program counter value, ie. before a CPU emulation started + * to fetch opcodes and arguments for the current instrution. */ + REG_PREVIOUSPC = CPUINFO_INT_PREVIOUSPC - CPUINFO_INT_REGISTER, + + /* This value is passed to activecpu_get_reg to retrieve the current + * program counter value. */ + REG_PC = CPUINFO_INT_PC - CPUINFO_INT_REGISTER, + + /* This value is passed to activecpu_get_reg to retrieve the current + * stack pointer value. */ + REG_SP = CPUINFO_INT_SP - CPUINFO_INT_REGISTER +}; + + +/* Endianness constants */ +enum +{ + CPU_IS_LE = 0, /* emulated CPU is little endian */ + CPU_IS_BE /* emulated CPU is big endian */ +}; + + +/* Translation intentions */ +#define TRANSLATE_TYPE_MASK 0x03 /* read write or fetch */ +#define TRANSLATE_USER_MASK 0x04 /* user mode or fully privileged */ +#define TRANSLATE_DEBUG_MASK 0x08 /* debug mode (no side effects) */ + +#define TRANSLATE_READ 0 /* translate for read */ +#define TRANSLATE_WRITE 1 /* translate for write */ +#define TRANSLATE_FETCH 2 /* translate for instruction fetch */ +#define TRANSLATE_READ_USER (TRANSLATE_READ | TRANSLATE_USER_MASK) +#define TRANSLATE_WRITE_USER (TRANSLATE_WRITE | TRANSLATE_USER_MASK) +#define TRANSLATE_FETCH_USER (TRANSLATE_FETCH | TRANSLATE_USER_MASK) +#define TRANSLATE_READ_DEBUG (TRANSLATE_READ | TRANSLATE_DEBUG_MASK) +#define TRANSLATE_WRITE_DEBUG (TRANSLATE_WRITE | TRANSLATE_DEBUG_MASK) +#define TRANSLATE_FETCH_DEBUG (TRANSLATE_FETCH | TRANSLATE_DEBUG_MASK) + + +/* Disassembler constants */ +#define DASMFLAG_SUPPORTED 0x80000000 /* are disassembly flags supported? */ +#define DASMFLAG_STEP_OUT 0x40000000 /* this instruction should be the end of a step out sequence */ +#define DASMFLAG_STEP_OVER 0x20000000 /* this instruction should be stepped over by setting a breakpoint afterwards */ +#define DASMFLAG_OVERINSTMASK 0x18000000 /* number of extra instructions to skip when stepping over */ +#define DASMFLAG_OVERINSTSHIFT 27 /* bits to shift after masking to get the value */ +#define DASMFLAG_LENGTHMASK 0x0000ffff /* the low 16-bits contain the actual length */ +#define DASMFLAG_STEP_OVER_EXTRA(x) ((x) << DASMFLAG_OVERINSTSHIFT) + + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* forward declaration of this union */ +typedef union _cpuinfo cpuinfo; + + +/* define the various callback functions */ +typedef void (*cpu_get_info_func)(UINT32 state, cpuinfo *info); +typedef void (*cpu_set_info_func)(UINT32 state, cpuinfo *info); +typedef void (*cpu_get_context_func)(void *buffer); +typedef void (*cpu_set_context_func)(void *buffer); +typedef void (*cpu_init_func)(int index, int clock, const void *config, int (*irqcallback)(int)); +typedef void (*cpu_reset_func)(void); +typedef void (*cpu_exit_func)(void); +typedef int (*cpu_execute_func)(int cycles); +typedef void (*cpu_burn_func)(int cycles); +typedef offs_t (*cpu_disassemble_func)(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram); +typedef int (*cpu_translate_func)(int space, int intention, offs_t *address); +typedef int (*cpu_read_func)(int space, UINT32 offset, int size, UINT64 *value); +typedef int (*cpu_write_func)(int space, UINT32 offset, int size, UINT64 value); +typedef int (*cpu_readop_func)(UINT32 offset, int size, UINT64 *value); +typedef void (*cpu_setup_commands_func)(void); +typedef int (*cpu_validity_check_func)(const game_driver *driver, const void *config); + + +/* cpuinfo union used to pass data to/from the get_info/set_info functions */ +union _cpuinfo +{ + INT64 i; /* generic integers */ + void * p; /* generic pointers */ + genf * f; /* generic function pointers */ + char * s; /* generic strings */ + + cpu_set_info_func setinfo; /* CPUINFO_PTR_SET_INFO */ + cpu_get_context_func getcontext; /* CPUINFO_PTR_GET_CONTEXT */ + cpu_set_context_func setcontext; /* CPUINFO_PTR_SET_CONTEXT */ + cpu_init_func init; /* CPUINFO_PTR_INIT */ + cpu_reset_func reset; /* CPUINFO_PTR_RESET */ + cpu_exit_func exit; /* CPUINFO_PTR_EXIT */ + cpu_execute_func execute; /* CPUINFO_PTR_EXECUTE */ + cpu_burn_func burn; /* CPUINFO_PTR_BURN */ + cpu_disassemble_func disassemble; /* CPUINFO_PTR_DISASSEMBLE */ + cpu_translate_func translate; /* CPUINFO_PTR_TRANSLATE */ + cpu_read_func read; /* CPUINFO_PTR_READ */ + cpu_write_func write; /* CPUINFO_PTR_WRITE */ + cpu_readop_func readop; /* CPUINFO_PTR_READOP */ + cpu_setup_commands_func setup_commands; /* CPUINFO_PTR_DEBUG_SETUP_COMMANDS */ + int * icount; /* CPUINFO_PTR_INSTRUCTION_COUNTER */ + const addrmap8_token * internal_map8; /* CPUINFO_PTR_INTERNAL_MEMORY_MAP */ + const addrmap16_token * internal_map16; /* CPUINFO_PTR_INTERNAL_MEMORY_MAP */ + const addrmap32_token * internal_map32; /* CPUINFO_PTR_INTERNAL_MEMORY_MAP */ + const addrmap64_token * internal_map64; /* CPUINFO_PTR_INTERNAL_MEMORY_MAP */ + cpu_validity_check_func validity_check; /* CPUINFO_PTR_VALIDITY_CHECK */ +}; + + +typedef struct _cpu_interface cpu_interface; +struct _cpu_interface +{ + /* table of core functions */ + cpu_get_info_func get_info; + cpu_set_info_func set_info; + cpu_get_context_func get_context; + cpu_set_context_func set_context; + cpu_init_func init; + cpu_reset_func reset; + cpu_exit_func exit; + cpu_execute_func execute; + cpu_burn_func burn; + cpu_disassemble_func disassemble; + cpu_translate_func translate; + + /* other info */ + size_t context_size; + INT8 address_shift; + int * icount; +}; + + + +/*************************************************************************** + CORE CPU INTERFACE FUNCTIONS +***************************************************************************/ + +/* reset the internal CPU tracking */ +void cpuintrf_init(running_machine *machine); + +/* set up the interface for one CPU of a given type */ +int cpuintrf_init_cpu(int cpunum, cpu_type cputype, int clock, const void *config, int (*irqcallback)(int)); + +/* clean up the interface for one CPU */ +void cpuintrf_exit_cpu(int cpunum); + +/* remember the previous context and set a new one */ +void cpuintrf_push_context(int cpunum); + +/* restore the previous context */ +void cpuintrf_pop_context(void); + +/* circular string buffer */ +char *cpuintrf_temp_str(void); + +/* set the dasm override handler */ +void cpuintrf_set_dasm_override(int cpunum, offs_t (*dasm_override)(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram)); + + + +/*************************************************************************** + ACTIVE CPU ACCCESSORS +***************************************************************************/ + +/* get info accessors */ +INT64 activecpu_get_info_int(UINT32 state); +void *activecpu_get_info_ptr(UINT32 state); +genf *activecpu_get_info_fct(UINT32 state); +const char *activecpu_get_info_string(UINT32 state); + +/* set info accessors */ +void activecpu_set_info_int(UINT32 state, INT64 data); +void activecpu_set_info_ptr(UINT32 state, void *data); +void activecpu_set_info_fct(UINT32 state, genf *data); + +/* apply a +/- to the current icount */ +void activecpu_adjust_icount(int delta); + +/* return the current icount */ +int activecpu_get_icount(void); + +/* ensure banking is reset properly */ +void activecpu_reset_banking(void); + +/* set the input line on a CPU -- drivers use cpu_set_input_line() */ +void activecpu_set_input_line(int irqline, int state); + +/* return the PC, corrected to a byte offset, on the active CPU */ +offs_t activecpu_get_physical_pc_byte(void); + +/* update the banking on the active CPU */ +void activecpu_set_opbase(offs_t val); + +/* disassemble a line at a given PC on the active CPU */ +offs_t activecpu_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram); + +#define activecpu_context_size() activecpu_get_info_int(CPUINFO_INT_CONTEXT_SIZE) +#define activecpu_input_lines() activecpu_get_info_int(CPUINFO_INT_INPUT_LINES) +#define activecpu_output_lines() activecpu_get_info_int(CPUINFO_INT_OUTPUT_LINES) +#define activecpu_default_irq_vector() activecpu_get_info_int(CPUINFO_INT_DEFAULT_IRQ_VECTOR) +#define activecpu_endianness() activecpu_get_info_int(CPUINFO_INT_ENDIANNESS) +#define activecpu_clock_multiplier() activecpu_get_info_int(CPUINFO_INT_CLOCK_MULTIPLIER) +#define activecpu_clock_divider() activecpu_get_info_int(CPUINFO_INT_CLOCK_DIVIDER) +#define activecpu_min_instruction_bytes() activecpu_get_info_int(CPUINFO_INT_MIN_INSTRUCTION_BYTES) +#define activecpu_max_instruction_bytes() activecpu_get_info_int(CPUINFO_INT_MAX_INSTRUCTION_BYTES) +#define activecpu_min_cycles() activecpu_get_info_int(CPUINFO_INT_MIN_CYCLES) +#define activecpu_max_cycles() activecpu_get_info_int(CPUINFO_INT_MAX_CYCLES) +#define activecpu_databus_width(space) activecpu_get_info_int(CPUINFO_INT_DATABUS_WIDTH + (space)) +#define activecpu_addrbus_width(space) activecpu_get_info_int(CPUINFO_INT_ADDRBUS_WIDTH + (space)) +#define activecpu_addrbus_shift(space) activecpu_get_info_int(CPUINFO_INT_ADDRBUS_SHIFT + (space)) +#define activecpu_logaddr_width(space) activecpu_get_info_int(CPUINFO_INT_LOGADDR_WIDTH + (space)) +#define activecpu_page_shift(space) activecpu_get_info_int(CPUINFO_INT_PAGE_SHIFT + (space)) +#define activecpu_get_reg(reg) activecpu_get_info_int(CPUINFO_INT_REGISTER + (reg)) +#define activecpu_debug_register_list() activecpu_get_info_ptr(CPUINFO_PTR_DEBUG_REGISTER_LIST) +#define activecpu_name() activecpu_get_info_string(CPUINFO_STR_NAME) +#define activecpu_core_family() activecpu_get_info_string(CPUINFO_STR_CORE_FAMILY) +#define activecpu_core_version() activecpu_get_info_string(CPUINFO_STR_CORE_VERSION) +#define activecpu_core_file() activecpu_get_info_string(CPUINFO_STR_CORE_FILE) +#define activecpu_core_credits() activecpu_get_info_string(CPUINFO_STR_CORE_CREDITS) +#define activecpu_flags() activecpu_get_info_string(CPUINFO_STR_FLAGS) +#define activecpu_irq_string(irq) activecpu_get_info_string(CPUINFO_STR_IRQ_STATE + (irq)) +#define activecpu_reg_string(reg) activecpu_get_info_string(CPUINFO_STR_REGISTER + (reg)) + +#define activecpu_set_reg(reg, val) activecpu_set_info_int(CPUINFO_INT_REGISTER + (reg), (val)) + + + +/*************************************************************************** + SPECIFIC CPU ACCCESSORS +***************************************************************************/ + +/* get info accessors */ +INT64 cpunum_get_info_int(int cpunum, UINT32 state); +void *cpunum_get_info_ptr(int cpunum, UINT32 state); +genf *cpunum_get_info_fct(int cpunum, UINT32 state); +const char *cpunum_get_info_string(int cpunum, UINT32 state); + +/* set info accessors */ +void cpunum_set_info_int(int cpunum, UINT32 state, INT64 data); +void cpunum_set_info_ptr(int cpunum, UINT32 state, void *data); +void cpunum_set_info_fct(int cpunum, UINT32 state, genf *data); + +/* execute the requested cycles on a given CPU */ +int cpunum_execute(int cpunum, int cycles); + +/* signal a reset for a given CPU */ +void cpunum_reset(int cpunum); + +/* read a byte from another CPU's memory space */ +UINT8 cpunum_read_byte(int cpunum, offs_t address); + +/* write a byte from another CPU's memory space */ +void cpunum_write_byte(int cpunum, offs_t address, UINT8 data); + +/* return a pointer to the saved context of a given CPU, or NULL if the + context is active (and contained within the CPU core */ +void *cpunum_get_context_ptr(int cpunum); + +/* return the PC, corrected to a byte offset, on a given CPU */ +offs_t cpunum_get_physical_pc_byte(int cpunum); + +/* update the banking on a given CPU */ +void cpunum_set_opbase(int cpunum, offs_t val); + +/* disassemble a line at a given PC on a given CPU */ +offs_t cpunum_dasm(int cpunum, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram); + +#define cpunum_context_size(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_CONTEXT_SIZE) +#define cpunum_input_lines(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_INPUT_LINES) +#define cpunum_output_lines(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_OUTPUT_LINES) +#define cpunum_default_irq_vector(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_DEFAULT_IRQ_VECTOR) +#define cpunum_endianness(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_ENDIANNESS) +#define cpunum_clock_multiplier(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_CLOCK_MULTIPLIER) +#define cpunum_clock_divider(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_CLOCK_DIVIDER) +#define cpunum_min_instruction_bytes(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_MIN_INSTRUCTION_BYTES) +#define cpunum_max_instruction_bytes(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_MAX_INSTRUCTION_BYTES) +#define cpunum_min_cycles(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_MIN_CYCLES) +#define cpunum_max_cycles(cpunum) cpunum_get_info_int(cpunum, CPUINFO_INT_MAX_CYCLES) +#define cpunum_databus_width(cpunum, space) cpunum_get_info_int(cpunum, CPUINFO_INT_DATABUS_WIDTH + (space)) +#define cpunum_addrbus_width(cpunum, space) cpunum_get_info_int(cpunum, CPUINFO_INT_ADDRBUS_WIDTH + (space)) +#define cpunum_addrbus_shift(cpunum, space) cpunum_get_info_int(cpunum, CPUINFO_INT_ADDRBUS_SHIFT + (space)) +#define cpunum_logaddr_width(cpunum, space) cpunum_get_info_int(cpunum, CPUINFO_INT_LOGADDR_WIDTH + (space)) +#define cpunum_page_shift(cpunum, space) cpunum_get_info_int(cpunum, CPUINFO_INT_PAGE_SHIFT + (space)) +#define cpunum_get_reg(cpunum, reg) cpunum_get_info_int(cpunum, CPUINFO_INT_REGISTER + (reg)) +#define cpunum_debug_register_list(cpunum) cpunum_get_info_ptr(cpunum, CPUINFO_PTR_DEBUG_REGISTER_LIST) +#define cpunum_name(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_NAME) +#define cpunum_core_family(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_CORE_FAMILY) +#define cpunum_core_version(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_CORE_VERSION) +#define cpunum_core_file(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_CORE_FILE) +#define cpunum_core_credits(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_CORE_CREDITS) +#define cpunum_flags(cpunum) cpunum_get_info_string(cpunum, CPUINFO_STR_FLAGS) +#define cpunum_irq_string(cpunum, irq) cpunum_get_info_string(cpunum, CPUINFO_STR_IRQ_STATE + (irq)) +#define cpunum_reg_string(cpunum, reg) cpunum_get_info_string(cpunum, CPUINFO_STR_REGISTER + (reg)) + +#define cpunum_set_reg(cpunum, reg, val) cpunum_set_info_int(cpunum, CPUINFO_INT_REGISTER + (reg), (val)) + + + +/*************************************************************************** + CPU TYPE ACCCESSORS +***************************************************************************/ + +/* get info accessors */ +INT64 cputype_get_info_int(cpu_type cputype, UINT32 state); +void *cputype_get_info_ptr(cpu_type cputype, UINT32 state); +genf *cputype_get_info_fct(cpu_type cputype, UINT32 state); +const char *cputype_get_info_string(cpu_type cputype, UINT32 state); + +#define cputype_context_size(cputype) cputype_get_info_int(cputype, CPUINFO_INT_CONTEXT_SIZE) +#define cputype_input_lines(cputype) cputype_get_info_int(cputype, CPUINFO_INT_INPUT_LINES) +#define cputype_output_lines(cputype) cputype_get_info_int(cputype, CPUINFO_INT_OUTPUT_LINES) +#define cputype_default_irq_vector(cputype) cputype_get_info_int(cputype, CPUINFO_INT_DEFAULT_IRQ_VECTOR) +#define cputype_endianness(cputype) cputype_get_info_int(cputype, CPUINFO_INT_ENDIANNESS) +#define cputype_clock_multiplier(cputype) cputype_get_info_int(cputype, CPUINFO_INT_CLOCK_MULTIPLIER) +#define cputype_clock_divider(cputype) cputype_get_info_int(cputype, CPUINFO_INT_CLOCK_DIVIDER) +#define cputype_min_instruction_bytes(cputype) cputype_get_info_int(cputype, CPUINFO_INT_MIN_INSTRUCTION_BYTES) +#define cputype_max_instruction_bytes(cputype) cputype_get_info_int(cputype, CPUINFO_INT_MAX_INSTRUCTION_BYTES) +#define cputype_min_cycles(cputype) cputype_get_info_int(cputype, CPUINFO_INT_MIN_CYCLES) +#define cputype_max_cycles(cputype) cputype_get_info_int(cputype, CPUINFO_INT_MAX_CYCLES) +#define cputype_databus_width(cputype, space) cputype_get_info_int(cputype, CPUINFO_INT_DATABUS_WIDTH + (space)) +#define cputype_addrbus_width(cputype, space) cputype_get_info_int(cputype, CPUINFO_INT_ADDRBUS_WIDTH + (space)) +#define cputype_addrbus_shift(cputype, space) cputype_get_info_int(cputype, CPUINFO_INT_ADDRBUS_SHIFT + (space)) +#define cputype_page_shift(cputype, space) cputype_get_info_int(cputype, CPUINFO_INT_PAGE_SHIFT + (space)) +#define cputype_debug_register_list(cputype) cputype_get_info_ptr(cputype, CPUINFO_PTR_DEBUG_REGISTER_LIST) +#define cputype_name(cputype) cputype_get_info_string(cputype, CPUINFO_STR_NAME) +#define cputype_core_family(cputype) cputype_get_info_string(cputype, CPUINFO_STR_CORE_FAMILY) +#define cputype_core_version(cputype) cputype_get_info_string(cputype, CPUINFO_STR_CORE_VERSION) +#define cputype_core_file(cputype) cputype_get_info_string(cputype, CPUINFO_STR_CORE_FILE) +#define cputype_core_credits(cputype) cputype_get_info_string(cputype, CPUINFO_STR_CORE_CREDITS) + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +#define activecpu_get_previouspc() ((offs_t)activecpu_get_reg(REG_PREVIOUSPC)) +#define activecpu_get_pc() ((offs_t)activecpu_get_reg(REG_PC)) +#define activecpu_get_sp() activecpu_get_reg(REG_SP) + + + +/*************************************************************************** + CPU INTERFACE ACCESSORS +***************************************************************************/ + +/* return a pointer to the interface struct for a given CPU type */ +INLINE const cpu_interface *cputype_get_interface(cpu_type cputype) +{ + extern cpu_interface cpuintrf[]; + return &cpuintrf[cputype]; +} + + +/* return a the index of the active CPU */ +INLINE int cpu_getactivecpu(void) +{ + extern int activecpu; + return activecpu; +} + + +/* return a the index of the executing CPU */ +INLINE int cpu_getexecutingcpu(void) +{ + extern int executingcpu; + return executingcpu; +} + + +/* return a the total number of registered CPUs */ +INLINE int cpu_gettotalcpu(void) +{ + extern int totalcpu; + return totalcpu; +} + + +/* return the current PC or ~0 if no CPU is active */ +INLINE offs_t safe_activecpu_get_pc(void) +{ + return (cpu_getactivecpu() >= 0) ? activecpu_get_pc() : ~0; +} + + +#endif /* __CPUINTRF_H__ */ diff --git a/TIKI-100_emul-src/messaudio/deprecat.h b/TIKI-100_emul-src/messaudio/deprecat.h new file mode 100644 index 0000000..17a75ce --- /dev/null +++ b/TIKI-100_emul-src/messaudio/deprecat.h @@ -0,0 +1,70 @@ +/*************************************************************************** + + deprecat.h + + Definition of derprecated and obsolte constructs that should not + be used by new code, if at all possible. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __DEPRECAT_H__ +#define __DEPRECAT_H__ + +#include "mamecore.h" + + +/************************************* + * + * Global access to the currently + * executing machine. + * + * Please investigate if it is + * possible to use a passed in + * 'machine' argument. + * + *************************************/ + +extern running_machine *Machine; + + + +/************************************* + * + * Old way of allowing "VBLANK" + * interrupts to fire more than once + * a frame. + * + * These should be replaced with + * scanline based interrupts as + * it makes no sense to have more + * than one VBLANK interrupt + * per frame. + * + *************************************/ + +#define MDRV_CPU_VBLANK_INT_HACK(_func, _rate) \ + TOKEN_UINT32_PACK2(MCONFIG_TOKEN_CPU_VBLANK_INT_HACK, 8, _rate, 24), \ + TOKEN_PTR(interrupt, _func), + + + +/************************************* + * + * Core timing + * + *************************************/ + +/* Returns the number of times the interrupt handler will be called before + the end of the current video frame. This is can be useful to interrupt + handlers to synchronize their operation. If you call this from outside + an interrupt handler, add 1 to the result, i.e. if it returns 0, it means + that the interrupt handler will be called once. */ +int cpu_getiloops(void); + + +#endif /* __DEPRECAT_H__ */ diff --git a/TIKI-100_emul-src/messaudio/devintrf.h b/TIKI-100_emul-src/messaudio/devintrf.h new file mode 100644 index 0000000..bdeb305 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/devintrf.h @@ -0,0 +1,320 @@ +/*************************************************************************** + + devintrf.h + + Device interface functions. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __DEVINTRF_H__ +#define __DEVINTRF_H__ + +#include "mamecore.h" + + +/*************************************************************************** + CONSTANTS +***************************************************************************/ + +/* device classes */ +enum _device_class +{ + DEVICE_CLASS_GENERAL = 0, /* default class for general devices */ + DEVICE_CLASS_PERIPHERAL, /* peripheral devices: PIAs, timers, etc. */ + DEVICE_CLASS_AUDIO, /* audio devices (not sound chips), including speakers */ + DEVICE_CLASS_VIDEO, /* video devices, including screens */ + DEVICE_CLASS_CPU_CHIP, /* CPU chips; only CPU cores should return this class */ + DEVICE_CLASS_SOUND_CHIP, /* sound chips; only sound cores should return this class */ + DEVICE_CLASS_TIMER, /* timer devices */ + DEVICE_CLASS_OTHER /* anything else (the list may expand in the future) */ +}; +typedef enum _device_class device_class; + + +/* useful in device_list functions for scanning through all devices */ +#define DEVICE_TYPE_WILDCARD NULL + + +/* state constants passed to the device_get_info_func */ +enum +{ + /* --- the following bits of info are returned as 64-bit signed integers --- */ + DEVINFO_INT_FIRST = 0x00000, + + DEVINFO_INT_TOKEN_BYTES = DEVINFO_INT_FIRST, /* R/O: bytes to allocate for the token */ + DEVINFO_INT_INLINE_CONFIG_BYTES, /* R/O: bytes to allocate for the inline configuration */ + DEVINFO_INT_CLASS, /* R/O: the device's class */ + + DEVINFO_INT_DEVICE_SPECIFIC = 0x08000, /* R/W: device-specific values start here */ + + DEVINFO_INT_LAST = 0x0ffff, + + /* --- the following bits of info are returned as pointers --- */ + DEVINFO_PTR_FIRST = 0x10000, + + DEVINFO_PTR_DEVICE_SPECIFIC = 0x18000, /* R/W: device-specific values start here */ + + DEVINFO_PTR_LAST = 0x1ffff, + + /* --- the following bits of info are returned as pointers to functions --- */ + DEVINFO_FCT_FIRST = 0x20000, + + DEVINFO_FCT_SET_INFO = DEVINFO_FCT_FIRST, /* R/O: device_set_info_func */ + DEVINFO_FCT_START, /* R/O: device_start_func */ + DEVINFO_FCT_STOP, /* R/O: device_stop_func */ + DEVINFO_FCT_RESET, /* R/O: device_reset_func */ + DEVINFO_FCT_VALIDITY_CHECK, /* R/O: device_validity_check_func */ + + DEVINFO_FCT_DEVICE_SPECIFIC = 0x28000, /* R/W: device-specific values start here */ + + DEVINFO_FCT_LAST = 0x2ffff, + + /* --- the following bits of info are returned as NULL-terminated strings --- */ + DEVINFO_STR_FIRST = 0x30000, + + DEVINFO_STR_NAME = DEVINFO_STR_FIRST, /* R/O: name of the device */ + DEVINFO_STR_FAMILY, /* R/O: family of the device */ + DEVINFO_STR_VERSION, /* R/O: version of the device */ + DEVINFO_STR_SOURCE_FILE, /* R/O: file containing the device implementation */ + DEVINFO_STR_CREDITS, /* R/O: credits for the device implementation */ + + DEVINFO_STR_DEVICE_SPECIFIC = 0x38000, /* R/W: device-specific values start here */ + + DEVINFO_STR_LAST = 0x3ffff +}; + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +#define DEVICE_GET_INFO_NAME(name) device_get_info_##name +#define DEVICE_GET_INFO(name) void DEVICE_GET_INFO_NAME(name)(const device_config *device, UINT32 state, deviceinfo *info) +#define DEVICE_GET_INFO_CALL(name) DEVICE_GET_INFO_NAME(name)(device, state, info) + +#define DEVICE_SET_INFO_NAME(name) device_set_info_##name +#define DEVICE_SET_INFO(name) void DEVICE_SET_INFO_NAME(name)(const device_config *device, UINT32 state, const deviceinfo *info) +#define DEVICE_SET_INFO_CALL(name) DEVICE_SET_INFO_NAME(name)(device, state, info) + +#define DEVICE_START_NAME(name) device_start_##name +#define DEVICE_START(name) void DEVICE_START_NAME(name)(const device_config *device) +#define DEVICE_START_CALL(name) DEVICE_START_NAME(name)(device) + +#define DEVICE_STOP_NAME(name) device_stop_##name +#define DEVICE_STOP(name) void DEVICE_STOP_NAME(name)(const device_config *device) +#define DEVICE_STOP_CALL(name) DEVICE_STOP_NAME(name)(device) + +#define DEVICE_RESET_NAME(name) device_reset_##name +#define DEVICE_RESET(name) void DEVICE_RESET_NAME(name)(const device_config *device) +#define DEVICE_RESET_CALL(name) DEVICE_RESET_NAME(name)(device) + +#define DEVICE_VALIDITY_CHECK_NAME(name) device_validity_check_##name +#define DEVICE_VALIDITY_CHECK(name) int DEVICE_VALIDITY_CHECK_NAME(name)(const game_driver *driver, const device_config *device) +#define DEVICE_VALIDITY_CHECK_CALL(name) DEVICE_VALIDITY_CHECK(name)(driver, device) + + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* forward-declare these types */ +typedef union _deviceinfo deviceinfo; +typedef struct _device_config device_config; + + +/* device interface function types */ +typedef void (*device_get_info_func)(const device_config *device, UINT32 state, deviceinfo *info); +typedef void (*device_set_info_func)(const device_config *device, UINT32 state, const deviceinfo *info); +typedef void (*device_start_func)(const device_config *device); +typedef void (*device_stop_func)(const device_config *device); +typedef void (*device_reset_func)(const device_config *device); +typedef int (*device_validity_check_func)(const game_driver *driver, const device_config *device); + + +/* a device_type is simply a pointer to its get_info function */ +typedef device_get_info_func device_type; + + +/* the actual deviceinfo union */ +union _deviceinfo +{ + INT64 i; /* generic integers */ + void * p; /* generic pointers */ + genf * f; /* generic function pointers */ + const char * s; /* generic strings */ + + device_set_info_func set_info; /* DEVINFO_FCT_SET_INFO */ + device_start_func start; /* DEVINFO_FCT_START */ + device_stop_func stop; /* DEVINFO_FCT_STOP */ + device_reset_func reset; /* DEVINFO_FCT_RESET */ + device_validity_check_func validity_check; /* DEVINFO_FCT_VALIDITY_CHECK */ +}; + + +/* the configuration for a general device */ +struct _device_config +{ + device_config * next; /* next device */ + device_type type; /* device type */ + device_class class; /* device class */ + device_set_info_func set_info; /* quick pointer to set_info callback */ + device_start_func start; /* quick pointer to start callback */ + device_stop_func stop; /* quick pointer to stop callback */ + device_reset_func reset; /* quick pointer to reset callback */ + const void * static_config; /* static device configuration */ + void * inline_config; /* inline device configuration */ + + /* these two fields are only valid if the device is live */ + void * token; /* token if device is live */ + running_machine * machine; /* machine if device is live */ + + char tag[1]; /* tag for this instance */ +}; + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + + +/* ----- device configuration ----- */ + +/* add a new device to the end of a device list */ +device_config *device_list_add(device_config **listheadptr, device_type type, const char *tag); + +/* remove a device from a device list */ +void device_list_remove(device_config **listheadptr, device_type type, const char *tag); + + + +/* ----- type-based device access ----- */ + +/* return the number of items of a given type; DEVICE_TYPE_WILDCARD is allowed */ +int device_list_items(const device_config *listhead, device_type type); + +/* return the first device in the list of a given type; DEVICE_TYPE_WILDCARD is allowed */ +const device_config *device_list_first(const device_config *listhead, device_type type); + +/* return the next device in the list of a given type; DEVICE_TYPE_WILDCARD is allowed */ +const device_config *device_list_next(const device_config *prevdevice, device_type type); + +/* retrieve a device configuration based on a type and tag; DEVICE_TYPE_WILDCARD is allowed */ +const device_config *device_list_find_by_tag(const device_config *listhead, device_type type, const char *tag); + +/* return the index of a device based on its type and tag; DEVICE_TYPE_WILDCARD is allowed */ +int device_list_index(const device_config *listhead, device_type type, const char *tag); + +/* retrieve a device configuration based on a type and index; DEVICE_TYPE_WILDCARD is allowed */ +const device_config *device_list_find_by_index(const device_config *listhead, device_type type, int index); + + + +/* ----- class-based device access ----- */ + +/* return the number of items of a given class */ +int device_list_class_items(const device_config *listhead, device_class class); + +/* return the first device in the list of a given class */ +const device_config *device_list_class_first(const device_config *listhead, device_class class); + +/* return the next device in the list of a given class */ +const device_config *device_list_class_next(const device_config *prevdevice, device_class class); + +/* retrieve a device configuration based on a class and tag */ +const device_config *device_list_class_find_by_tag(const device_config *listhead, device_class class, const char *tag); + +/* return the index of a device based on its class and tag */ +int device_list_class_index(const device_config *listhead, device_class class, const char *tag); + +/* retrieve a device configuration based on a class and index */ +const device_config *device_list_class_find_by_index(const device_config *listhead, device_class class, int index); + + + +/* ----- live device management ----- */ + +/* start the configured list of devices for a machine */ +void device_list_start(running_machine *machine); + +/* reset a device based on an allocated device_config */ +void device_reset(const device_config *device); +void devtag_reset(running_machine *machine, device_type type, const char *tag); + + + +/* ----- device information getters ----- */ + +/* return the token associated with an allocated device */ +void *devtag_get_token(running_machine *machine, device_type type, const char *tag); + +/* return a pointer to the static configuration for a device based on type and tag */ +const void *devtag_get_static_config(running_machine *machine, device_type type, const char *tag); + +/* return a pointer to the inline configuration for a device based on type and tag */ +const void *devtag_get_inline_config(running_machine *machine, device_type type, const char *tag); + +/* return an integer state value from an allocated device */ +INT64 device_get_info_int(const device_config *device, UINT32 state); +INT64 devtag_get_info_int(running_machine *machine, device_type type, const char *tag, UINT32 state); + +/* return a pointer state value from an allocated device */ +void *device_get_info_ptr(const device_config *device, UINT32 state); +void *devtag_get_info_ptr(running_machine *machine, device_type type, const char *tag, UINT32 state); + +/* return a function pointer state value from an allocated device */ +genf *device_get_info_fct(const device_config *device, UINT32 state); +genf *devtag_get_info_fct(running_machine *machine, device_type type, const char *tag, UINT32 state); + +/* return a string value from an allocated device */ +const char *device_get_info_string(const device_config *device, UINT32 state); +const char *devtag_get_info_string(running_machine *machine, device_type type, const char *tag, UINT32 state); + + + +/* ----- device type information getters ----- */ + +/* return an integer value from a device type (does not need to be allocated) */ +INT64 devtype_get_info_int(device_type type, UINT32 state); + +/* return a string value from a device type (does not need to be allocated) */ +const char *devtype_get_info_string(device_type type, UINT32 state); + + + +/* ----- device information setters ----- */ + +/* set an integer state value for an allocated device */ +void device_set_info_int(const device_config *device, UINT32 state, INT64 data); +void devtag_set_info_int(running_machine *machine, device_type type, const char *tag, UINT32 state, INT64 data); + +/* set a pointer state value for an allocated device */ +void device_set_info_ptr(const device_config *device, UINT32 state, void *data); +void devtag_set_info_ptr(running_machine *machine, device_type type, const char *tag, UINT32 state, void *data); + +/* set a function pointer state value for an allocated device */ +void device_set_info_fct(const device_config *device, UINT32 state, genf *data); +void devtag_set_info_fct(running_machine *machine, device_type type, const char *tag, UINT32 state, genf *data); + + + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +/* return common strings based on device types */ +INLINE const char *devtype_name(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_NAME); } +INLINE const char *devtype_family(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_FAMILY); } +INLINE const char *devtype_version(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_VERSION); } +INLINE const char *devtype_source_file(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_SOURCE_FILE); } +INLINE const char *devtype_credits(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_CREDITS); } + + +#endif /* __DEVINTRF_H__ */ diff --git a/TIKI-100_emul-src/messaudio/mamecore.h b/TIKI-100_emul-src/messaudio/mamecore.h new file mode 100644 index 0000000..5d3953e --- /dev/null +++ b/TIKI-100_emul-src/messaudio/mamecore.h @@ -0,0 +1,348 @@ +/*************************************************************************** + + mamecore.h + + General core utilities and macros used throughout MAME. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __MAMECORE_H__ +#define __MAMECORE_H__ + +#include +#include +#include +#include "osdcomm.h" +#include "bitmap.h" +#include "coreutil.h" +#include "corestr.h" + + +/*************************************************************************** + COMPILER-SPECIFIC NASTINESS +***************************************************************************/ + +/* Suppress warnings about redefining the macro 'PPC' on LinuxPPC. */ +#ifdef PPC +#undef PPC +#endif + +/* Suppress warnings about redefining the macro 'ARM' on ARM. */ +#ifdef ARM +#undef ARM +#endif + + + +/*************************************************************************** + COMMON TYPES +***************************************************************************/ + +/* genf is a type that can be used for function pointer casting in a way + that doesn't confuse some compilers */ +typedef void genf(void); + + +/* FPTR is a type that can be used to cast a pointer to a scalar */ +/* 64-bit platforms should define PTR64 */ +#ifdef PTR64 +typedef UINT64 FPTR; +#else +typedef UINT32 FPTR; +#endif + + +/* These are forward struct declarations that are used to break + circular dependencies in the code */ +typedef struct _running_machine running_machine; +typedef struct _mame_display mame_display; +typedef struct _game_driver game_driver; +typedef struct _machine_config machine_config; +typedef struct _rom_load_data rom_load_data; +typedef struct _osd_create_params osd_create_params; +typedef struct _gfx_element gfx_element; +typedef struct _mame_file mame_file; + + +/* pen_t is used to represent pixel values in bitmaps */ +typedef UINT32 pen_t; + +/* stream_sample_t is used to represent a single sample in a sound stream */ +typedef INT32 stream_sample_t; + + + +/*************************************************************************** + * Union of UINT8, UINT16 and UINT32 in native endianess of the target + * This is used to access bytes and words in a machine independent manner. + * The upper bytes h2 and h3 normally contain zero (16 bit CPU cores) + * thus PAIR.d can be used to pass arguments to the memory system + * which expects 'int' really. +***************************************************************************/ +typedef union +{ +#ifdef LSB_FIRST + struct { UINT8 l,h,h2,h3; } b; + struct { UINT16 l,h; } w; + struct { INT8 l,h,h2,h3; } sb; + struct { INT16 l,h; } sw; +#else + struct { UINT8 h3,h2,h,l; } b; + struct { INT8 h3,h2,h,l; } sb; + struct { UINT16 h,l; } w; + struct { INT16 h,l; } sw; +#endif + UINT32 d; + INT32 sd; +} PAIR; + + +/*************************************************************************** + * Union of UINT8, UINT16, UINT32, and UINT64 in native endianess of + * the target. This is used to access bytes and words in a machine + * independent manner. +***************************************************************************/ +typedef union +{ +#ifdef LSB_FIRST + struct { UINT8 l,h,h2,h3,h4,h5,h6,h7; } b; + struct { UINT16 l,h,h2,h3; } w; + struct { UINT32 l,h; } d; + struct { INT8 l,h,h2,h3,h4,h5,h6,h7; } sb; + struct { INT16 l,h,h2,h3; } sw; + struct { INT32 l,h; } sd; +#else + struct { UINT8 h7,h6,h5,h4,h3,h2,h,l; } b; + struct { UINT16 h3,h2,h,l; } w; + struct { UINT32 h,l; } d; + struct { INT8 h7,h6,h5,h4,h3,h2,h,l; } sb; + struct { INT16 h3,h2,h,l; } sw; + struct { INT32 h,l; } sd; +#endif + UINT64 q; + INT64 sq; +} PAIR64; + + + +/*************************************************************************** + COMMON CONSTANTS +***************************************************************************/ + +/* this is not part of the C/C++ standards and is not present on */ +/* strict ANSI compilers or when compiling under GCC with -ansi */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + + +/* orientation of bitmaps */ +#define ORIENTATION_FLIP_X 0x0001 /* mirror everything in the X direction */ +#define ORIENTATION_FLIP_Y 0x0002 /* mirror everything in the Y direction */ +#define ORIENTATION_SWAP_XY 0x0004 /* mirror along the top-left/bottom-right diagonal */ + +#define ROT0 0 +#define ROT90 (ORIENTATION_SWAP_XY | ORIENTATION_FLIP_X) /* rotate clockwise 90 degrees */ +#define ROT180 (ORIENTATION_FLIP_X | ORIENTATION_FLIP_Y) /* rotate 180 degrees */ +#define ROT270 (ORIENTATION_SWAP_XY | ORIENTATION_FLIP_Y) /* rotate counter-clockwise 90 degrees */ + + +/* giant global string buffer */ +#define GIANT_STRING_BUFFER_SIZE 65536 + + + +/*************************************************************************** + COMMON MACROS +***************************************************************************/ + +/* Standard MAME assertion macros */ +#undef assert +#undef assert_always + +#ifdef MAME_DEBUG +#define assert(x) do { if (!(x)) fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) +#define assert_always(x, msg) do { if (!(x)) fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0) +#else +#define assert(x) +#define assert_always(x, msg) do { if (!(x)) fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0) +#endif + + +/* map mame_* helpers to core_* helpers */ +#define mame_stricmp core_stricmp +#define mame_strnicmp core_strnicmp +#define mame_strdup core_strdup +#define mame_strwildcmp core_strwildcmp + + +/* prevent the use of rand() -- use mame_rand() instead */ +#define rand + + +/* macros to convert radians to degrees and degrees to radians */ +#define RADIAN_TO_DEGREE(x) ((180.0 / M_PI) * (x)) +#define DEGREE_TO_RADIAN(x) ((M_PI / 180.0) * (x)) + + + +/* Useful macros to deal with bit shuffling encryptions */ +#define BIT(x,n) (((x)>>(n))&1) + +#define BITSWAP8(val,B7,B6,B5,B4,B3,B2,B1,B0) \ + ((BIT(val,B7) << 7) | \ + (BIT(val,B6) << 6) | \ + (BIT(val,B5) << 5) | \ + (BIT(val,B4) << 4) | \ + (BIT(val,B3) << 3) | \ + (BIT(val,B2) << 2) | \ + (BIT(val,B1) << 1) | \ + (BIT(val,B0) << 0)) + +#define BITSWAP16(val,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ + ((BIT(val,B15) << 15) | \ + (BIT(val,B14) << 14) | \ + (BIT(val,B13) << 13) | \ + (BIT(val,B12) << 12) | \ + (BIT(val,B11) << 11) | \ + (BIT(val,B10) << 10) | \ + (BIT(val, B9) << 9) | \ + (BIT(val, B8) << 8) | \ + (BIT(val, B7) << 7) | \ + (BIT(val, B6) << 6) | \ + (BIT(val, B5) << 5) | \ + (BIT(val, B4) << 4) | \ + (BIT(val, B3) << 3) | \ + (BIT(val, B2) << 2) | \ + (BIT(val, B1) << 1) | \ + (BIT(val, B0) << 0)) + +#define BITSWAP24(val,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ + ((BIT(val,B23) << 23) | \ + (BIT(val,B22) << 22) | \ + (BIT(val,B21) << 21) | \ + (BIT(val,B20) << 20) | \ + (BIT(val,B19) << 19) | \ + (BIT(val,B18) << 18) | \ + (BIT(val,B17) << 17) | \ + (BIT(val,B16) << 16) | \ + (BIT(val,B15) << 15) | \ + (BIT(val,B14) << 14) | \ + (BIT(val,B13) << 13) | \ + (BIT(val,B12) << 12) | \ + (BIT(val,B11) << 11) | \ + (BIT(val,B10) << 10) | \ + (BIT(val, B9) << 9) | \ + (BIT(val, B8) << 8) | \ + (BIT(val, B7) << 7) | \ + (BIT(val, B6) << 6) | \ + (BIT(val, B5) << 5) | \ + (BIT(val, B4) << 4) | \ + (BIT(val, B3) << 3) | \ + (BIT(val, B2) << 2) | \ + (BIT(val, B1) << 1) | \ + (BIT(val, B0) << 0)) + +#define BITSWAP32(val,B31,B30,B29,B28,B27,B26,B25,B24,B23,B22,B21,B20,B19,B18,B17,B16,B15,B14,B13,B12,B11,B10,B9,B8,B7,B6,B5,B4,B3,B2,B1,B0) \ + ((BIT(val,B31) << 31) | \ + (BIT(val,B30) << 30) | \ + (BIT(val,B29) << 29) | \ + (BIT(val,B28) << 28) | \ + (BIT(val,B27) << 27) | \ + (BIT(val,B26) << 26) | \ + (BIT(val,B25) << 25) | \ + (BIT(val,B24) << 24) | \ + (BIT(val,B23) << 23) | \ + (BIT(val,B22) << 22) | \ + (BIT(val,B21) << 21) | \ + (BIT(val,B20) << 20) | \ + (BIT(val,B19) << 19) | \ + (BIT(val,B18) << 18) | \ + (BIT(val,B17) << 17) | \ + (BIT(val,B16) << 16) | \ + (BIT(val,B15) << 15) | \ + (BIT(val,B14) << 14) | \ + (BIT(val,B13) << 13) | \ + (BIT(val,B12) << 12) | \ + (BIT(val,B11) << 11) | \ + (BIT(val,B10) << 10) | \ + (BIT(val, B9) << 9) | \ + (BIT(val, B8) << 8) | \ + (BIT(val, B7) << 7) | \ + (BIT(val, B6) << 6) | \ + (BIT(val, B5) << 5) | \ + (BIT(val, B4) << 4) | \ + (BIT(val, B3) << 3) | \ + (BIT(val, B2) << 2) | \ + (BIT(val, B1) << 1) | \ + (BIT(val, B0) << 0)) + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + +/* Used by assert(), so definition here instead of mame.h */ +DECL_NORETURN void CLIB_DECL fatalerror(const char *text, ...) ATTR_PRINTF(1,2) ATTR_NORETURN; +DECL_NORETURN void CLIB_DECL fatalerror_exitcode(int exitcode, const char *text, ...) ATTR_PRINTF(2,3) ATTR_NORETURN; + + + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +/* convert a series of 32 bits into a float */ +INLINE float u2f(UINT32 v) +{ + union { + float ff; + UINT32 vv; + } u; + u.vv = v; + return u.ff; +} + + +/* convert a float into a series of 32 bits */ +INLINE UINT32 f2u(float f) +{ + union { + float ff; + UINT32 vv; + } u; + u.ff = f; + return u.vv; +} + + +/* convert a series of 64 bits into a double */ +INLINE double u2d(UINT64 v) +{ + union { + double dd; + UINT64 vv; + } u; + u.vv = v; + return u.dd; +} + + +/* convert a double into a series of 64 bits */ +INLINE UINT64 d2u(double d) +{ + union { + double dd; + UINT64 vv; + } u; + u.dd = d; + return u.vv; +} + +#endif /* __MAMECORE_H__ */ diff --git a/TIKI-100_emul-src/messaudio/memory.h b/TIKI-100_emul-src/messaudio/memory.h new file mode 100644 index 0000000..a72b487 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/memory.h @@ -0,0 +1,1335 @@ +/*************************************************************************** + + memory.h + + Functions which handle the CPU memory accesses. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __MEMORY_H__ +#define __MEMORY_H__ + + +#include "mamecore.h" +#include "devintrf.h" +#include "tokenize.h" +#include "osdcomm.h" + +/*************************************************************************** + CONSTANTS +***************************************************************************/ + +/* address spaces */ +enum +{ + ADDRESS_SPACE_PROGRAM = 0, /* program address space */ + ADDRESS_SPACE_DATA, /* data address space */ + ADDRESS_SPACE_IO, /* I/O address space */ + ADDRESS_SPACES /* maximum number of address spaces */ +}; + + +/* static data access handler constants */ +enum +{ + STATIC_INVALID = 0, /* invalid - should never be used */ + STATIC_BANK1 = 1, /* first memory bank */ + /* entries 1-32 are for fixed banks 1-32 specified by the driver */ + /* entries 33-66 are for dynamically allocated internal banks */ + STATIC_BANKMAX = 66, /* last memory bank */ + STATIC_RAM, /* RAM - reads/writes map to dynamic banks */ + STATIC_ROM, /* ROM - reads = RAM; writes = UNMAP */ + STATIC_NOP, /* NOP - reads = unmapped value; writes = no-op */ + STATIC_UNMAP, /* unmapped - same as NOP except we log errors */ + STATIC_WATCHPOINT, /* watchpoint - used internally */ + STATIC_COUNT /* total number of static handlers */ +}; + + +/* address map tokens */ +enum +{ + ADDRMAP_TOKEN_INVALID, + + ADDRMAP_TOKEN_START, + ADDRMAP_TOKEN_END, + ADDRMAP_TOKEN_INCLUDE, + + ADDRMAP_TOKEN_GLOBAL_MASK, + ADDRMAP_TOKEN_UNMAP_VALUE, + + ADDRMAP_TOKEN_RANGE, + ADDRMAP_TOKEN_MASK, + ADDRMAP_TOKEN_MIRROR, + ADDRMAP_TOKEN_READ, + ADDRMAP_TOKEN_WRITE, + ADDRMAP_TOKEN_DEVICE_READ, + ADDRMAP_TOKEN_DEVICE_WRITE, + ADDRMAP_TOKEN_READ_PORT, + ADDRMAP_TOKEN_REGION, + ADDRMAP_TOKEN_SHARE, + ADDRMAP_TOKEN_BASEPTR, + ADDRMAP_TOKEN_BASE_MEMBER, + ADDRMAP_TOKEN_SIZEPTR, + ADDRMAP_TOKEN_SIZE_MEMBER +}; + + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* handler_data is an opaque type used to hold information about a particular handler */ +typedef struct _handler_data handler_data; + + +/* offsets and addresses are 32-bit (for now...) */ +typedef UINT32 offs_t; + + +/* opbase_data contains state data for opcode handling */ +typedef struct _opbase_data opbase_data; +struct _opbase_data +{ + UINT8 * rom; /* opcode ROM base pointer */ + UINT8 * ram; /* opcode RAM base pointer */ + offs_t mask; /* opcode ROM address mask */ + offs_t mem_min; /* opcode ROM/RAM min */ + offs_t mem_max; /* opcode ROM/RAM max */ + UINT8 entry; /* opcode readmem entry */ +}; + + +/* opcode base adjustment handler */ +typedef offs_t (*opbase_handler_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t address, ATTR_UNUSED opbase_data *opbase); + + +/* machine read/write handlers */ +typedef UINT8 (*read8_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset); +typedef void (*write8_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data); +typedef UINT16 (*read16_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 mem_mask); +typedef void (*write16_machine_func)(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask); +typedef UINT32 (*read32_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 mem_mask); +typedef void (*write32_machine_func)(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 data, ATTR_UNUSED UINT32 mem_mask); +typedef UINT64 (*read64_machine_func) (ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 mem_mask); +typedef void (*write64_machine_func)(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 data, ATTR_UNUSED UINT64 mem_mask); + + +/* device read/write handlers */ +typedef UINT8 (*read8_device_func) (ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset); +typedef void (*write8_device_func) (ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data); +typedef UINT16 (*read16_device_func) (ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 mem_mask); +typedef void (*write16_device_func)(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask); +typedef UINT32 (*read32_device_func) (ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 mem_mask); +typedef void (*write32_device_func)(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 data, ATTR_UNUSED UINT32 mem_mask); +typedef UINT64 (*read64_device_func) (ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 mem_mask); +typedef void (*write64_device_func)(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 data, ATTR_UNUSED UINT64 mem_mask); + + +/* data_accessors is a struct with accessors of all flavors */ +typedef struct _data_accessors data_accessors; +struct _data_accessors +{ + void (*change_pc)(offs_t byteaddress); + + UINT8 (*read_byte)(offs_t byteaddress); + UINT16 (*read_word)(offs_t byteaddress); + UINT16 (*read_word_masked)(offs_t byteaddress, UINT16 mask); + 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_word_masked)(offs_t byteaddress, UINT16 data, UINT16 mask); + 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); +}; + + +/* read_handler is a union of all the different read handler types */ +typedef union _read_handler read_handler; +union _read_handler +{ + genf * generic; /* generic function pointer */ + read8_machine_func mhandler8; /* 8-bit machine read handler */ + read16_machine_func mhandler16; /* 16-bit machine read handler */ + read32_machine_func mhandler32; /* 32-bit machine read handler */ + read64_machine_func mhandler64; /* 64-bit machine read handler */ + read8_device_func dhandler8; /* 8-bit device read handler */ + read16_device_func dhandler16; /* 16-bit device read handler */ + read32_device_func dhandler32; /* 32-bit device read handler */ + read64_device_func dhandler64; /* 64-bit device read handler */ +}; + + +/* write_handler is a union of all the different write handler types */ +typedef union _write_handler write_handler; +union _write_handler +{ + genf * generic; /* generic function pointer */ + write8_machine_func mhandler8; /* 8-bit machine write handler */ + write16_machine_func mhandler16; /* 16-bit machine write handler */ + write32_machine_func mhandler32; /* 32-bit machine write handler */ + write64_machine_func mhandler64; /* 64-bit machine write handler */ + write8_device_func dhandler8; /* 8-bit device write handler */ + write16_device_func dhandler16; /* 16-bit device write handler */ + write32_device_func dhandler32; /* 32-bit device write handler */ + write64_device_func dhandler64; /* 64-bit device write handler */ +}; + + +/* memory_handler is a union of all read and write handler types */ +typedef union _memory_handler memory_handler; +union _memory_handler +{ + genf * generic; /* generic function pointer */ + read_handler read; /* read handler union */ + write_handler write; /* write handler union */ +}; + + +/* address_map_entry is a linked list element describing one address range in a map */ +typedef struct _address_map_entry address_map_entry; +struct _address_map_entry +{ + address_map_entry * next; /* pointer to the next entry */ + + offs_t addrstart; /* start address */ + offs_t addrend; /* end address */ + offs_t addrmirror; /* mirror bits */ + offs_t addrmask; /* mask bits */ + read_handler read; /* read handler callback */ + UINT8 read_bits; /* bits for the read handler callback (0=default, 1=8, 2=16, 3=32) */ + UINT8 read_mask; /* mask bits indicating which subunits to process */ + const char * read_name; /* read handler callback name */ + device_type read_devtype; /* read device type for device references */ + const char * read_devtag; /* read tag for the relevant device */ + const char * read_porttag; /* tag for input port reading */ + write_handler write; /* write handler callback */ + UINT8 write_bits; /* bits for the write handler callback (0=default, 1=8, 2=16, 3=32) */ + UINT8 write_mask; /* mask bits indicating which subunits to process */ + const char * write_name; /* write handler callback name */ + device_type write_devtype; /* read device type for device references */ + const char * write_devtag; /* read tag for the relevant device */ + UINT32 share; /* index of a shared memory block */ + void ** baseptr; /* receives pointer to memory (optional) */ + size_t * sizeptr; /* receives size of area in bytes (optional) */ + UINT32 baseptroffs_plus1; /* offset of base pointer within driver_data, plus 1 */ + UINT32 sizeptroffs_plus1; /* offset of size pointer within driver_data, plus 1 */ + UINT32 region; /* region containing the memory backing this entry */ + offs_t region_offs; /* offset within the region */ + + void * memory; /* pointer to memory backing this entry */ + 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 */ +}; + + +/* address_map holds global map parameters plus the head of the list of entries */ +typedef struct _address_map address_map; +struct _address_map +{ + UINT8 spacenum; /* space number of the map */ + UINT8 databits; /* data bits represented by the map */ + UINT8 unmapval; /* unmapped memory value */ + offs_t globalmask; /* global mask */ + address_map_entry * entrylist; /* list of entries */ +}; + + +/* address_space holds live information about an address space */ +typedef struct _address_space address_space; +struct _address_space +{ + offs_t bytemask; /* byte-adjusted address mask */ + UINT8 * readlookup; /* read table lookup */ + UINT8 * writelookup; /* write table lookup */ + handler_data * readhandlers; /* read handlers */ + handler_data * writehandlers; /* write handlers */ + const data_accessors * accessors; /* pointers to the data access handlers */ +}; + + +/* addrmap_token is a union of all types for a generic address map */ +typedef union _addrmap_token addrmap_token; +union _addrmap_token +{ + TOKEN_COMMON_FIELDS + const addrmap_token * tokenptr; + read_handler read; /* generic read handlers */ + write_handler write; /* generic write handlers */ + device_type devtype; /* device type */ + UINT8 ** memptr; /* memory pointer */ + size_t * sizeptr; /* size pointer */ +}; + + +/* addrmap8_token is a union of all types for an 8-bit address map */ +typedef union _addrmap8_token addrmap8_token; +union _addrmap8_token +{ + TOKEN_COMMON_FIELDS + const addrmap_token * tokenptr; + read8_machine_func mread; /* pointer to native machine read handler */ + write8_machine_func mwrite; /* pointer to native machine write handler */ + read8_device_func dread; /* pointer to native device read handler */ + write8_device_func dwrite; /* pointer to native device write handler */ + read_handler read; /* generic read handlers */ + write_handler write; /* generic write handlers */ + device_type devtype; /* device type */ + UINT8 ** memptr; /* memory pointer */ + size_t * sizeptr; /* size pointer */ +}; + + +/* addrmap16_token is a union of all types for a 16-bit address map */ +typedef union _addrmap16_token addrmap16_token; +union _addrmap16_token +{ + TOKEN_COMMON_FIELDS + const addrmap_token * tokenptr; + read16_machine_func mread; /* pointer to native read handler */ + write16_machine_func mwrite; /* pointer to native write handler */ + read16_device_func dread; /* pointer to native device read handler */ + write16_device_func dwrite; /* pointer to native device write handler */ + read8_machine_func mread8; /* pointer to 8-bit machine read handler */ + write8_machine_func mwrite8; /* pointer to 8-bit machine write handler */ + read8_device_func dread8; /* pointer to 8-bit device read handler */ + write8_device_func dwrite8; /* pointer to 8-bit device write handler */ + read_handler read; /* generic read handlers */ + write_handler write; /* generic write handlers */ + device_type devtype; /* device type */ + UINT16 ** memptr; /* memory pointer */ + size_t * sizeptr; /* size pointer */ +}; + + +/* addrmap32_token is a union of all types for a 32-bit address map */ +typedef union _addrmap32_token addrmap32_token; +union _addrmap32_token +{ + TOKEN_COMMON_FIELDS + const addrmap_token * tokenptr; + read32_machine_func mread; /* pointer to native read handler */ + write32_machine_func mwrite; /* pointer to native write handler */ + read32_device_func dread; /* pointer to native device read handler */ + write32_device_func dwrite; /* pointer to native device write handler */ + read8_machine_func mread8; /* pointer to 8-bit machine read handler */ + write8_machine_func mwrite8; /* pointer to 8-bit machine write handler */ + read8_device_func dread8; /* pointer to 8-bit device read handler */ + write8_device_func dwrite8; /* pointer to 8-bit device write handler */ + read16_machine_func mread16; /* pointer to 16-bit machine read handler */ + write16_machine_func mwrite16; /* pointer to 16-bit machine write handler */ + read16_device_func dread16; /* pointer to 16-bit device read handler */ + write16_device_func dwrite16; /* pointer to 16-bit device write handler */ + read_handler read; /* generic read handlers */ + write_handler write; /* generic write handlers */ + device_type devtype; /* device type */ + UINT32 ** memptr; /* memory pointer */ + size_t * sizeptr; /* size pointer */ +}; + + +/* addrmap64_token is a union of all types for a 64-bit address map */ +typedef union _addrmap64_token addrmap64_token; +union _addrmap64_token +{ + TOKEN_COMMON_FIELDS + const addrmap_token * tokenptr; + read64_machine_func mread; /* pointer to native read handler */ + write64_machine_func mwrite; /* pointer to native write handler */ + read64_device_func dread; /* pointer to native device read handler */ + write64_device_func dwrite; /* pointer to native device write handler */ + read8_machine_func mread8; /* pointer to 8-bit machine read handler */ + write8_machine_func mwrite8; /* pointer to 8-bit machine write handler */ + read8_device_func dread8; /* pointer to 8-bit device read handler */ + write8_device_func dwrite8; /* pointer to 8-bit device write handler */ + read16_machine_func mread16; /* pointer to 16-bit machine read handler */ + write16_machine_func mwrite16; /* pointer to 16-bit machine write handler */ + read16_device_func dread16; /* pointer to 16-bit device read handler */ + write16_device_func dwrite16; /* pointer to 16-bit device write handler */ + read32_machine_func mread32; /* pointer to 32-bit machine read handler */ + write32_machine_func mwrite32; /* pointer to 32-bit machine write handler */ + read32_device_func dread32; /* pointer to 32-bit device read handler */ + write32_device_func dwrite32; /* pointer to 32-bit device write handler */ + read_handler read; /* generic read handlers */ + write_handler write; /* generic write handlers */ + device_type devtype; /* device type */ + UINT64 ** memptr; /* memory pointer */ + size_t * sizeptr; /* size pointer */ +}; + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +/* opcode base adjustment handler function macro */ +#define OPBASE_HANDLER(name) offs_t name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t address, opbase_data *opbase) + + +/* machine read/write handler function macros */ +#define READ8_HANDLER(name) UINT8 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset) +#define WRITE8_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data) +#define READ16_HANDLER(name) UINT16 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 mem_mask) +#define WRITE16_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) +#define READ32_HANDLER(name) UINT32 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 mem_mask) +#define WRITE32_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 data, ATTR_UNUSED UINT32 mem_mask) +#define READ64_HANDLER(name) UINT64 name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 mem_mask) +#define WRITE64_HANDLER(name) void name(ATTR_UNUSED running_machine *machine, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 data, ATTR_UNUSED UINT64 mem_mask) + + +/* device read/write handler function macros */ +#define READ8_DEVICE_HANDLER(name) UINT8 name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset) +#define WRITE8_DEVICE_HANDLER(name) void name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT8 data) +#define READ16_DEVICE_HANDLER(name) UINT16 name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 mem_mask) +#define WRITE16_DEVICE_HANDLER(name) void name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask) +#define READ32_DEVICE_HANDLER(name) UINT32 name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 mem_mask) +#define WRITE32_DEVICE_HANDLER(name) void name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT32 data, ATTR_UNUSED UINT32 mem_mask) +#define READ64_DEVICE_HANDLER(name) UINT64 name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 mem_mask) +#define WRITE64_DEVICE_HANDLER(name) void name(ATTR_UNUSED const device_config *device, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT64 data, ATTR_UNUSED UINT64 mem_mask) + + +/* static memory handler (SMH) macros that can be used in place of read/write handlers */ +#define SMH_RAM ((void *)STATIC_RAM) +#define SMH_ROM ((void *)STATIC_ROM) +#define SMH_NOP ((void *)STATIC_NOP) +#define SMH_UNMAP ((void *)STATIC_UNMAP) +#define SMH_BANK(n) ((void *)(STATIC_BANK1 + (n) - 1)) +#define SMH_BANK1 SMH_BANK(1) +#define SMH_BANK2 SMH_BANK(2) +#define SMH_BANK3 SMH_BANK(3) +#define SMH_BANK4 SMH_BANK(4) +#define SMH_BANK5 SMH_BANK(5) +#define SMH_BANK6 SMH_BANK(6) +#define SMH_BANK7 SMH_BANK(7) +#define SMH_BANK8 SMH_BANK(8) +#define SMH_BANK9 SMH_BANK(9) +#define SMH_BANK10 SMH_BANK(10) +#define SMH_BANK11 SMH_BANK(11) +#define SMH_BANK12 SMH_BANK(12) +#define SMH_BANK13 SMH_BANK(13) +#define SMH_BANK14 SMH_BANK(14) +#define SMH_BANK15 SMH_BANK(15) +#define SMH_BANK16 SMH_BANK(16) +#define SMH_BANK17 SMH_BANK(17) +#define SMH_BANK18 SMH_BANK(18) +#define SMH_BANK19 SMH_BANK(19) +#define SMH_BANK20 SMH_BANK(20) +#define SMH_BANK21 SMH_BANK(21) +#define SMH_BANK22 SMH_BANK(22) +#define SMH_BANK23 SMH_BANK(23) +#define SMH_BANK24 SMH_BANK(24) +#define SMH_BANK25 SMH_BANK(25) +#define SMH_BANK26 SMH_BANK(26) +#define SMH_BANK27 SMH_BANK(27) +#define SMH_BANK28 SMH_BANK(28) +#define SMH_BANK29 SMH_BANK(29) +#define SMH_BANK30 SMH_BANK(30) +#define SMH_BANK31 SMH_BANK(31) +#define SMH_BANK32 SMH_BANK(32) + + +/* helper macro for merging data with the memory mask */ +#define COMBINE_DATA(varptr) (*(varptr) = (*(varptr) & ~mem_mask) | (data & mem_mask)) + +#define ACCESSING_BITS_0_7 ((mem_mask & 0x000000ff) != 0) +#define ACCESSING_BITS_8_15 ((mem_mask & 0x0000ff00) != 0) +#define ACCESSING_BITS_16_23 ((mem_mask & 0x00ff0000) != 0) +#define ACCESSING_BITS_24_31 ((mem_mask & 0xff000000) != 0) +#define ACCESSING_BITS_32_39 ((mem_mask & U64(0x000000ff00000000)) != 0) +#define ACCESSING_BITS_40_47 ((mem_mask & U64(0x0000ff0000000000)) != 0) +#define ACCESSING_BITS_48_55 ((mem_mask & U64(0x00ff000000000000)) != 0) +#define ACCESSING_BITS_56_63 ((mem_mask & U64(0xff00000000000000)) != 0) + +#define ACCESSING_BITS_0_15 ((mem_mask & 0x0000ffff) != 0) +#define ACCESSING_BITS_16_31 ((mem_mask & 0xffff0000) != 0) +#define ACCESSING_BITS_32_47 ((mem_mask & U64(0x0000ffff00000000)) != 0) +#define ACCESSING_BITS_48_63 ((mem_mask & U64(0xffff000000000000)) != 0) + +#define ACCESSING_BITS_0_31 ((mem_mask & 0xffffffff) != 0) +#define ACCESSING_BITS_32_63 ((mem_mask & U64(0xffffffff00000000)) != 0) + + +/* bank switching for CPU cores */ +#define change_pc(byteaddress) memory_set_opbase(byteaddress) + + +/* opcode range safety check */ +#define address_is_unsafe(A) ((UNEXPECTED((A) < opbase.mem_min) || UNEXPECTED((A) > opbase.mem_max))) + + +/* unsafe opcode and opcode argument reading */ +#define cpu_opptr_unsafe(A) ((void *)&opbase.rom[(A) & opbase.mask]) +#define cpu_readop_unsafe(A) (opbase.rom[(A) & opbase.mask]) +#define cpu_readop16_unsafe(A) (*(UINT16 *)&opbase.rom[(A) & opbase.mask]) +#define cpu_readop32_unsafe(A) (*(UINT32 *)&opbase.rom[(A) & opbase.mask]) +#define cpu_readop64_unsafe(A) (*(UINT64 *)&opbase.rom[(A) & opbase.mask]) +#define cpu_readop_arg_unsafe(A) (opbase.ram[(A) & opbase.mask]) +#define cpu_readop_arg16_unsafe(A) (*(UINT16 *)&opbase.ram[(A) & opbase.mask]) +#define cpu_readop_arg32_unsafe(A) (*(UINT32 *)&opbase.ram[(A) & opbase.mask]) +#define cpu_readop_arg64_unsafe(A) (*(UINT64 *)&opbase.ram[(A) & opbase.mask]) + + +/* wrappers for dynamic read handler installation */ +#define memory_install_read_handler(machine, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_handler(machine, cpu, space, start, end, mask, mirror, rhandler, (FPTR)NULL, #rhandler, NULL) +#define memory_install_read8_handler(machine, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_handler8(machine, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read16_handler(machine, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_handler16(machine, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read32_handler(machine, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_handler32(machine, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read64_handler(machine, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_handler64(machine, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) + +#define memory_install_read_device_handler(device, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read8_device_handler(device, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_device_handler8(device, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read16_device_handler(device, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_device_handler16(device, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read32_device_handler(device, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_device_handler32(device, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) +#define memory_install_read64_device_handler(device, cpu, space, start, end, mask, mirror, rhandler) \ + _memory_install_device_handler64(device, cpu, space, start, end, mask, mirror, rhandler, NULL, #rhandler, NULL) + + +/* wrappers for dynamic write handler installation */ +#define memory_install_write_handler(machine, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_handler(machine, cpu, space, start, end, mask, mirror, (FPTR)NULL, whandler, NULL, #whandler) +#define memory_install_write8_handler(machine, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_handler8(machine, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write16_handler(machine, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_handler16(machine, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write32_handler(machine, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_handler32(machine, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write64_handler(machine, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_handler64(machine, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) + +#define memory_install_write_device_handler(device, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_device_handler(device, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write8_device_handler(device, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_device_handler8(device, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write16_device_handler(device, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_device_handler16(device, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write32_device_handler(device, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_device_handler32(device, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) +#define memory_install_write64_device_handler(device, cpu, space, start, end, mask, mirror, whandler) \ + _memory_install_device_handler64(device, cpu, space, start, end, mask, mirror, NULL, whandler, NULL, #whandler) + + +/* wrappers for dynamic read/write handler installation */ +#define memory_install_readwrite_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite8_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_handler8(machine, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite16_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_handler16(machine, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite32_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_handler32(machine, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite64_handler(machine, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_handler64(machine, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) + +#define memory_install_readwrite_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite8_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_device_handler8(device, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite16_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_device_handler16(device, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite32_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_device_handler32(device, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) +#define memory_install_readwrite64_device_handler(device, cpu, space, start, end, mask, mirror, rhandler, whandler) \ + _memory_install_device_handler64(device, cpu, space, start, end, mask, mirror, rhandler, whandler, #rhandler, #whandler) + + +/* macros for accessing bytes and words within larger chunks */ +#ifdef LSB_FIRST + +#define BYTE_XOR_BE(a) ((a) ^ 1) /* read/write a byte to a 16-bit space */ +#define BYTE_XOR_LE(a) (a) +#define BYTE4_XOR_BE(a) ((a) ^ 3) /* read/write a byte to a 32-bit space */ +#define BYTE4_XOR_LE(a) (a) +#define WORD_XOR_BE(a) ((a) ^ 2) /* read/write a word to a 32-bit space */ +#define WORD_XOR_LE(a) (a) +#define BYTE8_XOR_BE(a) ((a) ^ 7) /* read/write a byte to a 64-bit space */ +#define BYTE8_XOR_LE(a) (a) +#define WORD2_XOR_BE(a) ((a) ^ 6) /* read/write a word to a 64-bit space */ +#define WORD2_XOR_LE(a) (a) +#define DWORD_XOR_BE(a) ((a) ^ 4) /* read/write a dword to a 64-bit space */ +#define DWORD_XOR_LE(a) (a) + +#else + +#define BYTE_XOR_BE(a) (a) +#define BYTE_XOR_LE(a) ((a) ^ 1) /* read/write a byte to a 16-bit space */ +#define BYTE4_XOR_BE(a) (a) +#define BYTE4_XOR_LE(a) ((a) ^ 3) /* read/write a byte to a 32-bit space */ +#define WORD_XOR_BE(a) (a) +#define WORD_XOR_LE(a) ((a) ^ 2) /* read/write a word to a 32-bit space */ +#define BYTE8_XOR_BE(a) (a) +#define BYTE8_XOR_LE(a) ((a) ^ 7) /* read/write a byte to a 64-bit space */ +#define WORD2_XOR_BE(a) (a) +#define WORD2_XOR_LE(a) ((a) ^ 6) /* read/write a word to a 64-bit space */ +#define DWORD_XOR_BE(a) (a) +#define DWORD_XOR_LE(a) ((a) ^ 4) /* read/write a dword to a 64-bit space */ + +#endif + + + +/*************************************************************************** + ADDRESS MAP MACROS +***************************************************************************/ + +/* so that "0" can be used for unneeded address maps */ +#define address_map_0 NULL + + +/* maps a full 64-bit mask down to an 8-bit byte mask */ +#define UNITMASK8(x) \ + ((((UINT64)(x) >> (63-7)) & 0x80) | \ + (((UINT64)(x) >> (55-6)) & 0x40) | \ + (((UINT64)(x) >> (47-5)) & 0x20) | \ + (((UINT64)(x) >> (39-4)) & 0x10) | \ + (((UINT64)(x) >> (31-3)) & 0x08) | \ + (((UINT64)(x) >> (23-2)) & 0x04) | \ + (((UINT64)(x) >> (15-1)) & 0x02) | \ + (((UINT64)(x) >> ( 7-0)) & 0x01)) + +/* maps a full 64-bit mask down to a 4-bit word mask */ +#define UNITMASK16(x) \ + ((((UINT64)(x) >> (63-3)) & 0x08) | \ + (((UINT64)(x) >> (47-2)) & 0x04) | \ + (((UINT64)(x) >> (31-1)) & 0x02) | \ + (((UINT64)(x) >> (15-0)) & 0x01)) + +/* maps a full 64-bit mask down to a 2-bit dword mask */ +#define UNITMASK32(x) \ + ((((UINT64)(x) >> (63-1)) & 0x02) | \ + (((UINT64)(x) >> (31-0)) & 0x01)) + + + +/* start/end tags for the address map */ +#define ADDRESS_MAP_START(_name, _space, _bits) \ + const addrmap##_bits##_token address_map_##_name[] = { \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_START, 8, _space, 8, _bits, 8), + +#define ADDRESS_MAP_END \ + TOKEN_UINT32_PACK1(ADDRMAP_TOKEN_END, 8) }; + +/* use this to declare external references to an address map */ +#define ADDRESS_MAP_EXTERN(_name, _bits) \ + extern const addrmap##_bits##_token address_map_##_name[] + + +/* global controls */ +#define ADDRESS_MAP_GLOBAL_MASK(_mask) \ + TOKEN_UINT64_PACK2(ADDRMAP_TOKEN_GLOBAL_MASK, 8, _mask, 32), + +#define ADDRESS_MAP_UNMAP_LOW \ + TOKEN_UINT32_PACK2(ADDRMAP_TOKEN_UNMAP_VALUE, 8, 0, 1), + +#define ADDRESS_MAP_UNMAP_HIGH \ + TOKEN_UINT32_PACK2(ADDRMAP_TOKEN_UNMAP_VALUE, 8, 1, 1), + + +/* importing data from other address maps */ +#define AM_IMPORT_FROM(_name) \ + TOKEN_UINT32_PACK1(ADDRMAP_TOKEN_INCLUDE, 8), \ + TOKEN_PTR(tokenptr, address_map_##_name), + + +/* address ranges */ +#define AM_RANGE(_start, _end) \ + TOKEN_UINT32_PACK1(ADDRMAP_TOKEN_RANGE, 8), \ + TOKEN_UINT64_PACK2(_start, 32, _end, 32), + +#define AM_MASK(_mask) \ + TOKEN_UINT64_PACK2(ADDRMAP_TOKEN_MASK, 8, _mask, 32), + +#define AM_MIRROR(_mirror) \ + TOKEN_UINT64_PACK2(ADDRMAP_TOKEN_MIRROR, 8, _mirror, 32), + +#define AM_READ(_handler) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_READ, 8, 0, 8, 0, 8), \ + TOKEN_PTR(mread, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_READ8(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_READ, 8, 8, 8, UNITMASK8(_unitmask), 8), \ + TOKEN_PTR(mread8, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_READ16(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_READ, 8, 16, 8, UNITMASK16(_unitmask), 8), \ + TOKEN_PTR(mread16, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_READ32(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_READ, 8, 32, 8, UNITMASK32(_unitmask), 8), \ + TOKEN_PTR(mread32, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_WRITE(_handler) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_WRITE, 8, 0, 8, 0, 8), \ + TOKEN_PTR(mwrite, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_WRITE8(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_WRITE, 8, 8, 8, UNITMASK8(_unitmask), 8), \ + TOKEN_PTR(mwrite8, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_WRITE16(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_WRITE, 8, 16, 8, UNITMASK16(_unitmask), 8), \ + TOKEN_PTR(mwrite16, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_WRITE32(_handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_WRITE, 8, 32, 8, UNITMASK32(_unitmask), 8), \ + TOKEN_PTR(mwrite32, _handler), \ + TOKEN_STRING(#_handler), + +#define AM_DEVREAD(_type, _tag, _handler) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_READ, 8, 0, 8, 0, 8), \ + TOKEN_PTR(dread, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVREAD8(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_READ, 8, 8, 8, UNITMASK8(_unitmask), 8), \ + TOKEN_PTR(dread8, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVREAD16(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_READ, 8, 16, 8, UNITMASK16(_unitmask), 8), \ + TOKEN_PTR(dread16, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVREAD32(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_READ, 8, 32, 8, UNITMASK32(_unitmask), 8), \ + TOKEN_PTR(dread32, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVWRITE(_type, _tag, _handler) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_WRITE, 8, 0, 8, 0, 8), \ + TOKEN_PTR(dwrite, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVWRITE8(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_WRITE, 8, 8, 8, UNITMASK8(_unitmask), 8), \ + TOKEN_PTR(dwrite8, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVWRITE16(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_WRITE, 8, 16, 8, UNITMASK16(_unitmask), 8), \ + TOKEN_PTR(dwrite16, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_DEVWRITE32(_type, _tag, _handler, _unitmask) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_DEVICE_WRITE, 8, 32, 8, UNITMASK32(_unitmask), 8), \ + TOKEN_PTR(dwrite32, _handler), \ + TOKEN_STRING(#_handler), \ + TOKEN_PTR(devtype, _type), \ + TOKEN_STRING(_tag), + +#define AM_READ_PORT(_tag) \ + TOKEN_UINT32_PACK3(ADDRMAP_TOKEN_READ_PORT, 8, 0, 8, 0, 8), \ + TOKEN_STRING(_tag), + +#define AM_REGION(_region, _offs) \ + TOKEN_UINT64_PACK3(ADDRMAP_TOKEN_REGION, 8, _region, 24, _offs, 32), + +#define AM_SHARE(_index) \ + TOKEN_UINT32_PACK2(ADDRMAP_TOKEN_SHARE, 8, _index, 24), + +#define AM_BASE(_base) \ + TOKEN_UINT32_PACK1(ADDRMAP_TOKEN_BASEPTR, 8), \ + TOKEN_PTR(memptr, _base), + +#define AM_BASE_MEMBER(_struct, _member) \ + TOKEN_UINT32_PACK2(ADDRMAP_TOKEN_BASE_MEMBER, 8, offsetof(_struct, _member), 24), + +#define AM_SIZE(_size) \ + TOKEN_UINT32_PACK1(ADDRMAP_TOKEN_SIZEPTR, 8), \ + TOKEN_PTR(sizeptr, _size), + +#define AM_SIZE_MEMBER(_struct, _member) \ + TOKEN_UINT32_PACK2(ADDRMAP_TOKEN_SIZE_MEMBER, 8, offsetof(_struct, _member), 24), + + +/* common shortcuts */ +#define AM_READWRITE(_read,_write) AM_READ(_read) AM_WRITE(_write) +#define AM_READWRITE8(_read,_write,_mask) AM_READ8(_read,_mask) AM_WRITE8(_write,_mask) +#define AM_READWRITE16(_read,_write,_mask) AM_READ16(_read,_mask) AM_WRITE16(_write,_mask) +#define AM_READWRITE32(_read,_write,_mask) AM_READ32(_read,_mask) AM_WRITE32(_write,_mask) + +#define AM_DEVREADWRITE(_type,_tag,_read,_write) AM_DEVREAD(_type,_tag,_read) AM_DEVWRITE(_type,_tag,_write) +#define AM_DEVREADWRITE8(_type,_tag,_read,_write,_mask) AM_DEVREAD8(_type,_tag,_read,_mask) AM_DEVWRITE8(_type,_tag,_write,_mask) +#define AM_DEVREADWRITE16(_type,_tag,_read,_write,_mask) AM_DEVREAD16(_type,_tag,_read,_mask) AM_DEVWRITE16(_type,_tag,_write,_mask) +#define AM_DEVREADWRITE32(_type,_tag,_read,_write,_mask) AM_DEVREAD32(_type,_tag,_read,_mask) AM_DEVWRITE32(_type,_tag,_write,_mask) + +#define AM_ROM AM_READ(SMH_ROM) +#define AM_ROMBANK(_bank) AM_READ(SMH_BANK(_bank)) + +#define AM_RAM AM_READWRITE(SMH_RAM, SMH_RAM) +#define AM_RAMBANK(_bank) AM_READWRITE(SMH_BANK(_bank), SMH_BANK(_bank)) +#define AM_RAM_WRITE(_write) AM_READWRITE(SMH_RAM, _write) +#define AM_WRITEONLY AM_WRITE(SMH_RAM) + +#define AM_UNMAP AM_READWRITE(SMH_UNMAP, SMH_UNMAP) +#define AM_NOP AM_READWRITE(SMH_NOP, SMH_NOP) +#define AM_READNOP AM_READ(SMH_NOP) +#define AM_WRITENOP AM_WRITE(SMH_NOP) + + + +/*************************************************************************** + GLOBAL VARIABLES +***************************************************************************/ + +extern address_space active_address_space[]; /* address spaces */ + +extern const char *const address_space_names[ADDRESS_SPACES]; + + + +/*************************************************************************** + FUNCTION PROTOTYPES FOR CORE MEMORY FUNCTIONS +***************************************************************************/ + + +/* ----- core system operations ----- */ + +/* initialize the memory system */ +void memory_init(running_machine *machine); + +/* set the current memory context */ +void memory_set_context(int activecpu); + +/* get a pointer to the set of memory accessor functions based on the address space, + databus width, and endianness */ +const data_accessors *memory_get_accessors(int spacenum, int databits, int endianness); + + + +/* ----- address maps ----- */ + +/* build and allocate an address map for a CPU's address space */ +address_map *address_map_alloc(const machine_config *drv, int cpunum, int spacenum); + +/* release allocated memory for an address map */ +void address_map_free(address_map *map); + +/* return a pointer to the constructed address map for a CPU's address space */ +const address_map *memory_get_address_map(int cpunum, int spacenum); + + + +/* ----- opcode base control ----- */ + +/* registers an address range as having a decrypted data pointer */ +void memory_set_decrypted_region(int cpunum, offs_t addrstart, offs_t addrend, void *base); + +/* register a handler for opcode base changes on a given CPU */ +opbase_handler_func memory_set_opbase_handler(int cpunum, opbase_handler_func function); + +/* called by CPU cores to update the opcode base for the given address */ +void memory_set_opbase(offs_t byteaddress); + + + +/* return a base pointer to memory */ +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); +void memory_configure_bank_decrypted(int banknum, int startentry, int numentries, void *base, offs_t stride); +void memory_set_bank(int banknum, int entrynum); +int memory_get_bank(int banknum); +void memory_set_bankptr(int banknum, void *base); + + +/* 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_handler (running_machine *machine, 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_handler8 (running_machine *machine, 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_handler16(running_machine *machine, 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_handler32(running_machine *machine, 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_handler64(running_machine *machine, 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); + +/* dynamic device address space mapping */ +void * _memory_install_device_handler (const device_config *device, 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_device_handler8 (const device_config *device, int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read8_device_func rhandler, write8_device_func whandler, const char *rhandler_name, const char *whandler_name); +UINT16 * _memory_install_device_handler16(const device_config *device, int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read16_device_func rhandler, write16_device_func whandler, const char *rhandler_name, const char *whandler_name); +UINT32 * _memory_install_device_handler32(const device_config *device, int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read32_device_func rhandler, write32_device_func whandler, const char *rhandler_name, const char *whandler_name); +UINT64 * _memory_install_device_handler64(const device_config *device, int cpunum, int spacenum, offs_t addrstart, offs_t addrend, offs_t addrmask, offs_t addrmirror, read64_device_func rhandler, write64_device_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 byteaddress); + + + +/*************************************************************************** + HELPER MACROS AND INLINES +***************************************************************************/ + +/* generic memory access */ +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 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); + +/* opcode and opcode argument reading */ +INLINE void * cpu_opptr(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_opptr_unsafe(byteaddress); } +INLINE UINT8 cpu_readop(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_unsafe(byteaddress); } +INLINE UINT16 cpu_readop16(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop16_unsafe(byteaddress); } +INLINE UINT32 cpu_readop32(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop32_unsafe(byteaddress); } +INLINE UINT64 cpu_readop64(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop64_unsafe(byteaddress); } +INLINE UINT8 cpu_readop_arg(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg_unsafe(byteaddress); } +INLINE UINT16 cpu_readop_arg16(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg16_unsafe(byteaddress); } +INLINE UINT32 cpu_readop_arg32(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg32_unsafe(byteaddress); } +INLINE UINT64 cpu_readop_arg64(offs_t byteaddress) { extern opbase_data opbase; if (address_is_unsafe(byteaddress)) { memory_set_opbase(byteaddress); } return cpu_readop_arg64_unsafe(byteaddress); } + + +/*************************************************************************** + FUNCTION PROTOTYPES FOR CORE READ/WRITE ROUTINES +***************************************************************************/ + +/* declare program address space handlers */ +UINT8 program_read_byte_8le(offs_t address); +UINT16 program_read_word_8le(offs_t address); +UINT16 program_read_word_masked_8le(offs_t address, UINT16 mask); +UINT32 program_read_dword_8le(offs_t address); +UINT32 program_read_dword_masked_8le(offs_t address, UINT32 mask); +UINT64 program_read_qword_8le(offs_t address); +UINT64 program_read_qword_masked_8le(offs_t address, UINT64 mask); +void program_write_byte_8le(offs_t address, UINT8 data); +void program_write_word_8le(offs_t address, UINT16 data); +void program_write_word_masked_8le(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_8le(offs_t address, UINT32 data); +void program_write_dword_masked_8le(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_8le(offs_t address, UINT64 data); +void program_write_qword_masked_8le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_8be(offs_t address); +UINT16 program_read_word_8be(offs_t address); +UINT16 program_read_word_masked_8be(offs_t address, UINT16 mask); +UINT32 program_read_dword_8be(offs_t address); +UINT32 program_read_dword_masked_8be(offs_t address, UINT32 mask); +UINT64 program_read_qword_8be(offs_t address); +UINT64 program_read_qword_masked_8be(offs_t address, UINT64 mask); +void program_write_byte_8be(offs_t address, UINT8 data); +void program_write_word_8be(offs_t address, UINT16 data); +void program_write_word_masked_8be(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_8be(offs_t address, UINT32 data); +void program_write_dword_masked_8be(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_8be(offs_t address, UINT64 data); +void program_write_qword_masked_8be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_16le(offs_t address); +UINT16 program_read_word_16le(offs_t address); +UINT16 program_read_word_masked_16le(offs_t address, UINT16 mask); +UINT32 program_read_dword_16le(offs_t address); +UINT32 program_read_dword_masked_16le(offs_t address, UINT32 mask); +UINT64 program_read_qword_16le(offs_t address); +UINT64 program_read_qword_masked_16le(offs_t address, UINT64 mask); +void program_write_byte_16le(offs_t address, UINT8 data); +void program_write_word_16le(offs_t address, UINT16 data); +void program_write_word_masked_16le(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_16le(offs_t address, UINT32 data); +void program_write_dword_masked_16le(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_16le(offs_t address, UINT64 data); +void program_write_qword_masked_16le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_16be(offs_t address); +UINT16 program_read_word_16be(offs_t address); +UINT16 program_read_word_masked_16be(offs_t address, UINT16 mask); +UINT32 program_read_dword_16be(offs_t address); +UINT32 program_read_dword_masked_16be(offs_t address, UINT32 mask); +UINT64 program_read_qword_16be(offs_t address); +UINT64 program_read_qword_masked_16be(offs_t address, UINT64 mask); +void program_write_byte_16be(offs_t address, UINT8 data); +void program_write_word_16be(offs_t address, UINT16 data); +void program_write_word_masked_16be(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_16be(offs_t address, UINT32 data); +void program_write_dword_masked_16be(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_16be(offs_t address, UINT64 data); +void program_write_qword_masked_16be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_32le(offs_t address); +UINT16 program_read_word_32le(offs_t address); +UINT16 program_read_word_masked_32le(offs_t address, UINT16 mask); +UINT32 program_read_dword_32le(offs_t address); +UINT32 program_read_dword_masked_32le(offs_t address, UINT32 mask); +UINT64 program_read_qword_32le(offs_t address); +UINT64 program_read_qword_masked_32le(offs_t address, UINT64 mask); +void program_write_byte_32le(offs_t address, UINT8 data); +void program_write_word_32le(offs_t address, UINT16 data); +void program_write_word_masked_32le(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_32le(offs_t address, UINT32 data); +void program_write_dword_masked_32le(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_32le(offs_t address, UINT64 data); +void program_write_qword_masked_32le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_32be(offs_t address); +UINT16 program_read_word_32be(offs_t address); +UINT16 program_read_word_masked_32be(offs_t address, UINT16 mask); +UINT32 program_read_dword_32be(offs_t address); +UINT32 program_read_dword_masked_32be(offs_t address, UINT32 mask); +UINT64 program_read_qword_32be(offs_t address); +UINT64 program_read_qword_masked_32be(offs_t address, UINT64 mask); +void program_write_byte_32be(offs_t address, UINT8 data); +void program_write_word_32be(offs_t address, UINT16 data); +void program_write_word_masked_32be(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_32be(offs_t address, UINT32 data); +void program_write_dword_masked_32be(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_32be(offs_t address, UINT64 data); +void program_write_qword_masked_32be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_64le(offs_t address); +UINT16 program_read_word_64le(offs_t address); +UINT16 program_read_word_masked_64le(offs_t address, UINT16 mask); +UINT32 program_read_dword_64le(offs_t address); +UINT32 program_read_dword_masked_64le(offs_t address, UINT32 mask); +UINT64 program_read_qword_64le(offs_t address); +UINT64 program_read_qword_masked_64le(offs_t address, UINT64 mask); +void program_write_byte_64le(offs_t address, UINT8 data); +void program_write_word_64le(offs_t address, UINT16 data); +void program_write_word_masked_64le(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_64le(offs_t address, UINT32 data); +void program_write_dword_masked_64le(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_64le(offs_t address, UINT64 data); +void program_write_qword_masked_64le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 program_read_byte_64be(offs_t address); +UINT16 program_read_word_64be(offs_t address); +UINT16 program_read_word_masked_64be(offs_t address, UINT16 mask); +UINT32 program_read_dword_64be(offs_t address); +UINT32 program_read_dword_masked_64be(offs_t address, UINT32 mask); +UINT64 program_read_qword_64be(offs_t address); +UINT64 program_read_qword_masked_64be(offs_t address, UINT64 mask); +void program_write_byte_64be(offs_t address, UINT8 data); +void program_write_word_64be(offs_t address, UINT16 data); +void program_write_word_masked_64be(offs_t address, UINT16 data, UINT16 mask); +void program_write_dword_64be(offs_t address, UINT32 data); +void program_write_dword_masked_64be(offs_t address, UINT32 data, UINT32 mask); +void program_write_qword_64be(offs_t address, UINT64 data); +void program_write_qword_masked_64be(offs_t address, UINT64 data, UINT64 mask); + + +/* declare data address space handlers */ +UINT8 data_read_byte_8le(offs_t address); +UINT16 data_read_word_8le(offs_t address); +UINT16 data_read_word_masked_8le(offs_t address, UINT16 mask); +UINT32 data_read_dword_8le(offs_t address); +UINT32 data_read_dword_masked_8le(offs_t address, UINT32 mask); +UINT64 data_read_qword_8le(offs_t address); +UINT64 data_read_qword_masked_8le(offs_t address, UINT64 mask); +void data_write_byte_8le(offs_t address, UINT8 data); +void data_write_word_8le(offs_t address, UINT16 data); +void data_write_word_masked_8le(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_8le(offs_t address, UINT32 data); +void data_write_dword_masked_8le(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_8le(offs_t address, UINT64 data); +void data_write_qword_masked_8le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_8be(offs_t address); +UINT16 data_read_word_8be(offs_t address); +UINT16 data_read_word_masked_8be(offs_t address, UINT16 mask); +UINT32 data_read_dword_8be(offs_t address); +UINT32 data_read_dword_masked_8be(offs_t address, UINT32 mask); +UINT64 data_read_qword_8be(offs_t address); +UINT64 data_read_qword_masked_8be(offs_t address, UINT64 mask); +void data_write_byte_8be(offs_t address, UINT8 data); +void data_write_word_8be(offs_t address, UINT16 data); +void data_write_word_masked_8be(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_8be(offs_t address, UINT32 data); +void data_write_dword_masked_8be(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_8be(offs_t address, UINT64 data); +void data_write_qword_masked_8be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_16le(offs_t address); +UINT16 data_read_word_16le(offs_t address); +UINT16 data_read_word_masked_16le(offs_t address, UINT16 mask); +UINT32 data_read_dword_16le(offs_t address); +UINT32 data_read_dword_masked_16le(offs_t address, UINT32 mask); +UINT64 data_read_qword_16le(offs_t address); +UINT64 data_read_qword_masked_16le(offs_t address, UINT64 mask); +void data_write_byte_16le(offs_t address, UINT8 data); +void data_write_word_16le(offs_t address, UINT16 data); +void data_write_word_masked_16le(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_16le(offs_t address, UINT32 data); +void data_write_dword_masked_16le(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_16le(offs_t address, UINT64 data); +void data_write_qword_masked_16le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_16be(offs_t address); +UINT16 data_read_word_16be(offs_t address); +UINT16 data_read_word_masked_16be(offs_t address, UINT16 mask); +UINT32 data_read_dword_16be(offs_t address); +UINT32 data_read_dword_masked_16be(offs_t address, UINT32 mask); +UINT64 data_read_qword_16be(offs_t address); +UINT64 data_read_qword_masked_16be(offs_t address, UINT64 mask); +void data_write_byte_16be(offs_t address, UINT8 data); +void data_write_word_16be(offs_t address, UINT16 data); +void data_write_word_masked_16be(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_16be(offs_t address, UINT32 data); +void data_write_dword_masked_16be(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_16be(offs_t address, UINT64 data); +void data_write_qword_masked_16be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_32le(offs_t address); +UINT16 data_read_word_32le(offs_t address); +UINT16 data_read_word_masked_32le(offs_t address, UINT16 mask); +UINT32 data_read_dword_32le(offs_t address); +UINT32 data_read_dword_masked_32le(offs_t address, UINT32 mask); +UINT64 data_read_qword_32le(offs_t address); +UINT64 data_read_qword_masked_32le(offs_t address, UINT64 mask); +void data_write_byte_32le(offs_t address, UINT8 data); +void data_write_word_32le(offs_t address, UINT16 data); +void data_write_word_masked_32le(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_32le(offs_t address, UINT32 data); +void data_write_dword_masked_32le(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_32le(offs_t address, UINT64 data); +void data_write_qword_masked_32le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_32be(offs_t address); +UINT16 data_read_word_32be(offs_t address); +UINT16 data_read_word_masked_32be(offs_t address, UINT16 mask); +UINT32 data_read_dword_32be(offs_t address); +UINT32 data_read_dword_masked_32be(offs_t address, UINT32 mask); +UINT64 data_read_qword_32be(offs_t address); +UINT64 data_read_qword_masked_32be(offs_t address, UINT64 mask); +void data_write_byte_32be(offs_t address, UINT8 data); +void data_write_word_32be(offs_t address, UINT16 data); +void data_write_word_masked_32be(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_32be(offs_t address, UINT32 data); +void data_write_dword_masked_32be(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_32be(offs_t address, UINT64 data); +void data_write_qword_masked_32be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_64le(offs_t address); +UINT16 data_read_word_64le(offs_t address); +UINT16 data_read_word_masked_64le(offs_t address, UINT16 mask); +UINT32 data_read_dword_64le(offs_t address); +UINT32 data_read_dword_masked_64le(offs_t address, UINT32 mask); +UINT64 data_read_qword_64le(offs_t address); +UINT64 data_read_qword_masked_64le(offs_t address, UINT64 mask); +void data_write_byte_64le(offs_t address, UINT8 data); +void data_write_word_64le(offs_t address, UINT16 data); +void data_write_word_masked_64le(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_64le(offs_t address, UINT32 data); +void data_write_dword_masked_64le(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_64le(offs_t address, UINT64 data); +void data_write_qword_masked_64le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 data_read_byte_64be(offs_t address); +UINT16 data_read_word_64be(offs_t address); +UINT16 data_read_word_masked_64be(offs_t address, UINT16 mask); +UINT32 data_read_dword_64be(offs_t address); +UINT32 data_read_dword_masked_64be(offs_t address, UINT32 mask); +UINT64 data_read_qword_64be(offs_t address); +UINT64 data_read_qword_masked_64be(offs_t address, UINT64 mask); +void data_write_byte_64be(offs_t address, UINT8 data); +void data_write_word_64be(offs_t address, UINT16 data); +void data_write_word_masked_64be(offs_t address, UINT16 data, UINT16 mask); +void data_write_dword_64be(offs_t address, UINT32 data); +void data_write_dword_masked_64be(offs_t address, UINT32 data, UINT32 mask); +void data_write_qword_64be(offs_t address, UINT64 data); +void data_write_qword_masked_64be(offs_t address, UINT64 data, UINT64 mask); + + +/* declare io address space handlers */ +UINT8 io_read_byte_8le(offs_t address); +UINT16 io_read_word_8le(offs_t address); +UINT16 io_read_word_masked_8le(offs_t address, UINT16 mask); +UINT32 io_read_dword_8le(offs_t address); +UINT32 io_read_dword_masked_8le(offs_t address, UINT32 mask); +UINT64 io_read_qword_8le(offs_t address); +UINT64 io_read_qword_masked_8le(offs_t address, UINT64 mask); +void io_write_byte_8le(offs_t address, UINT8 data); +void io_write_word_8le(offs_t address, UINT16 data); +void io_write_word_masked_8le(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_8le(offs_t address, UINT32 data); +void io_write_dword_masked_8le(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_8le(offs_t address, UINT64 data); +void io_write_qword_masked_8le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_8be(offs_t address); +UINT16 io_read_word_8be(offs_t address); +UINT16 io_read_word_masked_8be(offs_t address, UINT16 mask); +UINT32 io_read_dword_8be(offs_t address); +UINT32 io_read_dword_masked_8be(offs_t address, UINT32 mask); +UINT64 io_read_qword_8be(offs_t address); +UINT64 io_read_qword_masked_8be(offs_t address, UINT64 mask); +void io_write_byte_8be(offs_t address, UINT8 data); +void io_write_word_8be(offs_t address, UINT16 data); +void io_write_word_masked_8be(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_8be(offs_t address, UINT32 data); +void io_write_dword_masked_8be(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_8be(offs_t address, UINT64 data); +void io_write_qword_masked_8be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_16le(offs_t address); +UINT16 io_read_word_16le(offs_t address); +UINT16 io_read_word_masked_16le(offs_t address, UINT16 mask); +UINT32 io_read_dword_16le(offs_t address); +UINT32 io_read_dword_masked_16le(offs_t address, UINT32 mask); +UINT64 io_read_qword_16le(offs_t address); +UINT64 io_read_qword_masked_16le(offs_t address, UINT64 mask); +void io_write_byte_16le(offs_t address, UINT8 data); +void io_write_word_16le(offs_t address, UINT16 data); +void io_write_word_masked_16le(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_16le(offs_t address, UINT32 data); +void io_write_dword_masked_16le(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_16le(offs_t address, UINT64 data); +void io_write_qword_masked_16le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_16be(offs_t address); +UINT16 io_read_word_16be(offs_t address); +UINT16 io_read_word_masked_16be(offs_t address, UINT16 mask); +UINT32 io_read_dword_16be(offs_t address); +UINT32 io_read_dword_masked_16be(offs_t address, UINT32 mask); +UINT64 io_read_qword_16be(offs_t address); +UINT64 io_read_qword_masked_16be(offs_t address, UINT64 mask); +void io_write_byte_16be(offs_t address, UINT8 data); +void io_write_word_16be(offs_t address, UINT16 data); +void io_write_word_masked_16be(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_16be(offs_t address, UINT32 data); +void io_write_dword_masked_16be(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_16be(offs_t address, UINT64 data); +void io_write_qword_masked_16be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_32le(offs_t address); +UINT16 io_read_word_32le(offs_t address); +UINT16 io_read_word_masked_32le(offs_t address, UINT16 mask); +UINT32 io_read_dword_32le(offs_t address); +UINT32 io_read_dword_masked_32le(offs_t address, UINT32 mask); +UINT64 io_read_qword_32le(offs_t address); +UINT64 io_read_qword_masked_32le(offs_t address, UINT64 mask); +void io_write_byte_32le(offs_t address, UINT8 data); +void io_write_word_32le(offs_t address, UINT16 data); +void io_write_word_masked_32le(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_32le(offs_t address, UINT32 data); +void io_write_dword_masked_32le(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_32le(offs_t address, UINT64 data); +void io_write_qword_masked_32le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_32be(offs_t address); +UINT16 io_read_word_32be(offs_t address); +UINT16 io_read_word_masked_32be(offs_t address, UINT16 mask); +UINT32 io_read_dword_32be(offs_t address); +UINT32 io_read_dword_masked_32be(offs_t address, UINT32 mask); +UINT64 io_read_qword_32be(offs_t address); +UINT64 io_read_qword_masked_32be(offs_t address, UINT64 mask); +void io_write_byte_32be(offs_t address, UINT8 data); +void io_write_word_32be(offs_t address, UINT16 data); +void io_write_word_masked_32be(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_32be(offs_t address, UINT32 data); +void io_write_dword_masked_32be(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_32be(offs_t address, UINT64 data); +void io_write_qword_masked_32be(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_64le(offs_t address); +UINT16 io_read_word_64le(offs_t address); +UINT16 io_read_word_masked_64le(offs_t address, UINT16 mask); +UINT32 io_read_dword_64le(offs_t address); +UINT32 io_read_dword_masked_64le(offs_t address, UINT32 mask); +UINT64 io_read_qword_64le(offs_t address); +UINT64 io_read_qword_masked_64le(offs_t address, UINT64 mask); +void io_write_byte_64le(offs_t address, UINT8 data); +void io_write_word_64le(offs_t address, UINT16 data); +void io_write_word_masked_64le(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_64le(offs_t address, UINT32 data); +void io_write_dword_masked_64le(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_64le(offs_t address, UINT64 data); +void io_write_qword_masked_64le(offs_t address, UINT64 data, UINT64 mask); + +UINT8 io_read_byte_64be(offs_t address); +UINT16 io_read_word_64be(offs_t address); +UINT16 io_read_word_masked_64be(offs_t address, UINT16 mask); +UINT32 io_read_dword_64be(offs_t address); +UINT32 io_read_dword_masked_64be(offs_t address, UINT32 mask); +UINT64 io_read_qword_64be(offs_t address); +UINT64 io_read_qword_masked_64be(offs_t address, UINT64 mask); +void io_write_byte_64be(offs_t address, UINT8 data); +void io_write_word_64be(offs_t address, UINT16 data); +void io_write_word_masked_64be(offs_t address, UINT16 data, UINT16 mask); +void io_write_dword_64be(offs_t address, UINT32 data); +void io_write_dword_masked_64be(offs_t address, UINT32 data, UINT32 mask); +void io_write_qword_64be(offs_t address, UINT64 data); +void io_write_qword_masked_64be(offs_t address, UINT64 data, UINT64 mask); + + +#endif /* __MEMORY_H__ */ diff --git a/TIKI-100_emul-src/messaudio/osdcomm.h b/TIKI-100_emul-src/messaudio/osdcomm.h new file mode 100644 index 0000000..c1764de --- /dev/null +++ b/TIKI-100_emul-src/messaudio/osdcomm.h @@ -0,0 +1,187 @@ +/*************************************************************************** + + osdcomm.h + + Common definitions shared by the OSD layer. This includes the most + fundamental integral types as well as compiler-specific tweaks. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __OSDCOMM_H__ +#define __OSDCOMM_H__ + +#include +#include +#include + +#define INLINE static __inline__ + + +/*************************************************************************** + COMPILER-SPECIFIC NASTINESS +***************************************************************************/ + +/* The Win32 port requires this constant for variable arg routines. */ +#ifndef CLIB_DECL +#define CLIB_DECL +#endif + + +/* Some optimizations/warnings cleanups for GCC */ +#if defined(__GNUC__) && (__GNUC__ >= 3) +#define ATTR_UNUSED __attribute__((__unused__)) +#define ATTR_NORETURN __attribute__((noreturn)) +#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y))) +#define ATTR_MALLOC __attribute__((malloc)) +#define ATTR_PURE __attribute__((pure)) +#define ATTR_CONST __attribute__((const)) +#define ATTR_FORCE_INLINE __attribute__((always_inline)) +#define ATTR_NONNULL __attribute__((nonnull(1))) +#define UNEXPECTED(exp) __builtin_expect((exp), 0) +#define TYPES_COMPATIBLE(a,b) __builtin_types_compatible_p(a, b) +#define RESTRICT __restrict__ +#define SETJMP_GNUC_PROTECT() (void)__builtin_return_address(1) +#else +#define ATTR_UNUSED +#define ATTR_NORETURN +#define ATTR_PRINTF(x,y) +#define ATTR_MALLOC +#define ATTR_PURE +#define ATTR_CONST +#define ATTR_FORCE_INLINE +#define ATTR_NONNULL +#define UNEXPECTED(exp) (exp) +#define TYPES_COMPATIBLE(a,b) 1 +#define RESTRICT +#define SETJMP_GNUC_PROTECT() do {} while (0) +#endif + + +/* And some MSVC optimizations/warnings */ +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +#define DECL_NORETURN __declspec(noreturn) +#else +#define DECL_NORETURN +#endif + + + +/*************************************************************************** + FUNDAMENTAL TYPES +***************************************************************************/ + +/* These types work on most modern compilers; however, OSD code can + define their own by setting OSD_TYPES_DEFINED */ + +#ifndef OSD_TYPES_DEFINED + +/* 8-bit values */ +typedef unsigned char UINT8; +typedef signed char INT8; + +/* 16-bit values */ +typedef unsigned short UINT16; +typedef signed short INT16; + +/* 32-bit values */ +#ifndef _WINDOWS_H +typedef unsigned int UINT32; +typedef signed int INT32; +#endif + +/* 64-bit values */ +#ifndef _WINDOWS_H +#ifdef _MSC_VER +typedef signed __int64 INT64; +typedef unsigned __int64 UINT64; +#else +__extension__ typedef unsigned long long UINT64; +__extension__ typedef signed long long INT64; +#endif +#endif + +#endif + + + +/*************************************************************************** + FUNDAMENTAL CONSTANTS +***************************************************************************/ + +/* Ensure that TRUE/FALSE are defined */ +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + + + +/*************************************************************************** + FUNDAMENTAL MACROS +***************************************************************************/ + +/* Standard MIN/MAX macros */ +#ifndef MIN +#define MIN(x,y) ((x) < (y) ? (x) : (y)) +#endif +#ifndef MAX +#define MAX(x,y) ((x) > (y) ? (x) : (y)) +#endif + + +/* U64 and S64 are used to wrap long integer constants. */ +#ifdef __GNUC__ +#define U64(val) val##ULL +#define S64(val) val##LL +#else +#define U64(val) val +#define S64(val) val +#endif + + +/* Highly useful macro for compile-time knowledge of an array size */ +#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0])) + + +/* Macros for normalizing data into big or little endian formats */ +#define FLIPENDIAN_INT16(x) (((((UINT16) (x)) >> 8) | ((x) << 8)) & 0xffff) +#define FLIPENDIAN_INT32(x) ((((UINT32) (x)) << 24) | (((UINT32) (x)) >> 24) | \ + (( ((UINT32) (x)) & 0x0000ff00) << 8) | (( ((UINT32) (x)) & 0x00ff0000) >> 8)) +#define FLIPENDIAN_INT64(x) \ + ( \ + (((((UINT64) (x)) >> 56) & ((UINT64) 0xFF)) << 0) | \ + (((((UINT64) (x)) >> 48) & ((UINT64) 0xFF)) << 8) | \ + (((((UINT64) (x)) >> 40) & ((UINT64) 0xFF)) << 16) | \ + (((((UINT64) (x)) >> 32) & ((UINT64) 0xFF)) << 24) | \ + (((((UINT64) (x)) >> 24) & ((UINT64) 0xFF)) << 32) | \ + (((((UINT64) (x)) >> 16) & ((UINT64) 0xFF)) << 40) | \ + (((((UINT64) (x)) >> 8) & ((UINT64) 0xFF)) << 48) | \ + (((((UINT64) (x)) >> 0) & ((UINT64) 0xFF)) << 56) \ + ) + +#ifdef LSB_FIRST +#define BIG_ENDIANIZE_INT16(x) (FLIPENDIAN_INT16(x)) +#define BIG_ENDIANIZE_INT32(x) (FLIPENDIAN_INT32(x)) +#define BIG_ENDIANIZE_INT64(x) (FLIPENDIAN_INT64(x)) +#define LITTLE_ENDIANIZE_INT16(x) (x) +#define LITTLE_ENDIANIZE_INT32(x) (x) +#define LITTLE_ENDIANIZE_INT64(x) (x) +#else +#define BIG_ENDIANIZE_INT16(x) (x) +#define BIG_ENDIANIZE_INT32(x) (x) +#define BIG_ENDIANIZE_INT64(x) (x) +#define LITTLE_ENDIANIZE_INT16(x) (FLIPENDIAN_INT16(x)) +#define LITTLE_ENDIANIZE_INT32(x) (FLIPENDIAN_INT32(x)) +#define LITTLE_ENDIANIZE_INT64(x) (FLIPENDIAN_INT64(x)) +#endif /* LSB_FIRST */ + + +#endif /* __OSDCOMM_H__ */ diff --git a/TIKI-100_emul-src/messaudio/osdcore.h b/TIKI-100_emul-src/messaudio/osdcore.h new file mode 100644 index 0000000..bf34925 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/osdcore.h @@ -0,0 +1,802 @@ +/*************************************************************************** + + osdcore.h + + Core OS-dependent code interface. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +**************************************************************************** + + The prototypes in this file describe the interfaces that the MAME core + and various tools rely upon to interact with the outside world. They are + broken out into several categories. + +***************************************************************************/ + +#pragma once + +#ifndef __OSDCORE_H__ +#define __OSDCORE_H__ + +#include "osdcomm.h" + + + +/*************************************************************************** + FILE I/O INTERFACES +***************************************************************************/ + +/* Make sure we have a path separator (default to /) */ +#ifndef PATH_SEPARATOR +#define PATH_SEPARATOR "/" +#endif + +/* flags controlling file access */ +#define OPEN_FLAG_READ 0x0001 /* open for read */ +#define OPEN_FLAG_WRITE 0x0002 /* open for write */ +#define OPEN_FLAG_CREATE 0x0004 /* create & truncate file */ +#define OPEN_FLAG_CREATE_PATHS 0x0008 /* create paths as necessary */ + +/* error codes returned by routines below */ +enum _file_error +{ + FILERR_NONE, + FILERR_FAILURE, + FILERR_OUT_OF_MEMORY, + FILERR_NOT_FOUND, + FILERR_ACCESS_DENIED, + FILERR_ALREADY_OPEN, + FILERR_TOO_MANY_FILES, + FILERR_INVALID_DATA, + FILERR_INVALID_ACCESS +}; +typedef enum _file_error file_error; + +/* osd_file is an opaque type which represents an open file */ +typedef struct _osd_file osd_file; + + +/*----------------------------------------------------------------------------- + osd_open: open a new file. + + Parameters: + + path - path to the file to open + + openflags - some combination of: + + OPEN_FLAG_READ - open the file for read access + OPEN_FLAG_WRITE - open the file for write access + OPEN_FLAG_CREATE - create/truncate the file when opening + OPEN_FLAG_CREATE_PATHS - specifies that non-existant paths + should be created if necessary + + file - pointer to an osd_file * to receive the newly-opened file + handle; this is only valid if the function returns FILERR_NONE + + filesize - pointer to a UINT64 to receive the size of the opened + file; this is only valid if the function returns FILERR_NONE + + Return value: + + a file_error describing any error that occurred while opening + the file, or FILERR_NONE if no error occurred + + Notes: + + This function is called by mame_fopen and several other places in + the core to access files. These functions will construct paths by + concatenating various search paths held in the options.c options + database with partial paths specified by the core. The core assumes + that the path separator is the first character of the string + PATH_SEPARATOR, but does not interpret any path separators in the + search paths, so if you use a different path separator in a search + path, you may get a mixture of PATH_SEPARATORs (from the core) and + alternate path separators (specified by users and placed into the + options database). +-----------------------------------------------------------------------------*/ +file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize); + + +/*----------------------------------------------------------------------------- + osd_close: close an open file + + Parameters: + + file - handle to a file previously opened via osd_open + + Return value: + + a file_error describing any error that occurred while closing + the file, or FILERR_NONE if no error occurred +-----------------------------------------------------------------------------*/ +file_error osd_close(osd_file *file); + + +/*----------------------------------------------------------------------------- + osd_read: read from an open file + + Parameters: + + file - handle to a file previously opened via osd_open + + buffer - pointer to memory that will receive the data read + + offset - offset within the file to read from + + length - number of bytes to read from the file + + actual - pointer to a UINT32 to receive the number of bytes actually + read during the operation; valid only if the function returns + FILERR_NONE + + Return value: + + a file_error describing any error that occurred while reading + from the file, or FILERR_NONE if no error occurred +-----------------------------------------------------------------------------*/ +file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 length, UINT32 *actual); + + +/*----------------------------------------------------------------------------- + osd_write: write to an open file + + Parameters: + + file - handle to a file previously opened via osd_open + + buffer - pointer to memory that contains the data to write + + offset - offset within the file to write to + + length - number of bytes to write to the file + + actual - pointer to a UINT32 to receive the number of bytes actually + written during the operation; valid only if the function returns + FILERR_NONE + + Return value: + + a file_error describing any error that occurred while writing to + the file, or FILERR_NONE if no error occurred +-----------------------------------------------------------------------------*/ +file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual); + + +/*----------------------------------------------------------------------------- + osd_rmfile: deletes a file + + Parameters: + + filename - path to file to delete + + Return value: + + a file_error describing any error that occurred while deleting + the file, or FILERR_NONE if no error occurred +-----------------------------------------------------------------------------*/ +file_error osd_rmfile(const char *filename); + + +/*----------------------------------------------------------------------------- + osd_get_physical_drive_geometry: if the given path points to a physical + drive, return the geometry of that drive + + Parameters: + + filename - pointer to a path which might describe a physical drive + + cylinders - pointer to a UINT32 to receive the number of cylinders + of the physical drive + + heads - pointer to a UINT32 to receive the number of heads per + cylinder of the physical drive + + sectors - pointer to a UINT32 to receive the number of sectors per + cylinder of the physical drive + + bps - pointer to a UINT32 to receive the number of bytes per sector + of the physical drive + + Return value: + + TRUE if the filename points to a physical drive and if the values + pointed to by cylinders, heads, sectors, and bps are valid; FALSE in + any other case +-----------------------------------------------------------------------------*/ +int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UINT32 *heads, UINT32 *sectors, UINT32 *bps); + + +/*----------------------------------------------------------------------------- + osd_uchar_from_osdchar: convert the given character or sequence of + characters from the OS-default encoding to a Unicode character + + Parameters: + + uchar - pointer to a UINT32 to receive the resulting unicode + character + + osdchar - pointer to one or more chars that are in the OS-default + encoding + + count - number of characters provided in the OS-default encoding + + Return value: + + The number of characters required to form a Unicode character. +-----------------------------------------------------------------------------*/ +int osd_uchar_from_osdchar(UINT32 /* unicode_char */ *uchar, const char *osdchar, size_t count); + + + +/*************************************************************************** + DIRECTORY INTERFACES +***************************************************************************/ + +/* types of directory entries that can be returned */ +enum _osd_dir_entry_type +{ + ENTTYPE_NONE, + ENTTYPE_FILE, + ENTTYPE_DIR, + ENTTYPE_OTHER +}; +typedef enum _osd_dir_entry_type osd_dir_entry_type; + +/* osd_directory is an opaque type which represents an open directory */ +typedef struct _osd_directory osd_directory; + +/* osd_directory_entry contains basic information about a file when iterating through */ +/* a directory */ +typedef struct _osd_directory_entry osd_directory_entry; +struct _osd_directory_entry +{ + const char * name; /* name of the entry */ + osd_dir_entry_type type; /* type of the entry */ + UINT64 size; /* size of the entry */ +}; + + +/*----------------------------------------------------------------------------- + osd_opendir: open a directory for iteration + + Parameters: + + dirname - path to the directory in question + + Return value: + + upon success, this function should return an osd_directory pointer + which contains opaque data necessary to traverse the directory; on + failure, this function should return NULL +-----------------------------------------------------------------------------*/ +osd_directory *osd_opendir(const char *dirname); + + +/*----------------------------------------------------------------------------- + osd_readdir: return information about the next entry in the directory + + Parameters: + + dir - pointer to an osd_directory that was returned from a prior + call to osd_opendir + + Return value: + + a constant pointer to an osd_directory_entry representing the current item + in the directory, or NULL, indicating that no more entries are + present +-----------------------------------------------------------------------------*/ +const osd_directory_entry *osd_readdir(osd_directory *dir); + + +/*----------------------------------------------------------------------------- + osd_closedir: close an open directory for iteration + + Parameters: + + dir - pointer to an osd_directory that was returned from a prior + call to osd_opendir + + Return value: + + frees any allocated memory and resources associated with the open + directory +-----------------------------------------------------------------------------*/ +void osd_closedir(osd_directory *dir); + + +/*----------------------------------------------------------------------------- + osd_is_absolute_path: returns whether the specified path is absolute + + Parameters: + + path - the path in question + + Return value: + + non-zero if the path is absolute, zero otherwise +-----------------------------------------------------------------------------*/ +int osd_is_absolute_path(const char *path); + + + +/*************************************************************************** + TIMING INTERFACES +***************************************************************************/ + +/* a osd_ticks_t is a 64-bit integer that is used as a core type in timing interfaces */ +typedef INT64 osd_ticks_t; + + +/*----------------------------------------------------------------------------- + osd_ticks: return the current running tick counter + + Parameters: + + None + + Return value: + + an osd_ticks_t value which represents the current tick counter + + Notes: + + The resolution of this counter should be 1ms or better for accurate + performance. It is also important that the source of this timer be + accurate. It is ok if this call is not ultra-fast, since it is + primarily used for once/frame synchronization. +-----------------------------------------------------------------------------*/ +osd_ticks_t osd_ticks(void); + + +/*----------------------------------------------------------------------------- + osd_ticks_per_second: return the number of ticks per second + + Parameters: + + None + + Return value: + + an osd_ticks_t value which represents the number of ticks per + second +-----------------------------------------------------------------------------*/ +osd_ticks_t osd_ticks_per_second(void); + + +/*----------------------------------------------------------------------------- + osd_profiling_ticks: return the current running "profiling" tick counter + + Parameters: + + None + + Return value: + + an osd_ticks_t value which represents the current "profiling" tick + counter + + Notes: + + The profiling tick counter may or may not be different from the + regular tick counter. However, the profiling counter has differing + requirements. First, it must be as fast as possible, so as not to + perturb profiling measurements in a significant way. Second, it + should be a high resolution as possible to provide accurate short- + term measurements (1us resolution or better is ideal). Third, it + is not necessary to calibrate the timing (hence the lack of an + osd_profiling_ticks_per_second call). + + On x86 system, this generally maps to an RDTSC instruction. +-----------------------------------------------------------------------------*/ +osd_ticks_t osd_profiling_ticks(void); + + +/*----------------------------------------------------------------------------- + osd_sleep: sleep for the specified time interval + + Parameters: + + duration - an osd_ticks_t value that specifies how long we should + sleep + + Return value: + + None + + Notes: + + The OSD layer should try to sleep for as close to the specified + duration as possible, or less. This is used as a mechanism to + "give back" unneeded time to other programs running in the system. + On a simple, non multitasking system, this routine can be a no-op. + If there is significant volatility in the amount of time that the + sleep occurs for, the OSD layer should strive to sleep for less time + than specified rather than sleeping too long. +-----------------------------------------------------------------------------*/ +void osd_sleep(osd_ticks_t duration); + + + +/*************************************************************************** + SYNCHRONIZATION INTERFACES +***************************************************************************/ + +/* osd_lock is an opaque type which represents a recursive lock/mutex */ +typedef struct _osd_lock osd_lock; + + +/*----------------------------------------------------------------------------- + osd_lock_alloc: allocate a new lock + + Parameters: + + None. + + Return value: + + A pointer to the allocated lock. +-----------------------------------------------------------------------------*/ +osd_lock *osd_lock_alloc(void); + + +/*----------------------------------------------------------------------------- + osd_lock_acquire: acquire a lock, blocking until it can be acquired + + Parameters: + + lock - a pointer to a previously allocated osd_lock. + + Return value: + + None. + + Notes: + + osd_locks are defined to be recursive. If the current thread already + owns the lock, this function should return immediately. +-----------------------------------------------------------------------------*/ +void osd_lock_acquire(osd_lock *lock); + + +/*----------------------------------------------------------------------------- + osd_lock_try: attempt to acquire a lock + + Parameters: + + lock - a pointer to a previously allocated osd_lock. + + Return value: + + TRUE if the lock was available and was acquired successfully. + FALSE if the lock was already in used by another thread. +-----------------------------------------------------------------------------*/ +int osd_lock_try(osd_lock *lock); + + +/*----------------------------------------------------------------------------- + osd_lock_release: release control of a lock that has been acquired + + Parameters: + + lock - a pointer to a previously allocated osd_lock. + + Return value: + + None. +-----------------------------------------------------------------------------*/ +void osd_lock_release(osd_lock *lock); + + +/*----------------------------------------------------------------------------- + osd_lock_free: free the memory and resources associated with an osd_lock + + Parameters: + + lock - a pointer to a previously allocated osd_lock. + + Return value: + + None. +-----------------------------------------------------------------------------*/ +void osd_lock_free(osd_lock *lock); + + + +/*************************************************************************** + WORK ITEM INTERFACES +***************************************************************************/ + +/* this is the maximum number of supported threads for a single work queue */ +/* threadid values are expected to range from 0..WORK_MAX_THREADS-1 */ +#define WORK_MAX_THREADS 16 + +/* these flags can be set when creating a queue to give hints to the code about + how to configure the queue */ +#define WORK_QUEUE_FLAG_IO 0x0001 +#define WORK_QUEUE_FLAG_MULTI 0x0002 +#define WORK_QUEUE_FLAG_HIGH_FREQ 0x0004 + +/* these flags can be set when queueing a work item to indicate how to handle + its deconstruction */ +#define WORK_ITEM_FLAG_AUTO_RELEASE 0x0001 + +/* osd_work_queue is an opaque type which represents a queue of work items */ +typedef struct _osd_work_queue osd_work_queue; + +/* osd_work_item is an opaque type which represents a single work item */ +typedef struct _osd_work_item osd_work_item; + +/* osd_work_callback is a callback function that does work */ +typedef void *(*osd_work_callback)(void *param, int threadid); + + +/*----------------------------------------------------------------------------- + osd_work_queue_alloc: create a new work queue + + Parameters: + + flags - one or more of the WORK_QUEUE_FLAG_* values ORed together: + + WORK_QUEUE_FLAG_IO - indicates that the work queue will do some + I/O; this may be a useful hint so that threads are created + even on single-processor systems since I/O can often be + overlapped with other work + + WORK_QUEUE_FLAG_MULTI - indicates that the work queue should + take advantage of as many processors as it can; items queued + here are assumed to be fully independent or shared + + WORK_QUEUE_FLAG_HIGH_FREQ - indicates that items are expected + to be queued at high frequency and acted upon quickly; in + general, this implies doing some spin-waiting internally + before falling back to OS-specific synchronization + + Return value: + + A pointer to an allocated osd_work_queue object. + + Notes: + + A work queue abstracts the notion of how potentially threaded work + can be performed. If no threading support is available, it is a + simple matter to execute the work items as they are queued. +-----------------------------------------------------------------------------*/ +osd_work_queue *osd_work_queue_alloc(int flags); + + +/*----------------------------------------------------------------------------- + osd_work_queue_items: return the number of pending items in the queue + + Parameters: + + queue - pointer to an osd_work_queue that was previously created via + osd_work_queue_alloc + + Return value: + + The number of incomplete items remaining in the queue. +-----------------------------------------------------------------------------*/ +int osd_work_queue_items(osd_work_queue *queue); + + +/*----------------------------------------------------------------------------- + osd_work_queue_wait: wait for the queue to be empty + + Parameters: + + queue - pointer to an osd_work_queue that was previously created via + osd_work_queue_alloc + + timeout - a timeout value in osd_ticks_per_second() + + Return value: + + TRUE if the queue is empty; FALSE if the wait timed out before the + queue was emptied. +-----------------------------------------------------------------------------*/ +int osd_work_queue_wait(osd_work_queue *queue, osd_ticks_t timeout); + + +/*----------------------------------------------------------------------------- + osd_work_queue_free: free a work queue, waiting for all items to complete + + Parameters: + + queue - pointer to an osd_work_queue that was previously created via + osd_work_queue_alloc + + Return value: + + None. +-----------------------------------------------------------------------------*/ +void osd_work_queue_free(osd_work_queue *queue); + + +/*----------------------------------------------------------------------------- + osd_work_item_queue_multiple: queue a set of work items + + Parameters: + + queue - pointer to an osd_work_queue that was previously created via + osd_work_queue_alloc + + callback - pointer to a function that will do the work + + numitems - number of work items to queue + + param - a void * parameter that can be used to pass data to the + function + + paramstep - the number of bytes to increment param by for each item + queued; for example, if you have an array of work_unit objects, + you can point param to the base of the array and set paramstep to + sizeof(work_unit) + + flags - one or more of the WORK_ITEM_FLAG_* values ORed together: + + WORK_ITEM_FLAG_AUTO_RELEASE - indicates that the work item + should be automatically freed when it is complete + + Return value: + + A pointer to the final allocated osd_work_item in the list. + + Notes: + + On single-threaded systems, this function may actually execute the + work item immediately before returning. +-----------------------------------------------------------------------------*/ +osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_callback callback, INT32 numitems, void *parambase, INT32 paramstep, UINT32 flags); + + +/* inline helper to queue a single work item using the same interface */ +INLINE osd_work_item *osd_work_item_queue(osd_work_queue *queue, osd_work_callback callback, void *param, UINT32 flags) +{ + return osd_work_item_queue_multiple(queue, callback, 1, param, 0, flags); +} + + +/*----------------------------------------------------------------------------- + osd_work_item_wait: wait for a work item to complete + + Parameters: + + item - pointer to an osd_work_item that was previously returned from + osd_work_item_queue + + timeout - a timeout value in osd_ticks_per_second() + + Return value: + + TRUE if the item completed; FALSE if the wait timed out before the + item completed. +-----------------------------------------------------------------------------*/ +int osd_work_item_wait(osd_work_item *item, osd_ticks_t timeout); + + +/*----------------------------------------------------------------------------- + osd_work_item_result: get the result of a work item + + Parameters: + + item - pointer to an osd_work_item that was previously returned from + osd_work_item_queue + + Return value: + + A void * that represents the work item's result. +-----------------------------------------------------------------------------*/ +void *osd_work_item_result(osd_work_item *item); + + +/*----------------------------------------------------------------------------- + osd_work_item_release: release the memory allocated to a work item + + Parameters: + + item - pointer to an osd_work_item that was previously returned from + osd_work_item_queue + + Return value: + + None. + + Notes: + + The osd_work_item exists until explicitly released, even if it has + long since completed. It is the queuer's responsibility to release + any work items it has queued. +-----------------------------------------------------------------------------*/ +void osd_work_item_release(osd_work_item *item); + + + +/*************************************************************************** + MISCELLANEOUS INTERFACES +***************************************************************************/ + +/*----------------------------------------------------------------------------- + osd_alloc_executable: allocate memory that can contain executable code + + Parameters: + + size - the number of bytes to allocate + + Return value: + + a pointer to the allocated memory + + Notes: + + On many systems, this call may acceptably map to malloc(). On systems + where pages are tagged with "no execute" privileges, it may be + necessary to perform some kind of special allocation to ensure that + code placed into this buffer can be executed. +-----------------------------------------------------------------------------*/ +void *osd_alloc_executable(size_t size); + + +/*----------------------------------------------------------------------------- + osd_free_executable: free memory allocated by osd_alloc_executable + + Parameters: + + ptr - the pointer returned from osd_alloc_executable + + size - the number of bytes originally requested + + Return value: + + None +-----------------------------------------------------------------------------*/ +void osd_free_executable(void *ptr, size_t size); + + +/*----------------------------------------------------------------------------- + osd_is_bad_read_ptr: attempt to determine if the given pointer will + generate an access violation if accessed for read + + Parameters: + + ptr - the pointer to examine + + size - the number of bytes to reference + + Return value: + + TRUE if an access to the referenced memory will generate an access + violation on a read; FALSE otherwise. + + Notes: + + This function will eventually be deprecated. +-----------------------------------------------------------------------------*/ +int osd_is_bad_read_ptr(const void *ptr, size_t size); + + +/*----------------------------------------------------------------------------- + osd_break_into_debugger: break into the hosting system's debugger if one + is attached + + Parameters: + + message - pointer to string to output to the debugger + + Return value: + + None. + + Notes: + + This function is called when an assertion or other important error + occurs. If a debugger is attached to the current process, it should + break into the debugger and display the given message. +-----------------------------------------------------------------------------*/ +void osd_break_into_debugger(const char *message); + + +#endif /* __OSDEPEND_H__ */ diff --git a/TIKI-100_emul-src/messaudio/palette.h b/TIKI-100_emul-src/messaudio/palette.h new file mode 100644 index 0000000..3234e19 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/palette.h @@ -0,0 +1,259 @@ +/****************************************************************************** + + palette.h + + Core palette routines. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __PALETTE_H__ +#define __PALETTE_H__ + +#include "osdcore.h" + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* an rgb_t is a single combined R,G,B (and optionally alpha) value */ +typedef UINT32 rgb_t; + +/* an rgb15_t is a single combined 15-bit R,G,B value */ +typedef UINT16 rgb15_t; + +/* a palette is an opaque, reference counted object */ +typedef struct _palette_t palette_t; + +/* a palette client is someone who is tracking the dirty state of a palette */ +typedef struct _palette_client palette_client; + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +/* macros to assemble rgb_t values */ +#define MAKE_RGB(r,g,b) ((((rgb_t)(r) & 0xff) << 16) | (((rgb_t)(g) & 0xff) << 8) | ((rgb_t)(b) & 0xff)) +#define MAKE_ARGB(a,r,g,b) (MAKE_RGB(r,g,b) | (((rgb_t)(a) & 0xff) << 24)) + +/* macros to extract components from rgb_t values */ +#define RGB_ALPHA(rgb) (((rgb) >> 24) & 0xff) +#define RGB_RED(rgb) (((rgb) >> 16) & 0xff) +#define RGB_GREEN(rgb) (((rgb) >> 8) & 0xff) +#define RGB_BLUE(rgb) ((rgb) & 0xff) + +/* common colors */ +#define RGB_BLACK (MAKE_RGB(0,0,0)) +#define RGB_WHITE (MAKE_RGB(255,255,255)) + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + + +/* ----- palette allocation ----- */ + +/* allocate a new palette object and take a single reference on it */ +palette_t *palette_alloc(UINT32 numcolors, UINT32 numgroups); + +/* reference a palette object, incrementing its reference count */ +void palette_ref(palette_t *palette); + +/* dereference a palette object; if the reference count goes to 0, it is freed */ +void palette_deref(palette_t *palette); + + + +/* ----- palette information ----- */ + +/* return the number of colors managed by the palette */ +int palette_get_num_colors(palette_t *palette); + +/* return the number of groups managed by the palette */ +int palette_get_num_groups(palette_t *palette); + +/* return the index of the black entry */ +UINT32 palette_get_black_entry(palette_t *palette); + +/* return the index of the white entry */ +UINT32 palette_get_white_entry(palette_t *palette); + + + +/* ----- palette clients ----- */ + +/* add a new client to a palette */ +palette_client *palette_client_alloc(palette_t *palette); + +/* remove a client from a palette */ +void palette_client_free(palette_client *client); + +/* return a pointer to the palette for this client */ +palette_t *palette_client_get_palette(palette_client *client); + +/* atomically get the current dirty list for a client */ +const UINT32 *palette_client_get_dirty_list(palette_client *client, UINT32 *mindirty, UINT32 *maxdirty); + + + +/* ----- color management ----- */ + +/* set the raw RGB color for a given palette index */ +void palette_entry_set_color(palette_t *palette, UINT32 index, rgb_t rgb); + +/* return the raw RGB color for a given palette index */ +rgb_t palette_entry_get_color(palette_t *palette, UINT32 index); + +/* return the adjusted RGB color (after all adjustments) for a given palette index */ +rgb_t palette_entry_get_adjusted_color(palette_t *palette, UINT32 index); + +/* return the entire palette as an array of raw RGB values */ +const rgb_t *palette_entry_list_raw(palette_t *palette); + +/* return the entire palette as an array of adjusted RGB values */ +const rgb_t *palette_entry_list_adjusted(palette_t *palette); + +/* return the entire palette as an array of adjusted RGB-15 values */ +const rgb_t *palette_entry_list_adjusted_rgb15(palette_t *palette); + + + +/* ----- palette adjustments ----- */ + +/* set the contrast adjustment for a single palette index */ +void palette_entry_set_contrast(palette_t *palette, UINT32 index, float contrast); + +/* return the contrast adjustment for a single palette index */ +float palette_entry_get_contrast(palette_t *palette, UINT32 index); + +/* configure overall brightness for a palette group */ +void palette_group_set_brightness(palette_t *palette, UINT32 group, float brightness); + +/* configure overall contrast for a palette group */ +void palette_group_set_contrast(palette_t *palette, UINT32 group, float contrast); + + + +/* ----- palette utilities ----- */ + +/* normalize a range of palette entries, mapping minimum brightness to lum_min and maximum + brightness to lum_max; if either value is < 0, that boundary value is not modified */ +void palette_normalize_range(palette_t *palette, UINT32 start, UINT32 end, int lum_min, int lum_max); + + + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +/*------------------------------------------------- + rgb_to_rgb15 - convert an RGB triplet to + a 15-bit OSD-specified RGB value +-------------------------------------------------*/ + +INLINE rgb15_t rgb_to_rgb15(rgb_t rgb) +{ + return ((RGB_RED(rgb) >> 3) << 10) | ((RGB_GREEN(rgb) >> 3) << 5) | ((RGB_BLUE(rgb) >> 3) << 0); +} + + +/*------------------------------------------------- + rgb_clamp - clamp an RGB component to 0-255 +-------------------------------------------------*/ + +INLINE UINT8 rgb_clamp(INT32 value) +{ + if (value < 0) + return 0; + if (value > 255) + return 255; + return value; +} + + +/*------------------------------------------------- + pal1bit - convert a 1-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal1bit(UINT8 bits) +{ + return (bits & 1) ? 0xff : 0x00; +} + + +/*------------------------------------------------- + pal2bit - convert a 2-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal2bit(UINT8 bits) +{ + bits &= 3; + return (bits << 6) | (bits << 4) | (bits << 2) | bits; +} + + +/*------------------------------------------------- + pal3bit - convert a 3-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal3bit(UINT8 bits) +{ + bits &= 7; + return (bits << 5) | (bits << 2) | (bits >> 1); +} + + +/*------------------------------------------------- + pal4bit - convert a 4-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal4bit(UINT8 bits) +{ + bits &= 0xf; + return (bits << 4) | bits; +} + + +/*------------------------------------------------- + pal5bit - convert a 5-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal5bit(UINT8 bits) +{ + bits &= 0x1f; + return (bits << 3) | (bits >> 2); +} + + +/*------------------------------------------------- + pal6bit - convert a 6-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal6bit(UINT8 bits) +{ + bits &= 0x3f; + return (bits << 2) | (bits >> 4); +} + + +/*------------------------------------------------- + pal7bit - convert a 7-bit value to 8 bits +-------------------------------------------------*/ + +INLINE UINT8 pal7bit(UINT8 bits) +{ + bits &= 0x7f; + return (bits << 1) | (bits >> 6); +} + + +#endif /* __PALETTE_H__ */ diff --git a/TIKI-100_emul-src/messaudio/sndintrf.h b/TIKI-100_emul-src/messaudio/sndintrf.h new file mode 100644 index 0000000..14b617b --- /dev/null +++ b/TIKI-100_emul-src/messaudio/sndintrf.h @@ -0,0 +1,298 @@ +/*************************************************************************** + + sndintrf.h + + Core sound interface functions and definitions. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __SNDINTRF_H__ +#define __SNDINTRF_H__ + +//#include "memory.h" +//#include "mame.h" +//#include "state.h" + + +/*************************************************************************** + CONSTANTS +***************************************************************************/ + +#define MAX_SOUND 32 + +/* Enum listing all the sound chips */ +enum _sound_type +{ + SOUND_DUMMY, + SOUND_CUSTOM, + SOUND_SAMPLES, + SOUND_DAC, + SOUND_DMADAC, + SOUND_DISCRETE, + SOUND_AY8910, + SOUND_AY8912, + SOUND_AY8913, + SOUND_AY8930, + SOUND_YM2149, + SOUND_YM3439, + SOUND_YMZ284, + SOUND_YMZ294, + SOUND_YM2203, + SOUND_YM2151, + SOUND_YM2608, + SOUND_YM2610, + SOUND_YM2610B, + SOUND_YM2612, + SOUND_YM3438, + SOUND_YM2413, + SOUND_YM3812, + SOUND_YM3526, + SOUND_YMZ280B, + SOUND_Y8950, + SOUND_SN76477, + SOUND_SN76489, + SOUND_SN76489A, + SOUND_SN76494, + SOUND_SN76496, + SOUND_GAMEGEAR, + SOUND_SMSIII, + SOUND_POKEY, + SOUND_NES, + SOUND_ASTROCADE, + SOUND_NAMCO, + SOUND_NAMCO_15XX, + SOUND_NAMCO_CUS30, + SOUND_NAMCO_52XX, + SOUND_NAMCO_63701X, + SOUND_NAMCONA, + SOUND_TMS36XX, + SOUND_TMS3615, + SOUND_TMS5100, + SOUND_TMS5110, + SOUND_TMS5110A, + SOUND_CD2801, + SOUND_TMC0281, + SOUND_CD2802, + SOUND_M58817, + SOUND_TMC0285, + SOUND_TMS5200, + SOUND_TMS5220, + SOUND_VLM5030, + SOUND_OKIM6295, + SOUND_MSM5205, + SOUND_MSM5232, + SOUND_UPD7759, + SOUND_HC55516, + SOUND_MC3417, + SOUND_MC3418, + SOUND_K005289, + SOUND_K007232, + SOUND_K051649, + SOUND_K053260, + SOUND_K054539, + SOUND_SEGAPCM, + SOUND_RF5C68, + SOUND_CEM3394, + SOUND_C140, + SOUND_QSOUND, + SOUND_SAA1099, + SOUND_IREMGA20, + SOUND_ES5503, + SOUND_ES5505, + SOUND_ES5506, + SOUND_BSMT2000, + SOUND_YMF262, + SOUND_YMF278B, + SOUND_GAELCO_CG1V, + SOUND_GAELCO_GAE1, + SOUND_X1_010, + SOUND_MULTIPCM, + SOUND_C6280, + SOUND_TIA, + SOUND_SP0250, + SOUND_SCSP, + SOUND_PSXSPU, + SOUND_YMF271, + SOUND_CDDA, + SOUND_ICS2115, + SOUND_ST0016, + SOUND_NILE, + SOUND_C352, + SOUND_VRENDER0, + SOUND_VOTRAX, + SOUND_ES8712, + SOUND_RF5C400, + SOUND_SPEAKER, + SOUND_CDP1869, + SOUND_BEEP, + SOUND_WAVE, + SOUND_SID6581, + SOUND_SID8580, + SOUND_SP0256, + SOUND_S14001A, + SOUND_AICA, + + /* filters start here */ + SOUND_FILTER_VOLUME, + SOUND_FILTER_RC, + SOUND_FILTER_LOWPASS, + + SOUND_COUNT +}; +typedef enum _sound_type sound_type; + + +/* Sound information constants */ +enum +{ + /* --- the following bits of info are returned as 64-bit signed integers --- */ + SNDINFO_INT_FIRST = 0x00000, + + SNDINFO_INT_ALIAS = SNDINFO_INT_FIRST, /* R/O: alias to sound type for (type,index) identification */ + + SNDINFO_INT_CORE_SPECIFIC = 0x08000, /* R/W: core-specific values start here */ + + /* --- the following bits of info are returned as pointers to data or functions --- */ + SNDINFO_PTR_FIRST = 0x10000, + + SNDINFO_PTR_SET_INFO = SNDINFO_PTR_FIRST, /* R/O: void (*set_info)(void *token, UINT32 state, sndinfo *info) */ + SNDINFO_PTR_START, /* R/O: void *(*start)(int index, int clock, const void *config) */ + SNDINFO_PTR_STOP, /* R/O: void (*stop)(void *token) */ + SNDINFO_PTR_RESET, /* R/O: void (*reset)(void *token) */ + + SNDINFO_PTR_CORE_SPECIFIC = 0x18000, /* R/W: core-specific values start here */ + + /* --- the following bits of info are returned as NULL-terminated strings --- */ + SNDINFO_STR_FIRST = 0x20000, + + SNDINFO_STR_NAME = SNDINFO_STR_FIRST, /* R/O: name of the sound chip */ + SNDINFO_STR_CORE_FAMILY, /* R/O: family of the sound chip */ + SNDINFO_STR_CORE_VERSION, /* R/O: version of the sound core */ + SNDINFO_STR_CORE_FILE, /* R/O: file containing the sound core */ + SNDINFO_STR_CORE_CREDITS, /* R/O: credits for the sound core */ + + SNDINFO_STR_CORE_SPECIFIC = 0x28000 /* R/W: core-specific values start here */ +}; + + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +typedef union _sndinfo sndinfo; +union _sndinfo +{ + INT64 i; /* generic integers */ + void * p; /* generic pointers */ + genf * f; /* generic function pointers */ + const char *s; /* generic strings */ + + void (*set_info)(void *token, UINT32 state, sndinfo *info); + void * (*start)(int index, int clock, const void *config);/* SNDINFO_PTR_START */ + void (*stop)(void *token); /* SNDINFO_PTR_STOP */ + void (*reset)(void *token); /* SNDINFO_PTR_RESET */ +}; + + + +/*************************************************************************** + CHIP INTERFACES BY INDEX +***************************************************************************/ + +/* get info accessors */ +INT64 sndnum_get_info_int(int sndnum, UINT32 state); +void *sndnum_get_info_ptr(int sndnum, UINT32 state); +genf *sndnum_get_info_fct(int sndnum, UINT32 state); +const char *sndnum_get_info_string(int sndnum, UINT32 state); + +/* set info accessors */ +void sndnum_set_info_int(int sndnum, UINT32 state, INT64 data); +void sndnum_set_info_ptr(int sndnum, UINT32 state, void *data); +void sndnum_set_info_fct(int sndnum, UINT32 state, genf *data); + +#define sndnum_name(sndnum) sndnum_get_info_string(sndnum, SNDINFO_STR_NAME) +#define sndnum_core_family(sndnum) sndnum_get_info_string(sndnum, SNDINFO_STR_CORE_FAMILY) +#define sndnum_core_version(sndnum) sndnum_get_info_string(sndnum, SNDINFO_STR_CORE_VERSION) +#define sndnum_core_file(sndnum) sndnum_get_info_string(sndnum, SNDINFO_STR_CORE_FILE) +#define sndnum_core_credits(sndnum) sndnum_get_info_string(sndnum, SNDINFO_STR_CORE_CREDITS) + +/* misc accessors */ +void sndnum_reset(int sndnum); +int sndnum_clock(int sndnum); +void *sndnum_token(int sndnum); + + + +/*************************************************************************** + CHIP INTERFACES BY (TYPE,INDEX) PAIR +***************************************************************************/ + +/* get info accessors */ +INT64 sndti_get_info_int(sound_type sndtype, int sndindex, UINT32 state); +void *sndti_get_info_ptr(sound_type sndtype, int sndindex, UINT32 state); +genf *sndti_get_info_fct(sound_type sndtype, int sndindex, UINT32 state); +const char *sndti_get_info_string(sound_type sndtype, int sndindex, UINT32 state); + +/* set info accessors */ +void sndti_set_info_int(sound_type sndtype, int sndindex, UINT32 state, INT64 data); +void sndti_set_info_ptr(sound_type sndtype, int sndindex, UINT32 state, void *data); +void sndti_set_info_fct(sound_type sndtype, int sndindex, UINT32 state, genf *data); + +#define sndti_name(sndtype, sndindex) sndti_get_info_string(sndtype, sndindex, SNDINFO_STR_NAME) +#define sndti_core_family(sndtype, sndindex) sndti_get_info_string(sndtype, sndindex, SNDINFO_STR_CORE_FAMILY) +#define sndti_core_version(sndtype, sndindex) sndti_get_info_string(sndtype, sndindex, SNDINFO_STR_CORE_VERSION) +#define sndti_core_file(sndtype, sndindex) sndti_get_info_string(sndtype, sndindex, SNDINFO_STR_CORE_FILE) +#define sndti_core_credits(sndtype, sndindex) sndti_get_info_string(sndtype, sndindex, SNDINFO_STR_CORE_CREDITS) + +/* misc accessors */ +void sndti_reset(sound_type sndtype, int sndindex); +int sndti_clock(sound_type sndtype, int sndindex); +void *sndti_token(sound_type sndtype, int sndindex); + +/* driver gain controls on chip outputs */ +void sndti_set_output_gain(sound_type sndtype, int sndindex, int output, float gain); + + + +/*************************************************************************** + CHIP INTERFACES BY TYPE +***************************************************************************/ + +/* get info accessors */ +INT64 sndtype_get_info_int(sound_type sndtype, UINT32 state); +void *sndtype_get_info_ptr(sound_type sndtype, UINT32 state); +genf *sndtype_get_info_fct(sound_type sndtype, UINT32 state); +const char *sndtype_get_info_string(sound_type sndtype, UINT32 state); + +#define sndtype_name(sndtype) sndtype_get_info_string(sndtype, SNDINFO_STR_NAME) +#define sndtype_core_family(sndtype) sndtype_get_info_string(sndtype, SNDINFO_STR_CORE_FAMILY) +#define sndtype_core_version(sndtype) sndtype_get_info_string(sndtype, SNDINFO_STR_CORE_VERSION) +#define sndtype_core_file(sndtype) sndtype_get_info_string(sndtype, SNDINFO_STR_CORE_FILE) +#define sndtype_core_credits(sndtype) sndtype_get_info_string(sndtype, SNDINFO_STR_CORE_CREDITS) + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + +/* Initialization/Tear down */ +void sndintrf_init(running_machine *machine); +int sndintrf_init_sound(int sndnum, sound_type sndtype, int clock, const void *config); +void sndintrf_exit_sound(int sndnum); +void sndintrf_register_token(void *token); + +/* Misc helpers */ +int sndti_exists(sound_type sndtype, int sndindex); +int sndti_to_sndnum(sound_type type, int index); +sound_type sndnum_to_sndti(int sndnum, int *index); +int sndtype_count(sound_type sndtype); + + +#endif /* __SNDINTRF_H__ */ diff --git a/TIKI-100_emul-src/messaudio/streams.h b/TIKI-100_emul-src/messaudio/streams.h new file mode 100644 index 0000000..8f72bdd --- /dev/null +++ b/TIKI-100_emul-src/messaudio/streams.h @@ -0,0 +1,96 @@ +/*************************************************************************** + + streams.h + + Handle general purpose audio streams + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#ifndef STREAMS_H +#define STREAMS_H + +#include "mamecore.h" + + +/*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +typedef struct _sound_stream sound_stream; + +typedef void (*stream_update_func)(void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + + + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + + +/* ----- system-level management ----- */ + +/* initialize the streams engine */ +void streams_init(running_machine *machine, attoseconds_t update_subseconds); + +/* set the tag to be associated with all streams allocated from now on */ +void streams_set_tag(running_machine *machine, void *streamtag); + +/* update all the streams periodically */ +void streams_update(running_machine *machine); + + + +/* ----- stream configuration and setup ----- */ + +/* create a new stream */ +sound_stream *stream_create(int inputs, int outputs, int sample_rate, void *param, stream_update_func callback); + +/* configure a stream's input */ +void stream_set_input(sound_stream *stream, int index, sound_stream *input_stream, int output_index, float gain); + +/* force a stream to update to the current emulated time */ +void stream_update(sound_stream *stream); + +/* return a pointer to the output buffer and the number of samples since the last global update */ +const stream_sample_t *stream_get_output_since_last_update(sound_stream *stream, int outputnum, int *numsamples); + + + +/* ----- stream timing ----- */ + +/* return the currently set sample rate on a given stream */ +int stream_get_sample_rate(sound_stream *stream); + +/* set the sample rate on a given stream */ +void stream_set_sample_rate(sound_stream *stream, int sample_rate); + +/* return the emulation time of the next sample to be generated on the stream */ +attotime stream_get_time(sound_stream *stream); + +/* return the duration of a single sample for a stream */ +attotime stream_get_sample_period(sound_stream *stream); + + + +/* ----- stream information and control ----- */ + +/* find a stream using a tag and index */ +sound_stream *stream_find_by_tag(void *streamtag, int streamindex); + +/* return the number of inputs for a given stream */ +int stream_get_inputs(sound_stream *stream); + +/* return the number of outputs for a given stream */ +int stream_get_outputs(sound_stream *stream); + +/* set the input gain on a given stream */ +void stream_set_input_gain(sound_stream *stream, int input, float gain); + +/* set the output gain on a given stream */ +void stream_set_output_gain(sound_stream *stream, int output, float gain); + + +#endif diff --git a/TIKI-100_emul-src/messaudio/tokenize.h b/TIKI-100_emul-src/messaudio/tokenize.h new file mode 100644 index 0000000..aaff8a6 --- /dev/null +++ b/TIKI-100_emul-src/messaudio/tokenize.h @@ -0,0 +1,245 @@ +/*************************************************************************** + + tokenize.h + + Common definitions and macros for tokenizing definitions. + + Copyright Nicola Salmoria and the MAME Team. + Visit http://mamedev.org for licensing and usage restrictions. + +***************************************************************************/ + +#pragma once + +#ifndef __TOKENIZE_H__ +#define __TOKENIZE_H__ + + +/*************************************************************************** + CONSTANTS +***************************************************************************/ + +/* tokens per item */ +#define TOKENS_PER_PTR (1) +#define TOKENS_PER_UINT32 (1) +#define TOKENS_PER_UINT64 (8 / sizeof(FPTR)) +#define TOKENS_PER_ATTOTIME (TOKENS_PER_UINT32 + TOKENS_PER_UINT64) + + + +/*************************************************************************** + MACROS +***************************************************************************/ + +/* include this at the top of your union to get the standard fields */ +#define TOKEN_COMMON_FIELDS \ + FPTR i; \ + const char * stringptr; \ + const void * voidptr; \ + const UINT8 * ui8ptr; \ + const INT8 * i8ptr; \ + const UINT16 * ui16ptr; \ + const INT16 * i16ptr; \ + const UINT32 * ui32ptr; \ + const INT32 * i32ptr; \ + const UINT64 * ui64ptr; \ + const INT64 * i64ptr; \ + + +/* ----- compile-time token generation macros ----- */ + +/* GCC and C99 compilers can use designated initializers for type safety */ +#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(_STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) +#define TOKEN_VALUE(field,a) { .field = (a) } +#else +#define TOKEN_VALUE(field,a) { (FPTR)(a) } +#endif + +/* token output primitives */ +/* note that regardless of the endianness, UINT64s are packed LSW first */ +#define TOKEN_PTR(field,p) TOKEN_VALUE(field, p) +#define TOKEN_STRING(p) TOKEN_VALUE(stringptr, p) +#define TOKEN_UINT32(a) TOKEN_VALUE(i, a) +#ifdef PTR64 +#define TOKEN_UINT64(a) TOKEN_VALUE(i, a) +#else +#define TOKEN_UINT64(a) TOKEN_VALUE(i, (UINT32)(a)), TOKEN_VALUE(i, (UINT32)((a) >> 32)) +#endif + +/* mask a value to a fixed number of bits and then shift it */ +#define SHIFT_AND_MASK32(val, bits, shift) (((UINT32)(val) & ((1 << (bits)) - 1)) << (shift)) +#define SHIFT_AND_MASK64(val, bits, shift) (((UINT64)(val) & (((UINT64)1 << (bits)) - 1)) << (shift)) + +/* 32-bit integer packing */ +#define TOKEN_UINT32_PACK1(val1, bits1) \ + TOKEN_UINT32(SHIFT_AND_MASK32((val1), (bits1), 0)) + +#define TOKEN_UINT32_PACK2(val1, bits1, val2, bits2) \ + TOKEN_UINT32(SHIFT_AND_MASK32((val1), (bits1), 0) | \ + SHIFT_AND_MASK32((val2), (bits2), (bits1))) + +#define TOKEN_UINT32_PACK3(val1, bits1, val2, bits2, val3, bits3) \ + TOKEN_UINT32(SHIFT_AND_MASK32((val1), (bits1), 0) | \ + SHIFT_AND_MASK32((val2), (bits2), (bits1)) | \ + SHIFT_AND_MASK32((val3), (bits3), (bits1)+(bits2))) + +#define TOKEN_UINT32_PACK4(val1, bits1, val2, bits2, val3, bits3, val4, bits4) \ + TOKEN_UINT32(SHIFT_AND_MASK32((val1), (bits1), 0) | \ + SHIFT_AND_MASK32((val2), (bits2), (bits1)) | \ + SHIFT_AND_MASK32((val3), (bits3), (bits1)+(bits2)) | \ + SHIFT_AND_MASK32((val4), (bits4), (bits1)+(bits2)+(bits3))) + +/* 64-bit integer packing */ +#define TOKEN_UINT64_PACK1(val1, bits1) \ + TOKEN_UINT64(SHIFT_AND_MASK64((val1), (bits1), 0)) + +#define TOKEN_UINT64_PACK2(val1, bits1, val2, bits2) \ + TOKEN_UINT64(SHIFT_AND_MASK64((val1), (bits1), 0) | \ + SHIFT_AND_MASK64((val2), (bits2), (bits1))) + +#define TOKEN_UINT64_PACK3(val1, bits1, val2, bits2, val3, bits3) \ + TOKEN_UINT64(SHIFT_AND_MASK64((val1), (bits1), 0) | \ + SHIFT_AND_MASK64((val2), (bits2), (bits1)) | \ + SHIFT_AND_MASK64((val3), (bits3), (bits1)+(bits2))) + +#define TOKEN_UINT64_PACK4(val1, bits1, val2, bits2, val3, bits3, val4, bits4) \ + TOKEN_UINT64(SHIFT_AND_MASK64((val1), (bits1), 0) | \ + SHIFT_AND_MASK64((val2), (bits2), (bits1)) | \ + SHIFT_AND_MASK64((val3), (bits3), (bits1)+(bits2)) | \ + SHIFT_AND_MASK64((val4), (bits4), (bits1)+(bits2)+(bits3))) + + + +/* ----- run-time token extraction macros ----- */ + +/* token fetch and advance primitives */ +#define TOKEN_GET_PTR(tp,field) (((tp)++)->field) +#define TOKEN_GET_STRING(tp) (((tp)++)->stringptr) +#define TOKEN_GET_UINT32(tp) (((tp)++)->i) +#ifdef PTR64 +#define TOKEN_EXTRACT_UINT64(tp,a) do { (a) = (tp)->i; (tp)++; } while (0) +#else +#define TOKEN_EXTRACT_UINT64(tp,a) do { (a) = (tp)[0].i | ((UINT64)(tp)[1].i << 32); (tp) += 2; } while (0) +#endif + +/* token unfetch primitives */ +#define TOKEN_UNGET_PTR(tp) ((tp)--) +#define TOKEN_UNGET_STRING(tp) ((tp)--) +#define TOKEN_UNGET_UINT32(tp) ((tp)--) +#define TOKEN_UNGET_UINT64(tp) ((tp) -= 8 / sizeof(FPTR)) + +/* token skip primitives */ +#define TOKEN_SKIP_PTR(tp) ((tp)++) +#define TOKEN_SKIP_STRING(tp) ((tp)++) +#define TOKEN_SKIP_UINT32(tp) ((tp)++) +#define TOKEN_SKIP_UINT64(tp) ((tp) += 8 / sizeof(FPTR)) + +/* extract a value from a fixed number of bits; if bits is negative, treat it as a signed value */ +#define UNSHIFT_AND_MASK32(src, val, bits, shift) do { \ + if ((bits) < 0) \ + (val) = token_sign_extend32((src) >> (shift), -(bits)); \ + else \ + (val) = token_zero_extend32((src) >> (shift), (bits)); \ +} while (0) + +#define UNSHIFT_AND_MASK64(src, val, bits, shift) do { \ + if ((bits) < 0) \ + (val) = token_sign_extend64((src) >> (shift), -(bits)); \ + else \ + (val) = token_zero_extend64((src) >> (shift), (bits)); \ +} while (0) + +/* cheesy inline absolute value */ +#define TOKENABS(v) (((v) < 0) ? -(v) : (v)) + +/* 32-bit integer unpacking */ +#define TOKEN_GET_UINT32_UNPACK1(tp, val1, bits1) do { \ + UINT32 token32 = TOKEN_GET_UINT32(tp); \ + UNSHIFT_AND_MASK32(token32, val1, (bits1), 0); \ +} while (0) + +#define TOKEN_GET_UINT32_UNPACK2(tp, val1, bits1, val2, bits2) do { \ + UINT32 token32 = TOKEN_GET_UINT32(tp); \ + UINT8 shift = 0; \ + UNSHIFT_AND_MASK32(token32, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK32(token32, val2, (bits2), shift); \ +} while (0) + +#define TOKEN_GET_UINT32_UNPACK3(tp, val1, bits1, val2, bits2, val3, bits3) do { \ + UINT32 token32 = TOKEN_GET_UINT32(tp); \ + UINT8 shift = 0; \ + UNSHIFT_AND_MASK32(token32, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK32(token32, val2, (bits2), shift); shift += TOKENABS(bits2); \ + UNSHIFT_AND_MASK32(token32, val3, (bits3), shift); \ +} while (0) + +#define TOKEN_GET_UINT32_UNPACK4(tp, val1, bits1, val2, bits2, val3, bits3, val4, bits4) do { \ + UINT32 token32 = TOKEN_GET_UINT32(tp); \ + UINT8 shift = 0; \ + UNSHIFT_AND_MASK32(token32, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK32(token32, val2, (bits2), shift); shift += TOKENABS(bits2); \ + UNSHIFT_AND_MASK32(token32, val3, (bits3), shift); shift += TOKENABS(bits3); \ + UNSHIFT_AND_MASK32(token32, val4, (bits4), shift); \ +} while (0) + +/* 64-bit integer unpacking */ +#define TOKEN_GET_UINT64_UNPACK1(tp, val1, bits1) do { \ + UINT64 token64; \ + TOKEN_EXTRACT_UINT64(tp, token64); \ + UNSHIFT_AND_MASK64(token64, val1, (bits1), 0); \ +} while (0) + +#define TOKEN_GET_UINT64_UNPACK2(tp, val1, bits1, val2, bits2) do { \ + UINT64 token64; \ + UINT8 shift = 0; \ + TOKEN_EXTRACT_UINT64(tp, token64); \ + UNSHIFT_AND_MASK64(token64, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK64(token64, val2, (bits2), shift); \ +} while (0) + +#define TOKEN_GET_UINT64_UNPACK3(tp, val1, bits1, val2, bits2, val3, bits3) do { \ + UINT64 token64; \ + UINT8 shift = 0; \ + TOKEN_EXTRACT_UINT64(tp, token64); \ + UNSHIFT_AND_MASK64(token64, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK64(token64, val2, (bits2), shift); shift += TOKENABS(bits2); \ + UNSHIFT_AND_MASK64(token64, val3, (bits3), shift); \ +} while (0) + +#define TOKEN_GET_UINT64_UNPACK4(tp, val1, bits1, val2, bits2, val3, bits3, val4, bits4) do { \ + UINT64 token64; \ + UINT8 shift = 0; \ + TOKEN_EXTRACT_UINT64(tp, token64); \ + UNSHIFT_AND_MASK64(token64, val1, (bits1), shift); shift += TOKENABS(bits1); \ + UNSHIFT_AND_MASK64(token64, val2, (bits2), shift); shift += TOKENABS(bits2); \ + UNSHIFT_AND_MASK64(token64, val3, (bits3), shift); shift += TOKENABS(bits3); \ + UNSHIFT_AND_MASK64(token64, val4, (bits4), shift); \ +} while (0) + + + +/*************************************************************************** + INLINE FUNCTIONS +***************************************************************************/ + +INLINE UINT32 token_zero_extend32(UINT32 val, UINT8 bits) +{ + return val & (((UINT32)1 << bits) - 1); +} + +INLINE INT32 token_sign_extend32(UINT32 val, UINT8 bits) +{ + return (INT32)(val << (32 - bits)) >> (32 - bits); +} + +INLINE UINT64 token_zero_extend64(UINT64 val, UINT8 bits) +{ + return val & (((UINT64)1 << bits) - 1); +} + +INLINE INT64 token_sign_extend64(UINT64 val, UINT8 bits) +{ + return (INT64)(val << (64 - bits)) >> (64 - bits); +} + +#endif