Esempio n. 1
0
File: window.c Progetto: clobber/UME
static void sdlwindow_exit(running_machine &machine)
{
	ASSERT_MAIN_THREAD();

	mame_printf_verbose("Enter sdlwindow_exit\n");

	// free all the windows
	while (sdl_window_list != NULL)
	{
		sdl_window_info *temp = sdl_window_list;
		sdl_window_list = temp->next;
		sdlwindow_video_window_destroy(machine, temp);
	}

	// if we're multithreaded, clean up the window thread
	if (multithreading_enabled)
	{
		sdlwindow_sync();
	}

	// kill the drawers
	(*draw.exit)();

	execute_async_wait(&sdlwindow_exit_wt, NULL);

	if (multithreading_enabled)
	{
		osd_work_queue_wait(work_queue, 1000000);
		osd_work_queue_free(work_queue);
	}
	mame_printf_verbose("Leave sdlwindow_exit\n");

}
int ps_get_monitor_timing(int monitor_index, MonitorTiming *timing)
{
	LRESULT lresult;
	char in[256];
	
	if (!hPSWnd) return 0;
	
	lresult = SendMessage(hPSWnd, UM_GETTIMING, monitor_index, 0);
	
	if (lresult == -1)
	{
		mame_printf_verbose("PStrip: Could not get PowerStrip timing string\n");
		return 0;
	}
	
	if (!GlobalGetAtomNameA(lresult, in, sizeof(in)))
	{
		mame_printf_verbose("PStrip: GlobalGetAtomName failed\n");
		return 0;
	}
	
	mame_printf_verbose("PStrip: ps_get_monitor_timing(%d): %s\n", monitor_index, in);
	
	read_timing_string(in, timing);
	
	GlobalDeleteAtom(lresult); // delete atom created by PowerStrip

	return 1;
}
int ps_set_monitor_timing(int monitor_index, MonitorTiming *timing)
{
	LRESULT lresult;
	ATOM atom;
	char out[256];
	
	if (!hPSWnd) return 0;
		
	fill_timing_string(out, timing);
	atom = GlobalAddAtomA(out);
	
	if (atom)
	{
		lresult = SendMessage(hPSWnd, UM_SETCUSTOMTIMING, monitor_index, atom);
		
		if (lresult < 0)
		{
			mame_printf_verbose("PStrip: SendMessage failed\n");
			GlobalDeleteAtom(atom);
		}
		else
		{
			mame_printf_verbose("PStrip: ps_set_monitor_timing(%d): %s\n", monitor_index, out);
			return 1;
		}
	}
	else mame_printf_verbose("PStrip: ps_set_monitor_timing atom creation failed\n");

	return 0;
}
int ps_create_resolution(int monitor_index, ModeLine *modeline)
{
	LRESULT     lresult;
	ATOM        atom;
	char        out[256];
	MonitorTiming timing = {0};
	
	if (!hPSWnd) return 0;
	
	modeline_to_pstiming(modeline, &timing);
	
	fill_timing_string(out, &timing);
	atom = GlobalAddAtomA(out);
	
	if (atom)
	{
		lresult = SendMessage(hPSWnd, UM_CREATERESOLUTION, monitor_index, atom);
		
		if (lresult < 0)
        	{
        		mame_printf_verbose("PStrip: SendMessage failed\n");
        		GlobalDeleteAtom(atom);
        	}
        	else
        	{
        		mame_printf_verbose("PStrip: ps_create_resolution(%d): %dx%d succeded \n",
        			modeline->a_width, modeline->a_height, monitor_index);
        		return 1;
        	}
        }
        else mame_printf_verbose("PStrip: ps_create_resolution atom creation failed\n");
	
	return 0;
}
Esempio n. 5
0
int draw13_init(running_machine &machine, sdl_draw_info *callbacks)
{
	const char *stemp;

	// fill in the callbacks
	callbacks->exit = draw13_exit;
	callbacks->attach = draw13_attach;

	mame_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n");

	expand_copy_info(blit_info_default);
	//FIXME: -opengl16 should be -opengl -prefer16bpp
	//if (video_config.prefer16bpp_tex)
	expand_copy_info(blit_info_16bpp);

	// Load the GL library now - else MT will fail

	stemp = downcast<sdl_options &>(machine.options()).gl_lib();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) == 0)
		stemp = NULL;

	// No fatalerror here since not all video drivers support GL !
	if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==NULL
		mame_printf_verbose("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>");
	else
		mame_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>");

	return 0;
}
Esempio n. 6
0
netdev_tap::netdev_tap(const char *name, class device_network_interface *ifdev, int rate)
	: netdev(ifdev, rate)
{
#ifdef __linux__
	struct ifreq ifr;

	m_fd = -1;
	if((m_fd = open("/dev/net/tun", O_RDWR)) == -1) {
		mame_printf_verbose("tap: open failed %d\n", errno);
		return;
	}

	memset(&ifr, 0, sizeof(ifr));
	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
	sprintf(ifr.ifr_name, "tap-mess-%d-0", getuid());
	if(ioctl(m_fd, TUNSETIFF, (void *)&ifr) == -1) {
		mame_printf_verbose("tap: ioctl failed %d\n", errno);
		close(m_fd);
		m_fd = -1;
		return;
	}
    mame_printf_verbose("netdev_tap: network up!\n");
	strncpy(m_ifname, ifr.ifr_name, 10);
	fcntl(m_fd, F_SETFL, O_NONBLOCK);

#else
	m_fd = -1;
#endif
}
Esempio n. 7
0
static int ddraw_create(win_window_info *window)
{
	dd_info *dd = window->drawdata;
	HRESULT result;
	int verify;

	// if a device exists, free it
	if (dd->ddraw != NULL)
		ddraw_delete(window);

	// create the DirectDraw object
	result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, &IID_IDirectDraw7, NULL);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
		goto error;
	}

	// verify the caps
	verify = ddraw_verify_caps(dd);
	if (verify == 2)
	{
		mame_printf_error("DirectDraw: Error - Device does not meet minimum requirements for DirectDraw rendering\n");
		goto error;
	}
	if (verify == 1)
		mame_printf_verbose("DirectDraw: Warning - Device may not perform well for DirectDraw rendering\n");

	// set the cooperative level
	// for non-window modes, we will use full screen here
	result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->hwnd, DDSCL_SETFOCUSWINDOW);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result);
		goto error;
	}
	result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->hwnd, DDSCL_SETDEVICEWINDOW | (window->fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result);
		goto error;
	}

	// full screen mode: set the resolution
	if (window->fullscreen && video_config.switchres)
	{
		result = IDirectDraw7_SetDisplayMode(dd->ddraw, dd->width, dd->height, 32, dd->refresh, 0);
		if (result != DD_OK)
		{
			mame_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, dd->width, dd->height, dd->refresh);
			goto error;
		}
	}

	return ddraw_create_surfaces(window);

