Beispiel #1
0
void text_buffer_free(text_buffer *text)
{
	if (text->lineoffs)
		global_free_array(text->lineoffs);
	if (text->buffer)
		global_free_array(text->buffer);
	global_free(text);
}
Beispiel #2
0
reverb::~reverb()
{
	for (int c=0; c<2; c++)
	{
		for (int f=0; f<4; f++)
			global_free_array(y[c][f]);
		global_free_array(x[c]);
		global_free_array(ax[c]);
		global_free_array(ay[c]);
	}
}
Beispiel #3
0
static void ddraw_delete_surfaces(win_window_info *window)
{
	dd_info *dd = (dd_info *)window->drawdata;

	// release the gamma control
	if (dd->gamma != NULL)
		IDirectDrawGammaControl_Release(dd->gamma);
	dd->gamma = NULL;

	// release the clipper
	if (dd->clipper != NULL)
		IDirectDrawClipper_Release(dd->clipper);
	dd->clipper = NULL;

	// free the memory buffer
	global_free_array(dd->membuffer);
	dd->membuffer = NULL;
	dd->membuffersize = 0;

	// release the blit surface
	if (dd->blit != NULL)
		IDirectDrawSurface7_Release(dd->blit);
	dd->blit = NULL;

	// release the back surface
	if (dd->back != NULL)
		IDirectDrawSurface7_Release(dd->back);
	dd->back = NULL;

	// release the primary surface
	if (dd->primary != NULL)
		IDirectDrawSurface7_Release(dd->primary);
	dd->primary = NULL;
}
Beispiel #4
0
void renderer_dd::ddraw_delete_surfaces()
{
	// release the gamma control
	if (gamma != NULL)
		IDirectDrawGammaControl_Release(gamma);
	gamma = NULL;

	// release the clipper
	if (clipper != NULL)
		IDirectDrawClipper_Release(clipper);
	clipper = NULL;

	// free the memory buffer
	global_free_array(membuffer);
	membuffer = NULL;
	membuffersize = 0;

	// release the blit surface
	if (blit != NULL)
		IDirectDrawSurface7_Release(blit);
	blit = NULL;

	// release the back surface
	if (back != NULL)
		IDirectDrawSurface7_Release(back);
	back = NULL;

	// release the primary surface
	if (primary != NULL)
		IDirectDrawSurface7_Release(primary);
	primary = NULL;
}
Beispiel #5
0
void sound_sdl::sdl_destroy_buffers(void)
{
	// release the buffer
	if (stream_buffer)
		global_free_array(stream_buffer);
	stream_buffer = NULL;
}
Beispiel #6
0
text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines)
{
	text_buffer *text;

	/* allocate memory for the text buffer object */
	text = global_alloc_nothrow(text_buffer);
	if (!text)
		return nullptr;

	/* allocate memory for the buffer itself */
	text->buffer = global_alloc_array_nothrow(char, bytes);
	if (!text->buffer)
	{
		global_free(text);
		return nullptr;
	}

	/* allocate memory for the lines array */
	text->lineoffs = global_alloc_array_nothrow(INT32, lines);
	if (!text->lineoffs)
	{
		global_free_array(text->buffer);
		global_free(text);
		return nullptr;
	}

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

	return text;
}
Beispiel #7
0
static void hiscore_save (running_machine &machine)
{
	file_error filerr;
  	emu_file f(machine.options().hiscore_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
  	filerr = f.open(machine.basename(), ".hi");

	if (filerr == FILERR_NONE)
	{
		memory_range *mem_range = state.mem_range;

		while (mem_range)
		{
			UINT8 *data = global_alloc_array(UINT8, 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 (machine, mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				f.write(data, mem_range->num_bytes);
				global_free_array(data);
			}
			mem_range = mem_range->next;
		}
		f.close();
	}
}
Beispiel #8
0
int fuzzy_substring(std::string s_needle, std::string s_haystack)
{
	if (s_needle.empty())
		return s_haystack.size();
	if (s_haystack.empty())
		return s_needle.size();

	strmakelower(s_needle);
	strmakelower(s_haystack);

	if (s_needle == s_haystack)
		return 0;
	if (s_haystack.find(s_needle) != std::string::npos)
		return 0;

	auto *row1 = global_alloc_array_clear<int>(s_haystack.size() + 2);
	auto *row2 = global_alloc_array_clear<int>(s_haystack.size() + 2);

	for (int i = 0; i < s_needle.size(); ++i)
	{
		row2[0] = i + 1;
		for (int j = 0; j < s_haystack.size(); ++j)
		{
			int cost = (s_needle[i] == s_haystack[j]) ? 0 : 1;
			row2[j + 1] = MIN(row1[j + 1] + 1, MIN(row2[j] + 1, row1[j] + cost));
		}

		int *tmp = row1;
		row1 = row2;
		row2 = tmp;
	}

	int *first, *smallest;
	first = smallest = row1;
	int *last = row1 + s_haystack.size();

	while (++first != last)
		if (*first < *smallest)
			smallest = first;

	int rv = *smallest;
	global_free_array(row1);
	global_free_array(row2);

	return rv;
}
Beispiel #9
0
DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart )
{
	if (timex_cart.data)
	{
		global_free_array(timex_cart.data);
		timex_cart.data = NULL;
	}
	timex_cart.type = TIMEX_CART_NONE;
	timex_cart.chunks = 0x00;
}
Beispiel #10
0
/* hiscore_free disposes of the mem_range linked list */
static void hiscore_free (void)
{
	memory_range *mem_range = state.mem_range;

	while (mem_range)
	{
		memory_range *next = mem_range->next;
		global_free_array(mem_range);
		mem_range = next;
	}
	state.mem_range = NULL;
}
Beispiel #11
0
	char *convert_cfstring_to_utf8(CFStringRef str) const
	{
		CFIndex const len = CFStringGetMaximumSizeForEncoding(
				CFStringGetLength(str),
				kCFStringEncodingUTF8);
		char *const result = global_alloc_array_clear<char>(len + 1);
		if (!CFStringGetCString(str, result, len + 1, kCFStringEncodingUTF8))
		{
			global_free_array(result);
			return NULL;
		}
		return result;
	}
Beispiel #12
0
int renderer_gdi::draw(const int update)
{
	auto win = assert_window();

	// we don't have any special resize behaviors
	if (win->m_resize_state == RESIZE_STATE_PENDING)
		win->m_resize_state = RESIZE_STATE_NORMAL;

	// get the target bounds
	RECT bounds;
	GetClientRect(win->platform_window<HWND>(), &bounds);

	// compute width/height/pitch of target
	int width = rect_width(&bounds);
	int height = rect_height(&bounds);
	int pitch = (width + 3) & ~3;

	// make sure our temporary bitmap is big enough
	if (pitch * height * 4 > m_bmsize)
	{
		m_bmsize = pitch * height * 4 * 2;
		global_free_array(m_bmdata);
		m_bmdata = global_alloc_array(uint8_t, m_bmsize);
	}

	// draw the primitives to the bitmap
	win->m_primlist->acquire_lock();
	software_renderer<uint32_t, 0,0,0, 16,8,0>::draw_primitives(*win->m_primlist, m_bmdata, width, height, pitch);
	win->m_primlist->release_lock();

	// fill in bitmap-specific info
	m_bminfo.bmiHeader.biWidth = pitch;
	m_bminfo.bmiHeader.biHeight = -height;

	// blit to the screen
	StretchDIBits(win->m_dc, 0, 0, width, height,
				0, 0, width, height,
				m_bmdata, &m_bminfo, DIB_RGB_COLORS, SRCCOPY);
	return 0;
}
Beispiel #13
0
void horizon_ramdisk_device::nvram_read(emu_file &file)
{
	int size = 2097152*(1 << ioport("HORIZONSIZE")->read());

	// NVRAM plus ROS
	uint8_t* buffer = global_alloc_array_clear<uint8_t>(MAXSIZE + ROSSIZE);

	memset(m_nvram->pointer(), 0,  size);
	memset(m_ros->pointer(), 0, ROSSIZE);

	// We assume the last 8K is ROS
	int filesize = file.read(buffer, MAXSIZE+ROSSIZE);
	int nvramsize = filesize - ROSSIZE;

	// If there is a reasonable size
	if (nvramsize >= 0)
	{
		// Copy from buffer to NVRAM and ROS
		memcpy(m_nvram->pointer(), buffer, nvramsize);
		memcpy(m_ros->pointer(), buffer + nvramsize, ROSSIZE);
	}

	global_free_array(buffer);
}
Beispiel #14
0
static TCHAR *reg_query_string(HKEY key, const TCHAR *path)
{
	TCHAR *buffer;
	DWORD datalen;
	LONG result;

	// first query to get the length
	result = RegQueryValueEx(key, path, NULL, NULL, NULL, &datalen);
	if (result != ERROR_SUCCESS)
		return NULL;

	// allocate a buffer
	buffer = global_alloc_array(TCHAR, datalen + sizeof(*buffer));
	buffer[datalen / sizeof(*buffer)] = 0;

	// now get the actual data
	result = RegQueryValueEx(key, path, NULL, NULL, (LPBYTE)buffer, &datalen);
	if (result == ERROR_SUCCESS)
		return buffer;

	// otherwise return a NULL buffer
	global_free_array(buffer);
	return NULL;
}
Beispiel #15
0
renderer_gdi::~renderer_gdi()
{
	// free the bitmap memory
	if (m_bmdata != nullptr)
		global_free_array(m_bmdata);
}
Beispiel #16
0
void ti99_datamux_device::device_stop(void)
{
    if (m_ram16b) global_free_array(m_ram16b);
}
Beispiel #17
0
menu_control_floppy_image::~menu_control_floppy_image()
{
	global_free_array(format_array);
}
Beispiel #18
0
static int ddraw_create_surfaces(win_window_info *window)
{
	dd_info *dd = (dd_info *)window->drawdata;
	HRESULT result;

	// make a description of the primary surface
	memset(&dd->primarydesc, 0, sizeof(dd->primarydesc));
	dd->primarydesc.dwSize = sizeof(dd->primarydesc);
	dd->primarydesc.dwFlags = DDSD_CAPS;
	dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	// for triple-buffered full screen mode, allocate flipping surfaces
	if (window->fullscreen && video_config.triplebuf)
	{
		dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
		dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
		dd->primarydesc.dwBackBufferCount = 2;
	}

	// create the primary surface and report errors
	result = create_surface(dd, &dd->primarydesc, &dd->primary, "primary");
	if (result != DD_OK) goto error;

	// full screen mode: get the back surface
	dd->back = NULL;
	if (window->fullscreen && video_config.triplebuf)
	{
		DDSCAPS2 caps = { DDSCAPS_BACKBUFFER };
		result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back);
		if (result != DD_OK)
		{
			mame_printf_verbose("DirectDraw: Error %08X getting attached back surface\n", (int)result);
			goto error;
		}
	}

	// now make a description of our blit surface, based on the primary surface
	if (dd->blitwidth == 0 || dd->blitheight == 0)
		compute_blit_surface_size(window);
	dd->blitdesc = dd->primarydesc;
	dd->blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
	dd->blitdesc.dwWidth = dd->blitwidth;
	dd->blitdesc.dwHeight = dd->blitheight;
	dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;

	// then create the blit surface, fall back to system memory if video mem doesn't work
	result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
	if (result != DD_OK)
	{
		dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
		result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
	}
	if (result != DD_OK) goto error;

	// create a memory buffer for offscreen drawing
	if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4)
	{
		dd->membuffersize = dd->blitwidth * dd->blitheight * 4;
		global_free_array(dd->membuffer);
		dd->membuffer = global_alloc_array(UINT8, dd->membuffersize);
	}
	if (dd->membuffer == NULL)
		goto error;

	// create a clipper for windowed mode
	if (!window->fullscreen && create_clipper(window))
		goto error;

	// full screen mode: set the gamma
	if (window->fullscreen)
	{
		// only set the gamma if it's not 1.0f
		windows_options &options = downcast<windows_options &>(window->machine().options());
		float brightness = options.full_screen_brightness();
		float contrast = options.full_screen_contrast();
		float gamma = options.full_screen_gamma();
		if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f)
		{
			// see if we can get a GammaControl object
			result = IDirectDrawSurface_QueryInterface(dd->primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&dd->gamma);
			if (result != DD_OK)
			{
				mame_printf_warning("DirectDraw: Warning - device does not support full screen gamma correction.\n");
				dd->gamma = NULL;
			}

			// proceed if we can
			if (dd->gamma != NULL)
			{
				DDGAMMARAMP ramp;
				int i;

				// create a standard ramp and set it
				for (i = 0; i < 256; i++)
					ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8;

				// attempt to set it
				result = IDirectDrawGammaControl_SetGammaRamp(dd->gamma, 0, &ramp);
				if (result != DD_OK)
					mame_printf_verbose("DirectDraw: Error %08X attempting to set gamma correction.\n", (int)result);
			}
		}
	}

	// force some updates
	update_outer_rects(dd);
	return 0;

