示例#1
0
struct drccore *drc_init(UINT8 cpunum, struct drcconfig *config)
{
	int address_bits = config->address_bits;
	int effective_address_bits = address_bits - config->lsbs_to_ignore;
	struct drccore *drc;

	/* allocate memory */
	drc = osd_malloc(sizeof(*drc));
	if (!drc)
		return NULL;
	memset(drc, 0, sizeof(*drc));

	/* copy in relevant data from the config */
	drc->pcptr        = config->pcptr;
	drc->icountptr    = config->icountptr;
	drc->esiptr       = config->esiptr;
	drc->cb_reset     = config->cb_reset;
	drc->cb_recompile = config->cb_recompile;
	drc->cb_entrygen  = config->cb_entrygen;
	drc->uses_fp      = config->uses_fp;
	drc->uses_sse     = config->uses_sse;
	drc->pc_in_memory = config->pc_in_memory;
	drc->icount_in_memory = config->icount_in_memory;
	drc->fpcw_curr    = fp_control[0];
	drc->mxcsr_curr   = sse_control[0];

	/* allocate cache */
	drc->cache_base = osd_alloc_executable(config->cache_size);
	if (!drc->cache_base)
		return NULL;
	drc->cache_end = drc->cache_base + config->cache_size;
	drc->cache_danger = drc->cache_end - 65536;

	/* compute shifts and masks */
	drc->l1bits = effective_address_bits/2;
	drc->l2bits = effective_address_bits - drc->l1bits;
	drc->l1shift = config->lsbs_to_ignore + drc->l2bits;
	drc->l2mask = ((1 << drc->l2bits) - 1) << config->lsbs_to_ignore;
	drc->l2scale = 4 >> config->lsbs_to_ignore;

	/* allocate lookup tables */
	drc->lookup_l1 = osd_malloc(sizeof(*drc->lookup_l1) * (1 << drc->l1bits));
	drc->lookup_l2_recompile = osd_malloc(sizeof(*drc->lookup_l2_recompile) * (1 << drc->l2bits));
	if (!drc->lookup_l1 || !drc->lookup_l2_recompile)
		return NULL;
	memset(drc->lookup_l1, 0, sizeof(*drc->lookup_l1) * (1 << drc->l1bits));
	memset(drc->lookup_l2_recompile, 0, sizeof(*drc->lookup_l2_recompile) * (1 << drc->l2bits));

	/* allocate the sequence and tentative lists */
	drc->sequence_count_max = config->max_instructions;
	drc->sequence_list = osd_malloc(drc->sequence_count_max * sizeof(*drc->sequence_list));
	drc->tentative_count_max = config->max_instructions;
	drc->tentative_list = osd_malloc(drc->tentative_count_max * sizeof(*drc->tentative_list));
	if (!drc->sequence_list || !drc->tentative_list)
		return NULL;