error:
	ddraw_delete(window);
	return 1;
}
Esempio n. 8
0
static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
{
	HRESULT result;

	// create the surface as requested
	result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type);
		return result;
	}

	// get a description of the primary surface
	result = IDirectDrawSurface7_GetSurfaceDesc(*surface, desc);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X getting %s surface desciption\n", (int)result, type);
		IDirectDrawSurface7_Release(*surface);
		*surface = NULL;
		return result;
	}

	// print out the good stuff
	mame_printf_verbose("DirectDraw: %s surface created: %dx%dx%d (R=%08X G=%08X B=%08X)\n",
				type,
				(int)desc->dwWidth,
				(int)desc->dwHeight,
				(int)desc->ddpfPixelFormat.dwRGBBitCount,
				(UINT32)desc->ddpfPixelFormat.dwRBitMask,
				(UINT32)desc->ddpfPixelFormat.dwGBitMask,
				(UINT32)desc->ddpfPixelFormat.dwBBitMask);
	return result;
}
Esempio n. 9
0
static int RendererSupportsFormat(SDL_Renderer *renderer, Uint32 format, Uint32 access, const char *sformat)
{
	int i;
	SDL_Texture *texid;
	for (i=0; fmt_support[i].format != 0; i++)
	{
		if (format == fmt_support[i].format)
		{
			return fmt_support[i].status;
		}
	}
	/* not tested yet */
	fmt_support[i].format = format;
	fmt_support[i + 1].format = 0;
	texid = SDL_CreateTexture(renderer, format, access, 16, 16);
	if (texid)
	{
		fmt_support[i].status = 1;
		SDL_DestroyTexture(texid);
		return 1;
	}
	mame_printf_verbose("Pixelformat <%s> error %s \n", sformat, SDL_GetError());
	mame_printf_verbose("Pixelformat <%s> not supported\n", sformat);
	fmt_support[i].status = 0;
	return 0;
}
Esempio n. 10
0
static int create_clipper(win_window_info *window)
{
	dd_info *dd = window->drawdata;
	HRESULT result;

	// create a clipper for the primary surface
	result = IDirectDraw7_CreateClipper(dd->ddraw, 0, &dd->clipper, NULL);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X creating clipper\n", (int)result);
		return 1;
	}

	// set the clipper's hwnd
	result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->hwnd);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X setting clipper hwnd\n", (int)result);
		return 1;
	}

	// set the clipper on the primary surface
	result = IDirectDrawSurface7_SetClipper(dd->primary, dd->clipper);
	if (result != DD_OK)
	{
		mame_printf_verbose("DirectDraw: Error %08X setting clipper on primary surface\n", (int)result);
		return 1;
	}
	return 0;
}
Esempio n. 11
0
File: window.c Progetto: clobber/UME
int sdlwindow_init(running_machine &machine)
{
	mame_printf_verbose("Enter sdlwindow_init\n");
	// determine if we are using multithreading or not
	multithreading_enabled = downcast<sdl_options &>(machine.options()).multithreading();

	// get the main thread ID before anything else
	main_threadid = SDL_ThreadID();

	// ensure we get called on the way out
	machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(sdlwindow_exit), &machine));

	// if multithreading, create a thread to run the windows
	if (multithreading_enabled)
	{
		// create a thread to run the windows from
		work_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_IO);
		if (work_queue == NULL)
			return 1;
		osd_work_item_queue(work_queue, &sdlwindow_thread_id, NULL, WORK_ITEM_FLAG_AUTO_RELEASE);
	}
	else
	{
		// otherwise, treat the window thread as the main thread
		//window_threadid = main_threadid;
		sdlwindow_thread_id(NULL, 0);
	}

	// initialize the drawers
