mirror of
https://github.com/holub/mame
synced 2025-04-24 17:30:55 +03:00
More code alignment (windows/sdl). (nw)
This commit is contained in:
parent
fcdb51ef08
commit
4e94cc61de
@ -6,6 +6,16 @@
|
||||
#include "emu.h"
|
||||
#include "osdnet.h"
|
||||
|
||||
#define pcap_compile_dl pcap_compile
|
||||
#define pcap_findalldevs_dl pcap_findalldevs
|
||||
#define pcap_open_live_dl pcap_open_live
|
||||
#define pcap_next_ex_dl pcap_next_ex
|
||||
#define pcap_close_dl pcap_close
|
||||
#define pcap_setfilter_dl pcap_setfilter
|
||||
#define pcap_sendpacket_dl pcap_sendpacket
|
||||
#define pcap_set_datalink_dl pcap_set_datalink
|
||||
|
||||
|
||||
class netdev_pcap : public netdev
|
||||
{
|
||||
public:
|
||||
@ -24,16 +34,16 @@ netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev
|
||||
: netdev(ifdev, rate)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
|
||||
m_p = pcap_open_live_dl(name, 65535, 1, 1, errbuf);
|
||||
if(!m_p)
|
||||
{
|
||||
osd_printf_verbose("Unable to open %s: %s\n", name, errbuf);
|
||||
return;
|
||||
}
|
||||
if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
|
||||
if(pcap_set_datalink_dl(m_p, DLT_EN10MB) == -1)
|
||||
{
|
||||
osd_printf_verbose("Unable to set %s to ethernet", name);
|
||||
pcap_close(m_p);
|
||||
osd_printf_verbose("Unable to set %s to ethernet\n", name);
|
||||
pcap_close_dl(m_p);
|
||||
m_p = NULL;
|
||||
return;
|
||||
}
|
||||
@ -46,26 +56,30 @@ void netdev_pcap::set_mac(const char *mac)
|
||||
struct bpf_program fp;
|
||||
if(!m_p) return;
|
||||
sprintf(filter, "ether dst %.2X:%.2X:%.2X:%.2X:%.2X:%.2X or ether multicast or ether broadcast", (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5]);
|
||||
pcap_compile(m_p, &fp, filter, 1, 0);
|
||||
pcap_setfilter(m_p, &fp);
|
||||
if(pcap_compile_dl(m_p, &fp, filter, 1, 0) == -1) {
|
||||
osd_printf_verbose("Error with pcap_compile\n");
|
||||
}
|
||||
if(pcap_setfilter_dl(m_p, &fp) == -1) {
|
||||
osd_printf_verbose("Error with pcap_setfilter\n");
|
||||
}
|
||||
}
|
||||
|
||||
int netdev_pcap::send(UINT8 *buf, int len)
|
||||
{
|
||||
if(!m_p) return 0;
|
||||
return (!pcap_sendpacket(m_p, buf, len))?len:0;
|
||||
return (!pcap_sendpacket_dl(m_p, buf, len))?len:0;
|
||||
}
|
||||
|
||||
int netdev_pcap::recv_dev(UINT8 **buf)
|
||||
{
|
||||
struct pcap_pkthdr *header;
|
||||
if(!m_p) return 0;
|
||||
return (pcap_next_ex(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
|
||||
return (pcap_next_ex_dl(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
|
||||
}
|
||||
|
||||
netdev_pcap::~netdev_pcap()
|
||||
{
|
||||
if(m_p) pcap_close(m_p);
|
||||
if(m_p) pcap_close_dl(m_p);
|
||||
}
|
||||
|
||||
static CREATE_NETDEV(create_pcap)
|
||||
@ -78,20 +92,17 @@ void init_pcap()
|
||||
{
|
||||
pcap_if_t *devs;
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
if(pcap_findalldevs(&devs, errbuf) == -1)
|
||||
if(pcap_findalldevs_dl(&devs, errbuf) == -1)
|
||||
{
|
||||
osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
if (devs)
|
||||
{
|
||||
while(devs->next)
|
||||
{
|
||||
add_netdev(devs->name, devs->description, create_pcap);
|
||||
devs = devs->next;
|
||||
}
|
||||
}
|
||||
while(devs)
|
||||
{
|
||||
add_netdev(devs->name, devs->description, create_pcap);
|
||||
devs = devs->next;
|
||||
}
|
||||
}
|
||||
|
||||
void deinit_pcap()
|
||||
|
@ -8,6 +8,15 @@
|
||||
#include <pthread.h>
|
||||
#include <libkern/OSAtomic.h>
|
||||
|
||||
#define pcap_compile_dl pcap_compile
|
||||
#define pcap_findalldevs_dl pcap_findalldevs
|
||||
#define pcap_open_live_dl pcap_open_live
|
||||
#define pcap_next_ex_dl pcap_next_ex
|
||||
#define pcap_close_dl pcap_close
|
||||
#define pcap_setfilter_dl pcap_setfilter
|
||||
#define pcap_sendpacket_dl pcap_sendpacket
|
||||
#define pcap_set_datalink_dl pcap_set_datalink
|
||||
|
||||
struct netdev_pcap_context {
|
||||
UINT8 *pkt;
|
||||
int len;
|
||||
@ -61,16 +70,16 @@ netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev
|
||||
: netdev(ifdev, rate)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
|
||||
m_p = pcap_open_live_dl(name, 65535, 1, 1, errbuf);
|
||||
if(!m_p)
|
||||
{
|
||||
osd_printf_verbose("Unable to open %s: %s\n", name, errbuf);
|
||||
return;
|
||||
}
|
||||
if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
|
||||
if(pcap_set_datalink_dl(m_p, DLT_EN10MB) == -1)
|
||||
{
|
||||
osd_printf_verbose("Unable to set %s to ethernet\n", name);
|
||||
pcap_close(m_p);
|
||||
pcap_close_dl(m_p);
|
||||
m_p = NULL;
|
||||
return;
|
||||
}
|
||||
@ -88,10 +97,10 @@ void netdev_pcap::set_mac(const char *mac)
|
||||
struct bpf_program fp;
|
||||
if(!m_p) return;
|
||||
sprintf(filter, "not ether src %.2X:%.2X:%.2X:%.2X:%.2X:%.2X and (ether dst %.2X:%.2X:%.2X:%.2X:%.2X:%.2X or ether multicast or ether broadcast or ether dst 09:00:07:ff:ff:ff)", (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5], (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5]);
|
||||
if(pcap_compile(m_p, &fp, filter, 1, 0) == -1) {
|
||||
if(pcap_compile_dl(m_p, &fp, filter, 1, 0) == -1) {
|
||||
osd_printf_verbose("Error with pcap_compile\n");
|
||||
}
|
||||
if(pcap_setfilter(m_p, &fp) == -1) {
|
||||
if(pcap_setfilter_dl(m_p, &fp) == -1) {
|
||||
osd_printf_verbose("Error with pcap_setfilter\n");
|
||||
}
|
||||
}
|
||||
@ -99,7 +108,7 @@ void netdev_pcap::set_mac(const char *mac)
|
||||
int netdev_pcap::send(UINT8 *buf, int len)
|
||||
{
|
||||
if(!m_p) return 0;
|
||||
return (!pcap_sendpacket(m_p, buf, len))?len:0;
|
||||
return (!pcap_sendpacket_dl(m_p, buf, len))?len:0;
|
||||
}
|
||||
|
||||
int netdev_pcap::recv_dev(UINT8 **buf)
|
||||
@ -121,7 +130,7 @@ int netdev_pcap::recv_dev(UINT8 **buf)
|
||||
|
||||
netdev_pcap::~netdev_pcap()
|
||||
{
|
||||
if(m_p) pcap_close(m_p);
|
||||
if(m_p) pcap_close_dl(m_p);
|
||||
}
|
||||
|
||||
static CREATE_NETDEV(create_pcap)
|
||||
@ -134,12 +143,19 @@ void init_pcap()
|
||||
{
|
||||
pcap_if_t *devs;
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
if(pcap_findalldevs(&devs, errbuf) == -1)
|
||||
if(pcap_findalldevs_dl(&devs, errbuf) == -1)
|
||||
{
|
||||
osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
while(devs)
|
||||
{
|
||||
add_netdev(devs->name, devs->description, create_pcap);
|
||||
devs = devs->next;
|
||||
}
|
||||
#else
|
||||
if (devs)
|
||||
{
|
||||
while(devs->next)
|
||||
@ -148,6 +164,7 @@ void init_pcap()
|
||||
devs = devs->next;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void deinit_pcap()
|
||||
|
@ -102,45 +102,3 @@ char *osd_get_clipboard_text(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// astring_from_utf8
|
||||
//============================================================
|
||||
|
||||
CHAR *astring_from_utf8(const char *utf8string)
|
||||
{
|
||||
WCHAR *wstring;
|
||||
int char_count;
|
||||
CHAR *result;
|
||||
|
||||
// convert MAME string (UTF-8) to UTF-16
|
||||
char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
|
||||
wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
|
||||
|
||||
// convert UTF-16 to "ANSI code page" string
|
||||
char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, NULL, 0, NULL, NULL);
|
||||
result = (CHAR *)osd_malloc_array(char_count * sizeof(*result));
|
||||
if (result != NULL)
|
||||
WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, NULL, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// wstring_from_utf8
|
||||
//============================================================
|
||||
|
||||
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_array(char_count * sizeof(*result));
|
||||
if (result != NULL)
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,46 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Aaron Giles
|
||||
//============================================================
|
||||
//
|
||||
// strconv.c - SDL (POSIX) string conversion
|
||||
//
|
||||
// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
|
||||
// Visit http://mamedev.org for licensing and usage restrictions.
|
||||
//
|
||||
// SDLMAME by Olivier Galibert and R. Belmont
|
||||
// strconv.c - Win32 string conversion
|
||||
//
|
||||
//============================================================
|
||||
|
||||
#ifdef SDLMAME_WIN32
|
||||
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// MAMEOS headers
|
||||
#include "strconv.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#ifdef SDLMAME_WIN32
|
||||
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
|
||||
//============================================================
|
||||
// astring_from_utf8
|
||||
//============================================================
|
||||
|
||||
CHAR *astring_from_utf8(const char *utf8string)
|
||||
{
|
||||
WCHAR *wstring;
|
||||
int char_count;
|
||||
CHAR *result;
|
||||
|
||||
// convert MAME string (UTF-8) to UTF-16
|
||||
char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
|
||||
wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
|
||||
|
||||
// convert UTF-16 to "ANSI code page" string
|
||||
char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, NULL, 0, NULL, NULL);
|
||||
result = (CHAR *)osd_malloc_array(char_count * sizeof(*result));
|
||||
if (result != NULL)
|
||||
WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, NULL, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// utf8_from_astring
|
||||
//============================================================
|
||||
@ -45,6 +65,26 @@ char *utf8_from_astring(const CHAR *astring)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// wstring_from_utf8
|
||||
//============================================================
|
||||
|
||||
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_array(char_count * sizeof(*result));
|
||||
if (result != NULL)
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// utf8_from_wstring
|
||||
//============================================================
|
||||
@ -62,7 +102,24 @@ char *utf8_from_wstring(const WCHAR *wstring)
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
//============================================================
|
||||
// osd_uchar_from_osdchar
|
||||
//============================================================
|
||||
|
||||
int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
WCHAR wch;
|
||||
|
||||
count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
|
||||
if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
return (int) count;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//============================================================
|
||||
// osd_uchar_from_osdchar
|
||||
@ -70,13 +127,15 @@ char *utf8_from_wstring(const WCHAR *wstring)
|
||||
|
||||
int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
wchar_t wch;
|
||||
wchar_t wch;
|
||||
|
||||
count = mbstowcs(&wch, (char *)osdchar, 1);
|
||||
if (count != -1)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
count = mbstowcs(&wch, (char *)osdchar, 1);
|
||||
if (count != -1)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -112,13 +112,13 @@ void init_pcap()
|
||||
catch (DWORD e)
|
||||
{
|
||||
FreeLibrary(handle);
|
||||
osd_printf_verbose("Unable to load winpcap: %lx\n", e);
|
||||
osd_printf_warning("Unable to load winpcap: %lx\n", e);
|
||||
return;
|
||||
}
|
||||
if(pcap_findalldevs_dl(&devs, errbuf) == -1)
|
||||
{
|
||||
FreeLibrary(handle);
|
||||
osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
|
||||
osd_printf_warning("Unable to get network devices: %s\n", errbuf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,16 @@
|
||||
//
|
||||
//============================================================
|
||||
|
||||
// standard windows headers
|
||||
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
// MAMEOS headers
|
||||
#include "strconv.h"
|
||||
#include "unicode.h"
|
||||
|
||||
|
||||
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
|
||||
//============================================================
|
||||
// astring_from_utf8
|
||||
//============================================================
|
||||
@ -101,3 +102,40 @@ char *utf8_from_wstring(const WCHAR *wstring)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_uchar_from_osdchar
|
||||
//============================================================
|
||||
|
||||
int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
WCHAR wch;
|
||||
|
||||
count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
|
||||
if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
return (int) count;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//============================================================
|
||||
// osd_uchar_from_osdchar
|
||||
//============================================================
|
||||
|
||||
int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
wchar_t wch;
|
||||
|
||||
count = mbstowcs(&wch, (char *)osdchar, 1);
|
||||
if (count != -1)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -382,23 +382,6 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// osd_uchar_from_osdchar
|
||||
//============================================================
|
||||
|
||||
int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
WCHAR wch;
|
||||
|
||||
count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
|
||||
if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
|
||||
*uchar = wch;
|
||||
else
|
||||
*uchar = 0;
|
||||
return (int) count;
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// create_path_recursive
|
||||
//============================================================
|
||||
|
Loading…
Reference in New Issue
Block a user