	/* seed the cache */
	drc_cache_reset(drc);
	return drc;
}
示例#2
0
int tms36xx_sh_start(const struct MachineSound *msound)
{
	int i, j;
	intf = msound->sound_interface;

	for( i = 0; i < intf->num; i++ )
	{
		int enable;
		struct TMS36XX *tms;
		char name[16];

		if (intf->subtype[i] == MM6221AA)
			sprintf(name, "MM6221AA #%d", i);
		else
			sprintf(name, "TMS36%02d #%d", intf->subtype[i], i);
		tms36xx[i] = osd_malloc(sizeof(struct TMS36XX));
		if( !tms36xx[i] )
		{
			logerror("%s failed to malloc struct TMS36XX\n", name);
            return 1;
        }
		tms = tms36xx[i];
		memset(tms, 0, sizeof(struct TMS36XX));

		tms->subtype = osd_malloc(strlen(name) + 1);
		strcpy(tms->subtype, name);
        tms->channel = stream_init(name, intf->mixing_level[i], Machine->sample_rate, i, tms36xx_sound_update);

        if( tms->channel == -1 )
		{
			logerror("%s stream_init failed\n", name);
			return 1;
		}
		tms->samplerate = Machine->sample_rate ? Machine->sample_rate : 1;
		tms->basefreq = intf->basefreq[i];
		enable = 0;
        for (j = 0; j < 6; j++)
		{
			if( intf->decay[i][j] > 0 )
			{
				tms->decay[j+0] = tms->decay[j+6] = VMAX / intf->decay[i][j];
				enable |= 0x41 << j;
			}
		}
		tms->speed = (intf->speed[i] > 0) ? VMAX / intf->speed[i] : VMAX;
		tms3617_enable_w(i,enable);

        LOG(("%s samplerate    %d\n", name, tms->samplerate));
		LOG(("%s basefreq      %d\n", name, tms->basefreq));
		LOG(("%s decay         %d,%d,%d,%d,%d,%d\n", name,
			tms->decay[0], tms->decay[1], tms->decay[2],
			tms->decay[3], tms->decay[4], tms->decay[5]));
        LOG(("%s speed         %d\n", name, tms->speed));
    }
    return 0;
}
示例#3
0
文件: afega.c 项目: joolswills/mameox
MACHINE_DRIVER_END

/***************************************************************************


								ROMs Loading


***************************************************************************/

/* Address lines scrambling */