error:
	ddraw_delete_surfaces(window);
	return 1;
}
Beispiel #19
0
/*-------------------------------------------------
    DEVICE_IMAGE_UNLOAD( rom )
-------------------------------------------------*/
void rom_image_device::call_unload()
{
	global_free_array(m_base);
	m_base = NULL;
}
Beispiel #20
0
static TCHAR *rawinput_device_improve_name(TCHAR *name)
{
	static const TCHAR usbbasepath[] = TEXT("SYSTEM\\CurrentControlSet\\Enum\\USB");
	static const TCHAR basepath[] = TEXT("SYSTEM\\CurrentControlSet\\Enum\\");
	TCHAR *regstring = NULL;
	TCHAR *parentid = NULL;
	TCHAR *regpath = NULL;
	const TCHAR *chsrc;
	HKEY regkey = NULL;
	int usbindex;
	TCHAR *chdst;
	LONG result;

	// The RAW name received is formatted as:
	//   \??\type-id#hardware-id#instance-id#{DeviceClasses-id}
	// XP starts with "\??\"
	// Vista64 starts with "\\?\"

	// ensure the name is something we can handle
	if (_tcsncmp(name, TEXT("\\\\?\\"), 4) != 0 && _tcsncmp(name, TEXT("\\??\\"), 4) != 0)
		return name;

	// allocate a temporary string and concatenate the base path plus the name
	regpath = global_alloc_array(TCHAR, _tcslen(basepath) + 1 + _tcslen(name));
	_tcscpy(regpath, basepath);
	chdst = regpath + _tcslen(regpath);

	// convert all # to \ in the name
	for (chsrc = name + 4; *chsrc != 0; chsrc++)
		*chdst++ = (*chsrc == '#') ? '\\' : *chsrc;
	*chdst = 0;

	// remove the final chunk
	chdst = _tcsrchr(regpath, '\\');
	if (chdst == NULL)
		goto exit;
	*chdst = 0;

	// now try to open the registry key
	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &regkey);
	if (result != ERROR_SUCCESS)
		goto exit;

	// fetch the device description; if it exists, we are finished
	regstring = reg_query_string(regkey, TEXT("DeviceDesc"));
	if (regstring != NULL)
		goto convert;

	// close this key
	RegCloseKey(regkey);
	regkey = NULL;

	// if the key name does not contain "HID", it's not going to be in the USB tree; give up
	if (_tcsstr(regpath, TEXT("HID")) == NULL)
		goto exit;

	// extract the expected parent ID from the regpath
	parentid = _tcsrchr(regpath, '\\');
	if (parentid == NULL)
		goto exit;
	parentid++;

	// open the USB key
	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, usbbasepath, 0, KEY_READ, &regkey);
	if (result != ERROR_SUCCESS)
		goto exit;

	// enumerate the USB key
	for (usbindex = 0; result == ERROR_SUCCESS && regstring == NULL; usbindex++)
	{
		TCHAR keyname[MAX_PATH];
		DWORD namelen;

		// get the next enumerated subkey and scan it
		namelen = ARRAY_LENGTH(keyname) - 1;
		result = RegEnumKeyEx(regkey, usbindex, keyname, &namelen, NULL, NULL, NULL, NULL);
		if (result == ERROR_SUCCESS)
		{
			LONG subresult;
			int subindex;
			HKEY subkey;

			// open the subkey
			subresult = RegOpenKeyEx(regkey, keyname, 0, KEY_READ, &subkey);
			if (subresult != ERROR_SUCCESS)
				continue;

			// enumerate the subkey
			for (subindex = 0; subresult == ERROR_SUCCESS && regstring == NULL; subindex++)
			{
				// get the next enumerated subkey and scan it
				namelen = ARRAY_LENGTH(keyname) - 1;
				subresult = RegEnumKeyEx(subkey, subindex, keyname, &namelen, NULL, NULL, NULL, NULL);
				if (subresult == ERROR_SUCCESS)
				{
					TCHAR *endparentid;
					LONG endresult;
					HKEY endkey;

					// open this final key
					endresult = RegOpenKeyEx(subkey, keyname, 0, KEY_READ, &endkey);
					if (endresult != ERROR_SUCCESS)
						continue;

					// do we have a match?
					endparentid = reg_query_string(endkey, TEXT("ParentIdPrefix"));
					if (endparentid != NULL && _tcsncmp(parentid, endparentid, _tcslen(endparentid)) == 0)
						regstring = reg_query_string(endkey, TEXT("DeviceDesc"));

					// free memory and close the key
					if (endparentid != NULL)
						global_free_array(endparentid);
					RegCloseKey(endkey);
				}
			}

			// close the subkey
			RegCloseKey(subkey);
		}
	}

	// if we didn't find anything, go to the exit
	if (regstring == NULL)
		goto exit;