#if USE_OPENGL
	if (video_config.mode == VIDEO_MODE_OPENGL)
	{
		if (drawogl_init(machine, &draw))
			video_config.mode = VIDEO_MODE_SOFT;
	}
#endif
#if SDLMAME_SDL2
	if (video_config.mode == VIDEO_MODE_SDL13)
	{
		if (draw13_init(machine, &draw))
			video_config.mode = VIDEO_MODE_SOFT;
	}
#endif
	if (video_config.mode == VIDEO_MODE_SOFT)
	{
		if (drawsdl_init(&draw))
			return 1;
	}

	// set up the window list
	last_window_ptr = &sdl_window_list;
	mame_printf_verbose("Leave sdlwindow_init\n");
	return 0;
}
Esempio n. 12
0
int drawgx_init(sdl_draw_info *callbacks)
{
    // fill in the callbacks
    callbacks->exit = drawgx_exit;
    callbacks->attach = drawgx_attach;

    if (SDL_VERSION_ATLEAST(1,3,0))
        mame_printf_verbose("Using SDL multi-window soft driver (SDL 1.3+)\n");
    else
        mame_printf_verbose("Using SDL single-window soft driver (SDL 1.2)\n");

    return 0;
}
Esempio n. 13
0
static void init_monitors(void)
{
	sdl_monitor_info **tailptr;

	// make a list of monitors
	sdl_monitor_list = NULL;
	tailptr = &sdl_monitor_list;

	#if (SDLMAME_SDL2)
	{
		int i;

		mame_printf_verbose("Enter init_monitors\n");

		for (i = 0; i < SDL_GetNumVideoDisplays(); i++)
		{
			sdl_monitor_info *monitor;
			SDL_DisplayMode dmode;

			// allocate a new monitor info
			monitor = global_alloc_clear(sdl_monitor_info);

			snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", SDLOPTION_SCREEN,i);

			SDL_GetDesktopDisplayMode(i, &dmode);
			monitor->monitor_width = dmode.w;
			monitor->monitor_height = dmode.h;
			monitor->center_width = dmode.w;
			monitor->center_height = dmode.h;
			monitor->handle = i;
			// guess the aspect ratio assuming square pixels
			monitor->aspect = (float)(dmode.w) / (float)(dmode.h);
			mame_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h);

			// save the primary monitor handle
			if (i == 0)
				primary_monitor = monitor;

			// hook us into the list
			*tailptr = monitor;
			tailptr = &monitor->next;
		}
	}
	mame_printf_verbose("Leave init_monitors\n");
	#elif defined(SDLMAME_WIN32)
	EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr);
	#else
	add_primary_monitor((void *)&tailptr);
	#endif
}
Esempio n. 14
0
void video_manager::update_refresh_speed()
{
	// only do this if the refreshspeed option is used
	if (machine().options().refresh_speed())
	{
		float minrefresh = machine().render().max_update_rate();
		if (minrefresh != 0)
		{
			// find the screen with the shortest frame period (max refresh rate)
			// note that we first check the token since this can get called before all screens are created
			attoseconds_t min_frame_period = ATTOSECONDS_PER_SECOND;
			screen_device_iterator iter(machine().root_device());
			for (screen_device *screen = iter.first(); screen != NULL; screen = iter.next())
			{
				attoseconds_t period = screen->frame_period().attoseconds;
				if (period != 0)
					min_frame_period = MIN(min_frame_period, period);
			}

			// compute a target speed as an integral percentage
			// note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for
            // the fact that most refresh rates are not accurate to 10 digits...
			UINT32 target_speed = floor((minrefresh - 0.25f) * 1000.0 / ATTOSECONDS_TO_HZ(min_frame_period));
			UINT32 original_speed = original_speed_setting();
			target_speed = MIN(target_speed, original_speed);

			// if we changed, log that verbosely
			if (target_speed != m_speed)
			{
				mame_printf_verbose("Adjusting target speed to %.1f%% (hw=%.2fHz, game=%.2fHz, adjusted=%.2fHz)\n", target_speed / 10.0, minrefresh, ATTOSECONDS_TO_HZ(min_frame_period), ATTOSECONDS_TO_HZ(min_frame_period * 1000.0 / target_speed));
				m_speed = target_speed;
			}
		}
	}
}
Esempio n. 15
0
static void sdlwindow_modify_yuv(running_machine *machine, sdl_window_info *window, int dir)
{
	int new_scale_mode = window->scale_mode;
	worker_param wp;
	const char *stemp;
	
	if (dir > 0)
		new_scale_mode = window->scale_mode + 1;
	if (dir < 0)
		new_scale_mode = window->scale_mode - 1;
	
	stemp = drawsdl_scale_mode_str(new_scale_mode);
	
	if (stemp==NULL)
		return;
	
	clear_worker_param(&wp);
	wp.window = window;
	wp.machine = machine;
	sdlwindow_sync();
	execute_async_wait(&sdlwindow_video_window_destroy_wt, &wp);
		
	window->scale_mode = new_scale_mode;
	
	ui_popup_time(1, "Scale mode %s", stemp);
	mame_printf_verbose("Scale mode %s\n", stemp);

	sdlwindow_sync();
	execute_async_wait(&complete_create_wt, &wp);
	sdlwindow_sync();

}
Esempio n. 16
0
int ps_init(int monitor_index)
{
	hPSWnd = FindWindowA("TPShidden", NULL);
	
	if (hPSWnd)
	{
		mame_printf_verbose("PStrip: PowerStrip found!\n");
		ps_get_monitor_timing(monitor_index, &timing_backup);
		return 1;
	}
	else
	{
		mame_printf_verbose("PStrip: Could not get PowerStrip API interface\n");
		return 0;
	}	
}
Esempio n. 17
0
static void pick_best_mode(win_window_info *window)
{
	dd_info *dd = (dd_info *)window->drawdata;
	mode_enum_info einfo;
	HRESULT result;

	// determine the minimum width/height for the selected target
	// note: technically we should not be calling this from an alternate window
	// thread; however, it is only done during init time, and the init code on
	// the main thread is waiting for us to finish, so it is safe to do so here
	window->target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);

	// use those as the target for now
	einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale);
	einfo.target_height = einfo.minimum_height * MAX(1, video_config.prescale);

	// determine the refresh rate of the primary screen
	einfo.target_refresh = 60.0;
	const screen_device *primary_screen = window->machine().config().first_screen();
	if (primary_screen != NULL)
		einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
	printf("Target refresh = %f\n", einfo.target_refresh);

	// if we're not stretching, allow some slop on the minimum since we can handle it
	if (!video_config.hwstretch)
	{
		einfo.minimum_width -= 4;
		einfo.minimum_height -= 4;
	}

	// if we are stretching, aim for a mode approximately 2x the game's resolution
	else if (video_config.prescale <= 1)
	{
		einfo.target_width *= 2;
		einfo.target_height *= 2;
	}

	// fill in the rest of the data
	einfo.window = window;
	einfo.best_score = 0.0f;

	// enumerate the modes
	mame_printf_verbose("DirectDraw: Selecting video mode...\n");
	result = IDirectDraw7_EnumDisplayModes(dd->ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
	if (result != DD_OK) mame_printf_verbose("DirectDraw: Error %08X during EnumDisplayModes call\n", (int)result);
	mame_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", dd->width, dd->height, dd->refresh);
}
Esempio n. 18
0
int ps_set_refresh(int monitor_index, double vfreq)
{
	MonitorTiming timing = {0};
	int i, hht, vvt, new_vvt;
	int desired_pClock;
	int best_pClock = 0;
	
	memcpy(&timing, &timing_backup, sizeof(MonitorTiming));

	hht = timing.HorizontalActivePixels
		+ timing.HorizontalFrontPorch
		+ timing.HorizontalSyncWidth
		+ timing.HorizontalBackPorch;
	
	vvt = timing.VerticalActivePixels
		+ timing.VerticalFrontPorch
		+ timing.VerticalSyncWidth
		+ timing.VerticalBackPorch;

	desired_pClock = hht * vvt * vfreq / 1000;

	mame_printf_verbose("PStrip: ps_set_refresh(%d) %f Hz, getting stable dotclocks for %d...\n", monitor_index, vfreq, desired_pClock);
		
	for (i = -50; i <= 50; i += 25)
	{
		timing.PixelClockInKiloHertz = desired_pClock + i;
	
		ps_set_monitor_timing(monitor_index, &timing);
		ps_get_monitor_timing(monitor_index, &timing);
		
		if (abs(timing.PixelClockInKiloHertz - desired_pClock) < abs(desired_pClock - best_pClock))
			
			best_pClock = timing.PixelClockInKiloHertz;
	}
	
	mame_printf_verbose("PStrip: ps_set_refresh(%d), new dotclock: %d\n", monitor_index, best_pClock);

	new_vvt = best_pClock * 1000 / (vfreq * hht);
	
	timing.VerticalBackPorch += (new_vvt - vvt);
	timing.PixelClockInKiloHertz = best_pClock;
	
	ps_set_monitor_timing(monitor_index, &timing);
	ps_get_monitor_timing(monitor_index, &timing);
	
	return 1;
}
Esempio n. 19
0
d3d *drawd3d8_init(void)
{
	direct3dcreate8_ptr direct3dcreate8;
	HINSTANCE dllhandle;
	IDirect3D8 *d3d8;
	d3d *d3dptr;

	// dynamically grab the create function from d3d8.dll
	dllhandle = LoadLibrary(TEXT("d3d8.dll"));
	if (dllhandle == NULL)
	{
		mame_printf_verbose("Direct3D: Unable to access d3d8.dll\n");
		return NULL;
	}

	// import the create function
	direct3dcreate8 = (direct3dcreate8_ptr)GetProcAddress(dllhandle, "Direct3DCreate8");
	if (direct3dcreate8 == NULL)
	{
		mame_printf_verbose("Direct3D: Unable to find Direct3DCreate8\n");
		FreeLibrary(dllhandle);
		dllhandle = NULL;
		return NULL;
	}

	// create our core direct 3d object
	d3d8 = (*direct3dcreate8)(D3D_SDK_VERSION);
	if (d3d8 == NULL)
	{
		mame_printf_verbose("Direct3D: Error attempting to initialize Direct3D8\n");
		FreeLibrary(dllhandle);
		dllhandle = NULL;
		return NULL;
	}

	// allocate an object to hold our data
	d3dptr = global_alloc(d3d);
	d3dptr->version = 8;
	d3dptr->d3dobj = d3d8;
	d3dptr->dllhandle = dllhandle;
	d3dptr->post_fx_available = false;
	set_interfaces(d3dptr);

	mame_printf_verbose("Direct3D: Using Direct3D 8\n");
	return d3dptr;
}
Esempio n. 20
0
void init_pcap()
{
	pcap_if_t *devs;
	char errbuf[PCAP_ERRBUF_SIZE];
	handle = NULL;

	try
	{
		if(!(handle = LoadLibrary(L"wpcap.dll"))) throw GetLastError();
		if(!(pcap_findalldevs_dl = (int (*)(pcap_if_t **, char *))GetProcAddress(handle, "pcap_findalldevs")))
			throw GetLastError();
		if(!(pcap_open_live_dl = (pcap_t* (*)(const char *, int, int, int, char *))GetProcAddress(handle, "pcap_open_live")))
			throw GetLastError();
		if(!(pcap_next_ex_dl = (int (*)(pcap_t *, struct pcap_pkthdr **, const u_char **))GetProcAddress(handle, "pcap_next_ex")))
			throw GetLastError();
		if(!(pcap_compile_dl = (int (*)(pcap_t *, struct bpf_program *, char *, int, bpf_u_int32))GetProcAddress(handle, "pcap_compile")))
			throw GetLastError();
		if(!(pcap_close_dl = (void (*)(pcap_t *))GetProcAddress(handle, "pcap_close")))
			throw GetLastError();
		if(!(pcap_setfilter_dl = (int (*)(pcap_t *, struct bpf_program *))GetProcAddress(handle, "pcap_setfilter")))
			throw GetLastError();
		if(!(pcap_sendpacket_dl = (int (*)(pcap_t *, u_char *, int))GetProcAddress(handle, "pcap_sendpacket")))
			throw GetLastError();
		if(!(pcap_set_datalink_dl = (int (*)(pcap_t *, int))GetProcAddress(handle, "pcap_set_datalink")))
			throw GetLastError();
	}
	catch (DWORD e)
	{
		FreeLibrary(handle);
		mame_printf_verbose("Unable to load winpcap: %lx\n", e);
		return;
	}
	if(pcap_findalldevs_dl(&devs, errbuf) == -1)
	{
		FreeLibrary(handle);
		mame_printf_verbose("Unable to get network devices: %s\n", errbuf);
		return;
	}

	while(devs)
	{
		add_netdev(devs->name, devs->description, create_pcap);
		devs = devs->next;
	}
}
Esempio n. 21
0
static int sdl_create_buffers(void)
{
	mame_printf_verbose("sdl_create_buffers: creating stream buffer of %u bytes\n", stream_buffer_size);

	stream_buffer = global_alloc_array_clear(INT8, stream_buffer_size);
	stream_playpos = 0;
	buf_locked = 0;
	return 0;
}
Esempio n. 22
0
static void sdl_kill(running_machine &machine)
{
	if (initialized_audio)
	{
		mame_printf_verbose("sdl_kill: closing audio\n");

		SDL_CloseAudio();
	}
}
Esempio n. 23
0
void eeprom_base_device::nvram_default()
{
    UINT32 eeprom_length = 1 << m_address_bits;
    UINT32 eeprom_bytes = eeprom_length * m_data_bits / 8;

    // initialize to the default value
    UINT32 default_value = m_default_value_set ? m_default_value : ~0;
    for (offs_t offs = 0; offs < eeprom_length; offs++)
        if (m_data_bits == 8)
            m_addrspace[0]->write_byte(offs, default_value);
        else
            m_addrspace[0]->write_word(offs * 2, default_value);

    // handle hard-coded data from the driver
    if (m_default_data.u8 != NULL)
    {
        mame_printf_verbose("Warning: Driver-specific EEPROM defaults are going away soon.\n");
        for (offs_t offs = 0; offs < m_default_data_size; offs++)
        {
            if (m_data_bits == 8)
                m_addrspace[0]->write_byte(offs, m_default_data.u8[offs]);
            else
                m_addrspace[0]->write_word(offs * 2, m_default_data.u16[offs]);
        }
    }

    // populate from a memory region if present
    if (m_region != NULL)
    {
        if (m_region->bytes() != eeprom_bytes)
            fatalerror("eeprom region '%s' wrong size (expected size = 0x%X)\n", tag(), eeprom_bytes);
        if (m_data_bits == 8 && m_region->width() != 1)
            fatalerror("eeprom region '%s' needs to be an 8-bit region\n", tag());
        if (m_data_bits == 16 && (m_region->width() != 2 || m_region->endianness() != ENDIANNESS_BIG))
            fatalerror("eeprom region '%s' needs to be a 16-bit big-endian region\n", tag());
        mame_printf_verbose("Loading data from EEPROM region '%s'\n", tag());

        for (offs_t offs = 0; offs < eeprom_length; offs++)
            if (m_data_bits == 8)
                m_addrspace[0]->write_byte(offs, m_region->u8(offs));
            else
                m_addrspace[0]->write_word(offs * 2, m_region->u16(offs));
    }
}
Esempio n. 24
0
static int sdl_create_buffers(void)
{
    mame_printf_verbose("sdl_create_buffers: creating stream buffer of %u bytes\n", stream_buffer_size);

    stream_buffer = (INT8 *)malloc(stream_buffer_size);
    memset(stream_buffer, 0, stream_buffer_size);
    stream_playpos = 0;
    buf_locked = 0;
    return 0;
}
Esempio n. 25
0
netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev, int rate)
	: netdev(ifdev, rate)
{
	char errbuf[PCAP_ERRBUF_SIZE];
	m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
	if(!m_p)
	{
		mame_printf_verbose("Unable to open %s: %s\n", name, errbuf);
		return;
	}
	if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
	{
		mame_printf_verbose("Unable to set %s to ethernet", name);
		pcap_close(m_p);
		m_p = NULL;
		return;
	}
	set_mac(get_mac());
}
Esempio n. 26
0
int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks)
{
	// dynamically grab the create function from ddraw.dll
	dllhandle = LoadLibrary(TEXT("ddraw.dll"));
	if (dllhandle == NULL)
	{
		mame_printf_verbose("DirectDraw: Unable to access ddraw.dll\n");
		return 1;
	}

	// import the create function
	directdrawcreateex = (directdrawcreateex_ptr)GetProcAddress(dllhandle, "DirectDrawCreateEx");
	if (directdrawcreateex == NULL)
	{
		mame_printf_verbose("DirectDraw: Unable to find DirectDrawCreateEx\n");
		FreeLibrary(dllhandle);
		dllhandle = NULL;
		return 1;
	}

	// import the enumerate function
	directdrawenumerateex = (directdrawenumerateex_ptr)GetProcAddress(dllhandle, "DirectDrawEnumerateExA");
	if (directdrawenumerateex == NULL)
	{
		mame_printf_verbose("DirectDraw: Unable to find DirectDrawEnumerateExA\n");
		FreeLibrary(dllhandle);
		dllhandle = NULL;
		return 1;
	}

	// fill in the callbacks
	callbacks->exit = drawdd_exit;
	callbacks->window_init = drawdd_window_init;
	callbacks->window_get_primitives = drawdd_window_get_primitives;
	callbacks->window_draw = drawdd_window_draw;
	callbacks->window_save = NULL;
	callbacks->window_record = NULL;
	callbacks->window_toggle_fsfx = NULL;
	callbacks->window_destroy = drawdd_window_destroy;

	mame_printf_verbose("DirectDraw: Using DirectDraw 7\n");
	return 0;
}
Esempio n. 27
0
static void sdloutput_exit(running_machine &machine)
{
    if (output != NULL)
    {
        fprintf(output, "MAME " PID_FMT " STOP %s\n", osd_getpid(), machine.system().name);
        fflush(output);
        fclose(output);
        output = NULL;
        mame_printf_verbose("ouput: closed output notifier file\n");
    }
}
Esempio n. 28
0
static void sound_exit(running_machine &machine)
{
	// kill the buffers and dsound
	dsound_destroy_buffers();
	dsound_kill();

	// print out over/underflow stats
	if (buffer_overflows || buffer_underflows)
		mame_printf_verbose("Sound: buffer overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows);

	LOG(("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows));
}
Esempio n. 29
0
void running_machine::start_all_devices()
{
	// iterate through the devices
	int last_failed_starts = -1;
	while (last_failed_starts != 0)
	{
		// iterate over all devices
		int failed_starts = 0;
		device_iterator iter(root_device());
		for (device_t *device = iter.first(); device != NULL; device = iter.next())
			if (!device->started())
			{
				// attempt to start the device, catching any expected exceptions
				try
				{
					// if the device doesn't have a machine yet, set it first
					if (device->m_machine == NULL)
						device->set_machine(*this);

					// now start the device
					mame_printf_verbose("Starting %s '%s'\n", device->name(), device->tag());
					device->start();
				}

				// handle missing dependencies by moving the device to the end
				catch (device_missing_dependencies &)
				{
					// if we're the end, fail
					mame_printf_verbose("  (missing dependencies; rescheduling)\n");
					failed_starts++;
				}
			}

		// each iteration should reduce the number of failed starts; error if
		// this doesn't happen
		if (failed_starts == last_failed_starts)
			throw emu_fatalerror("Circular dependency in device startup!");
		last_failed_starts = failed_starts;
	}
}
Esempio n. 30
0
static HRESULT WINAPI enum_modes_callback(LPDDSURFACEDESC2 desc, LPVOID context)
{
	float size_score, refresh_score, final_score;
	mode_enum_info *einfo = context;
	dd_info *dd = einfo->window->drawdata;

	// skip non-32 bit modes
	if (desc->ddpfPixelFormat.dwRGBBitCount != 32)
		return DDENUMRET_OK;

	// compute initial score based on difference between target and current
	size_score = 1.0f / (1.0f + fabs((INT32)desc->dwWidth - einfo->target_width) + fabs((INT32)desc->dwHeight - einfo->target_height));

	// if the mode is too small, give a big penalty
	if (desc->dwWidth < einfo->minimum_width || desc->dwHeight < einfo->minimum_height)
		size_score *= 0.01f;

	// if mode is smaller than we'd like, it only scores up to 0.1
	if (desc->dwWidth < einfo->target_width || desc->dwHeight < einfo->target_height)
		size_score *= 0.1f;

	// if we're looking for a particular mode, that's a winner
	if (desc->dwWidth == einfo->window->maxwidth && desc->dwHeight == einfo->window->maxheight)
		size_score = 2.0f;

	// compute refresh score
	refresh_score = 1.0f / (1.0f + fabs((double)desc->dwRefreshRate - einfo->target_refresh));

	// if refresh is smaller than we'd like, it only scores up to 0.1
	if ((double)desc->dwRefreshRate < einfo->target_refresh)
		refresh_score *= 0.1;

	// if we're looking for a particular refresh, make sure it matches
	if (desc->dwRefreshRate == einfo->window->refresh)
		refresh_score = 2.0f;

	// weight size and refresh equally
	final_score = size_score + refresh_score;

	// best so far?
	mame_printf_verbose("  %4dx%4d@%3dHz -> %f\n", (int)desc->dwWidth, (int)desc->dwHeight, (int)desc->dwRefreshRate, final_score * 1000.0f);
	if (final_score > einfo->best_score)
	{
		einfo->best_score = final_score;
		dd->width = desc->dwWidth;
		dd->height = desc->dwHeight;
		dd->refresh = desc->dwRefreshRate;
	}
	return DDENUMRET_OK;
}