static void decryptcode( int a23, int a22, int a21, int a20, int a19, int a18, int a17, int a16, int a15, int a14, int a13, int a12,
	int a11, int a10, int a9, int a8, int a7, int a6, int a5, int a4, int a3, int a2, int a1, int a0 )
{
	int i;
	data8_t *RAM = memory_region( REGION_CPU1 );
	size_t  size = memory_region_length( REGION_CPU1 );
	data8_t *buffer = osd_malloc( size );

	if( buffer )
	{
		memcpy( buffer, RAM, size );
		for( i = 0; i < size; i++ )
		{
			RAM[ i ] = buffer[ BITSWAP24( i, a23, a22, a21, a20, a19, a18, a17, a16, a15, a14, a13, a12,
				a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0 ) ];
		}
		free( buffer );
	}
}
示例#4
0
文件: nltool.c 项目: ef1105/mameplus
void *malloc_file_line(size_t size, const char *file, int line)
{
	// allocate the memory and fail if we can't
	void *ret = osd_malloc(size);
	memset(ret, 0, size);
	return ret;
}
示例#5
0
void *malloc_or_die_file_line(size_t size, const char *file, int line)
{
	void *result;

	/* fail on attempted allocations of 0 */
	if (size == 0)
		fatalerror("Attempted to malloc zero bytes (%s:%d)", file, line);

	/* allocate and return if we succeeded */
#ifdef MALLOC_DEBUG
	result = malloc_file_line(size, file, line);
#elif _PS3_
	result = osd_malloc(size);
#else
	result = malloc(size);
#endif
	if (result != NULL)
	{
#ifdef MAME_DEBUG
		rand_memory(result, size);
#endif
		return result;
	}

	/* otherwise, die horribly */
	fatalerror("Failed to allocate %d bytes (%s:%d)", (int)size, file, line);
}
示例#6
0
osd_lock *osd_lock_alloc(void)
{
    pthread_mutexattr_t mutexattr;

    if (pthread_mutexattr_init(&mutexattr) ||
        pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE))
    {
        return NULL;
    }

    pthread_mutex_t *ret = (pthread_mutex_t *) 
        osd_malloc(sizeof(pthread_mutex_t));

    if (ret == NULL)
    {
        return NULL;
    }

    if (pthread_mutex_init(ret, &mutexattr))
    {
        osd_free(ret);
        return NULL;
    }

    return (osd_lock *) ret;
}
示例#7
0
void wav_add_data_32(wav_file *wav, INT32 *data, int samples, int shift)
{
	INT16 *temp;
	int i;

	if (!wav) return;

	/* allocate temp memory */
	temp = (INT16 *)osd_malloc(samples * sizeof(temp[0]));
	if (!temp)
		return;

	/* clamp */
	for (i = 0; i < samples; i++)
	{
		int val = data[i] >> shift;
		temp[i] = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
	}

	/* write and flush */
	fwrite(temp, 2, samples, wav->file);
	fflush(wav->file);

	/* free memory */
	osd_free(temp);
}
示例#8
0
int stream_init_multi(int channels,const char **names,const int *default_mixing_levels,
		int sample_rate,
		int param,void (*callback)(int param,INT16 **buffer,int length))
{
	int channel,i;


	channel = mixer_allocate_channels(channels,default_mixing_levels);

	stream_joined_channels[channel] = channels;

	for (i = 0;i < channels;i++)
	{
		mixer_set_name(channel+i,names[i]);

		if ((stream_buffer[channel+i] = osd_malloc(sizeof(INT16)*BUFFER_LEN)) == 0)
			return -1;

		stream_sample_rate[channel+i] = sample_rate;
		stream_buffer_pos[channel+i] = 0;
		if (sample_rate)
			stream_sample_length[channel+i] = 1000000 / sample_rate;
		else
			stream_sample_length[channel+i] = 0;
	}

	stream_param[channel] = param;
	stream_callback_multi[channel] = callback;
	set_RC_filter(channel,0,0,0,0);

	return channel;
}
示例#9
0
void *malloc_file_line(size_t size, const char *file, int line, bool array, bool throw_on_fail, bool clear)
{
	// allocate the memory and fail if we can't
	void *result = array ? osd_malloc_array(size) : osd_malloc(size);
	if (result == nullptr)
	{
		fprintf(stderr, "Failed to allocate %d bytes (%s:%d)\n", UINT32(size), file, line);
		osd_break_into_debugger("Failed to allocate RAM");
		if (throw_on_fail)
			throw std::bad_alloc();
		return nullptr;
	}

	// zap the memory if requested
	if (clear)
		memset(result, 0, size);
	else
	{
#if !__has_feature(memory_sanitizer) && defined(INITIALIZE_ALLOCATED_MEMORY) && !defined(MAME_DEBUG_FAST)
		memset(result, 0xdd, size);
#endif
	}

	// add a new entry
	memory_entry::allocate(size, result, file, line, array);

	return result;
}
示例#10
0
int stream_init(const char *name,int default_mixing_level,
		int sample_rate,
		int param,void (*callback)(int param,INT16 *buffer,int length))
{
	int channel;


	channel = mixer_allocate_channel(default_mixing_level);

	stream_joined_channels[channel] = 1;

	mixer_set_name(channel,name);

	if ((stream_buffer[channel] = osd_malloc(sizeof(INT16)*BUFFER_LEN)) == 0)
		return -1;

	stream_sample_rate[channel] = sample_rate;
	stream_buffer_pos[channel] = 0;
	if (sample_rate)
		stream_sample_length[channel] = 1000000 / sample_rate;
	else
		stream_sample_length[channel] = 0;
	stream_param[channel] = param;
	stream_callback[channel] = callback;
	set_RC_filter(channel,0,0,0,0);

	return channel;
}
示例#11
0
文件: textbuf.c 项目: Ilgrim/MAMEHub
text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines)
{
	text_buffer *text;

	/* allocate memory for the text buffer object */
	text = (text_buffer *)osd_malloc(sizeof(*text));
	if (!text)
		return NULL;

	/* allocate memory for the buffer itself */
	text->buffer = (char *)osd_malloc_array(bytes);
	if (!text->buffer)
	{
		osd_free(text);
		return NULL;
	}

	/* allocate memory for the lines array */
	text->lineoffs = (INT32 *)osd_malloc_array(lines * sizeof(text->lineoffs[0]));
	if (!text->lineoffs)
	{
		osd_free(text->buffer);
		osd_free(text);
		return NULL;
	}

	/* initialize the buffer description */
	text->bufsize = bytes;
	text->linesize = lines;
	text_buffer_clear(text);

	return text;
}
示例#12
0
static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t size)
{
	int fd;
	osd_shared_mem *os_shmem = (osd_shared_mem *) osd_malloc(sizeof(osd_shared_mem));

	if (create)
	{
		char *buf = (char *) osd_malloc_array(size);
		memset(buf,0, size);

		fd = open(path, O_RDWR | O_CREAT, S_IRWXU);
		write(fd, buf, size);
		os_shmem->creator = 1;
	}
	else
	{
		fd = open(path, O_RDWR);
		if (fd == -1)
		{
			osd_free(os_shmem);
			return NULL;
		}
		os_shmem->creator = 0;
	}
	os_shmem->fn = (char *) osd_malloc_array(strlen(path)+1);
	strcpy(os_shmem->fn, path);

	assert(fd != -1);

	os_shmem->ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	os_shmem->size = size;
	close(fd);
	return os_shmem;
}
示例#13
0
static inline void execute_sync(osd_work_callback callback, const worker_param &wp)
{
	worker_param *wp_temp = (worker_param *) osd_malloc(sizeof(worker_param));
	*wp_temp = wp;

	callback((void *) wp_temp, 0);
}
示例#14
0
file_error osd_get_full_path(char **dst, const char *path)
{
	file_error err;
	char path_buffer[512];

	err = FILERR_NONE;

	if (getcwd(path_buffer, 511) == NULL)
	{
		printf("osd_get_full_path: failed!\n");
		err = FILERR_FAILURE;
	}
	else
	{
		*dst = (char *)osd_malloc(strlen(path_buffer)+strlen(path)+3);

		// if it's already a full path, just pass it through
		if (path[0] == '/')
		{
			strcpy(*dst, path);
		}
		else
		{
			sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
		}
	}

	return err;
}
示例#15
0
osd_directory_entry *osd_stat(const char *path)
{
	int err;
	osd_directory_entry *result = NULL;
	#if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
	struct stat st;
	#else
	struct stat64 st;
	#endif

	#if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
	err = stat(path, &st);
	#else
	err = stat64(path, &st);
	#endif

	if( err == -1) return NULL;

	// create an osd_directory_entry; be sure to make sure that the caller can
	// free all resources by just freeing the resulting osd_directory_entry
	result = (osd_directory_entry *) osd_malloc(sizeof(*result) + strlen(path) + 1);
	strcpy(((char *) result) + sizeof(*result), path);
	result->name = ((char *) result) + sizeof(*result);
	result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
	result->size = (UINT64)st.st_size;

	return result;
}
示例#16
0
static void hs_save (void)
{
	mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 1);
	LOG(("hs_save\n"));
	if (f)
	{
		struct mem_range *mem_range = state.mem_range;
		LOG(("saving...\n"));
		while (mem_range)
		{
			UINT8 *data = osd_malloc (mem_range->num_bytes);
			if (data)
			{
				/*	this buffer will almost certainly be small
					enough to be dynamically allocated, but let's
					avoid memory trashing just in case
				*/
				copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				mame_fwrite(f, data, mem_range->num_bytes);
			}
			mem_range = mem_range->next;
		}
		mame_fclose(f);
	}
}
示例#17
0
static void hs_load (void)
{
	mame_file *f = mame_fopen (Machine->gamedrv->name, 0, FILETYPE_HIGHSCORE, 0);
	state.hiscores_have_been_loaded = 1;
	LOG(("hs_load\n"));
	if (f)
	{
		struct mem_range *mem_range = state.mem_range;
		LOG(("loading...\n"));
		while (mem_range)
		{
			UINT8 *data = osd_malloc (mem_range->num_bytes);
			if (data)
			{
				/*	this buffer will almost certainly be small
					enough to be dynamically allocated, but let's
					avoid memory trashing just in case
				*/
				mame_fread (f, data, mem_range->num_bytes);
				copy_to_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				free (data);
			}
			mem_range = mem_range->next;
		}
		mame_fclose (f);
	}
}
示例#18
0
void wav_add_data_32lr(wav_file *wav, INT32 *left, INT32 *right, int samples, int shift)
{
	INT16 *temp;
	int i;

	if (!wav) return;

	/* allocate temp memory */
	temp = (INT16 *)osd_malloc(samples * 2 * sizeof(temp[0]));
	if (!temp)
		return;

	/* interleave */
	for (i = 0; i < samples * 2; i++)
	{
		int val = (i & 1) ? right[i / 2] : left[i / 2];
		val >>= shift;
		temp[i] = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
	}

	/* write and flush */
	fwrite(temp, 4, samples, wav->file);
	fflush(wav->file);

	/* free memory */
	osd_free(temp);
}
示例#19
0
文件: window.c 项目: mbcoguno/mame
int sdl_window_info::window_init()
{
	worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param));
	int result;

	ASSERT_MAIN_THREAD();

	// set the initial maximized state
	// FIXME: Does not belong here
	sdl_options &options = downcast<sdl_options &>(m_machine.options());
	m_startmaximized = options.maximize();

	// add us to the list
	*last_window_ptr = this;
	last_window_ptr = &this->m_next;

	set_renderer(draw.create(this));

	// create an event that we can use to skip blitting
	m_rendered_event = osd_event_alloc(FALSE, TRUE);

	// load the layout
	m_target = m_machine.render().target_alloc();

	// set the specific view
	set_starting_view(m_index, options.view(), options.view(m_index));

	// make the window title
	if (video_config.numscreens == 1)
		sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name);
	else
		sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), m_machine.system().description, m_machine.system().name, m_index);

	wp->set_window(this);

	// FIXME: pass error back in a different way
	if (multithreading_enabled)
	{
		osd_work_item *wi;

		wi = osd_work_item_queue(work_queue, &sdl_window_info::complete_create_wt, (void *) wp, 0);
		sdlwindow_sync();
		result = *((int *) (osd_work_item_result)(wi));
		osd_work_item_release(wi);
	}
	else
		result = *((int *) sdl_window_info::complete_create_wt((void *) wp, 0));

	// handle error conditions
	if (result == 1)
		goto error;

	return 0;