convert:
	// replace the name with the nicer one
	global_free_array(name);

	// remove anything prior to the final semicolon
	chsrc = _tcsrchr(regstring, ';');
	if (chsrc != NULL)
		chsrc++;
	else
		chsrc = regstring;
	name = global_alloc_array(TCHAR, _tcslen(chsrc) + 1);
	_tcscpy(name, chsrc);

exit:
	if (regstring != NULL)
		global_free_array(regstring);
	if (regpath != NULL)
		global_free_array(regpath);
	if (regkey != NULL)
		RegCloseKey(regkey);

	return name;
}
Beispiel #21
0
bool imd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT64 size = io_generic_size(io);
	dynamic_buffer img(size);
	io_generic_read(io, img, 0, size);

	UINT64 pos;
	for(pos=0; pos < size && img[pos] != 0x1a; pos++);
	pos++;

	if(pos >= size)
		return false;

	while(pos < size) {
		UINT8 mode = img[pos++];
		UINT8 track = img[pos++];
		UINT8 head = img[pos++];
		UINT8 sector_count = img[pos++];
		UINT8 ssize = img[pos++];

		if(ssize == 0xff)
			throw emu_fatalerror("imd_format: Unsupported variable sector size on track %d head %d", track, head);

		UINT32 actual_size = ssize < 7 ? 128 << ssize : 8192;

		static const int rates[3] = { 500000, 300000, 250000 };
		bool fm = mode < 3;
		int rate = rates[mode % 3];
		int rpm = form_factor == floppy_image::FF_8 || (form_factor == floppy_image::FF_525 && rate >= 300000) ? 360 : 300;
		int cell_count = (fm ? 1 : 2)*rate*60/rpm;

		const UINT8 *snum = img+pos;
		pos += sector_count;
		const UINT8 *tnum = head & 0x80 ? img+pos : NULL;
		if(tnum)
			pos += sector_count;
		const UINT8 *hnum = head & 0x40 ? img+pos : NULL;
		if(hnum)
			pos += sector_count;

		head &= 0x3f;

		int gap_3 = calc_default_pc_gap3_size(form_factor, actual_size);

		desc_pc_sector sects[256];

		for(int i=0; i<sector_count; i++) {
			UINT8 stype = img[pos++];
			sects[i].track       = tnum ? tnum[i] : track;
			sects[i].head        = hnum ? hnum[i] : head;
			sects[i].sector      = snum[i];
			sects[i].size        = ssize;
			sects[i].actual_size = actual_size;

			if(stype == 0 || stype > 8) {
				sects[i].data = NULL;

			} else {
				sects[i].deleted = stype == 3 || stype == 4 || stype == 7 || stype == 8;
				sects[i].bad_crc = stype == 5 || stype == 6 || stype == 7 || stype == 8;

				if(stype == 2 || stype == 4 || stype == 6 || stype == 8) {
					sects[i].data = global_alloc_array(UINT8, actual_size);
					memset(sects[i].data, img[pos++], actual_size);

				} else {
					sects[i].data = img + pos;
					pos += actual_size;
				}
			}
		}

		if(fm)
			build_pc_track_fm(track, head, image, cell_count, sector_count, sects, gap_3);
		else
			build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, gap_3);

		for(int i=0; i<sector_count; i++)
			if(sects[i].data && (sects[i].data < img || sects[i].data >= img+size))
				global_free_array(sects[i].data);
	}

	return true;
}