Projects/tigris
Projects
/
tigris
Archived
5
0
Fork 0

Vi har lekt. Og kanskje kommet litt lengre.

This commit is contained in:
Jens ]dne Rydland 2008-09-02 20:35:06 +00:00
parent 3d6d7458a0
commit a0f4554285
17 changed files with 4912 additions and 5 deletions

View File

@ -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"
/*************************************

View File

@ -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

View File

@ -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__ */

View File

@ -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 <stdarg.h>
#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__ */

View File

@ -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 <string.h>
/***************************************************************************
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__ */

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#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__ */

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#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__ */

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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

View File

@ -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