error:
	destroy();
	return 1;
}
示例#20
0
static void add_list(copy_info **head, copy_info *element, Uint32 bm)
{
	copy_info *newci = (copy_info *) osd_malloc(sizeof(copy_info));
	*newci = *element;

	newci->bm_mask = bm;
	newci->next = *head;
	*head = newci;
}
示例#21
0
static osd_shared_mem *osd_sharedmem_alloc(const char *path, int create, size_t size)
{
	osd_shared_mem *os_shmem = (osd_shared_mem *) osd_malloc(sizeof(osd_shared_mem));

	os_shmem->creator = 0;

	os_shmem->ptr = (void *) osd_malloc_array(size);
	os_shmem->size = size;
	return os_shmem;
}
示例#22
0
文件: mui_util.cpp 项目: cdrr/mameui
TCHAR* win_tstring_strdup(LPCTSTR str)
{
	TCHAR *cpy = NULL;
	if (str != NULL)
	{
		cpy = (TCHAR*)osd_malloc((_tcslen(str) + 1) * sizeof(TCHAR));
		if (cpy != NULL)
			_tcscpy(cpy, str);
	}
	return cpy;
}
示例#23
0
static inline void execute_async(osd_work_callback callback, const worker_param &wp)
{
	worker_param *wp_temp = (worker_param *) osd_malloc(sizeof(worker_param));
	*wp_temp = wp;

	if (multithreading_enabled)
	{
		osd_work_item_queue(work_queue, callback, (void *) wp_temp, WORK_ITEM_FLAG_AUTO_RELEASE);
	} else
		callback((void *) wp_temp, 0);
}
示例#24
0
static char *build_full_path(const char *path, const char *file)
{
	char *ret = (char *) osd_malloc(strlen(path)+strlen(file)+2);
	char *p = ret;

	strcpy(p, path);
	p += strlen(path);
	*p++ = PATHSEPCH;
	strcpy(p, file);
	return ret;
}
示例#25
0
文件: debugwin.c 项目: Ilgrim/MAMEHub
static win_i *add_win_i(running_machine &machine, int win_type)
{
	win_i *win = (win_i *) osd_malloc(sizeof(*win));
	memset(win, 0, sizeof(*win));
	win->cpu = NULL;
	win->machine = &machine;
	win->type = win_type;

	win->next = win_list;
	win_list = win;
	return win;
}
示例#26
0
char *utf8_from_wstring(const WCHAR *wstring)
{
	int char_count;
	char *result;

	// convert UTF-16 to MAME string (UTF-8)
	char_count = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL);
	result = (char *)osd_malloc(char_count * sizeof(*result));
	if (result != NULL)
		WideCharToMultiByte(CP_UTF8, 0, wstring, -1, result, char_count, NULL, NULL);

	return result;
}
示例#27
0
WCHAR *wstring_from_utf8(const char *utf8string)
{
	int char_count;
	WCHAR *result;

	// convert MAME string (UTF-8) to UTF-16
	char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
	result = (WCHAR *)osd_malloc(char_count * sizeof(*result));
	if (result != NULL)
		MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);

	return result;
}
示例#28
0
osd_midi_device *osd_open_midi_output(const char *devname)
{
    int num_devs = Pm_CountDevices();
    int found_dev = -1;
    const PmDeviceInfo *pmInfo;
    PortMidiStream *stm;
    osd_midi_device *ret;

    if (!strcmp("default", devname))
    {
        found_dev = Pm_GetDefaultOutputDeviceID();
    }
    else
    {
        for (int i = 0; i < num_devs; i++)
        {
            pmInfo = Pm_GetDeviceInfo(i);

            if (pmInfo->output)
            {
                if (!strcmp(devname, pmInfo->name))
                {
                    found_dev = i;
                    break;
                }
            }
        }
    }

    if (found_dev >= 0)
    {
        if (Pm_OpenOutput(&stm, found_dev, NULL, 100, NULL, NULL, 0) == pmNoError)
        {
            ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device));
            memset(ret, 0, sizeof(osd_midi_device));
            ret->pmStream = stm;
            return ret;
        }
        else
        {
            printf("Couldn't open PM device\n");
            return NULL;
        }
    }
    else
    {
        return NULL;
    }
    return NULL;
}
示例#29
0
文件: window.c 项目: clobber/UME
void sdlwindow_clear(sdl_window_info *window)
{
	worker_param *wp = (worker_param *) osd_malloc(sizeof(worker_param));

	clear_worker_param(wp);
	wp->window = window;

	if (SDL_ThreadID() == main_threadid)
	{
		execute_async_wait(&sdlwindow_clear_surface_wt, wp);
		osd_free(wp);
	}
	else
		sdlwindow_clear_surface_wt( (void *) wp, 0);
}
示例#30
0
文件: window.c 项目: clobber/UME
INLINE void execute_async(osd_work_callback callback, worker_param *wp)
{
	worker_param *wp_temp = NULL;

	if (wp)
	{
		wp_temp = (worker_param *) osd_malloc(sizeof(worker_param));
		*wp_temp = *wp;
	}
	if (multithreading_enabled)
	{
		osd_work_item_queue(work_queue, callback, (void *) wp_temp, WORK_ITEM_FLAG_AUTO_RELEASE);
	} else
		callback((void *) wp_temp, 0);
}