Previous 15994 Revisions Next

r13515 Thursday 8th December, 2011 at 13:59:13 UTC by Miodrag Milanović
Added network menu and configuration save (no whatsnew)
note: let's test this first in mess before it's merged to core
[src/emu]dinetwork.c dinetwork.h emu.h emu.mak machine.c network.c* network.h* uimain.c
[src/mess/machine]3c503.c ne1000.c ne2000.c nubus_asntmc3b.c x68k_neptunex.c x68k_neptunex.h
[src/osd]osdnet.c osdnet.h
[src/osd/sdl]netdev_pcap.c netdev_tap.c
[src/osd/windows]netdev_pcap.c

src/osd/osdnet.h
r13514r13515
33#ifndef __OSDNET_H__
44#define __OSDNET_H__
55
6class netdev;
7
8#define CREATE_NETDEV(name) class netdev *name(const char *ifname, class device_network_interface *ifdev, int rate)
9typedef class netdev *(*create_netdev)(const char *ifname, class device_network_interface *ifdev, int rate);
10
11typedef struct netdev_entry
12{
13   int id;
14   char name[256];
15   char description[256];
16   create_netdev func;
17   struct netdev_entry *m_next;
18} netdev_entry_t;
19
620class netdev
721{
822public:
r13514r13515
2539   class device_network_interface *m_dev;
2640};
2741
28#define CREATE_NETDEV(name) class netdev *name(const char *ifname, class device_network_interface *ifdev, int rate)
29typedef class netdev *(*create_netdev)(const char *ifname, class device_network_interface *ifdev, int rate);
30
3142class netdev *open_netdev(int id, class device_network_interface *ifdev, int rate);
32void add_netdev(const char *name, create_netdev func);
43void add_netdev(const char *name, const char *description, create_netdev func);
3344void clear_netdev();
45const netdev_entry_t *netdev_first();
46int netdev_count();
3447#endif
src/osd/sdl/netdev_pcap.c
r13514r13515
8888   {
8989       while(devs->next)
9090       {
91          add_netdev(devs->name, create_pcap);
91          add_netdev(devs->name, devs->description, create_pcap);
9292          devs = devs->next;
9393       }
9494    }
src/osd/sdl/netdev_tap.c
r13514r13515
9494
9595void init_tap()
9696{
97   add_netdev("tap", create_tap);
97   add_netdev("tap", "TAP/TUN Device", create_tap);
9898}
9999
100100void deinit_tap()
src/osd/windows/netdev_pcap.c
r13514r13515
127127   {
128128      while(devs->next)
129129      {
130         add_netdev(devs->name, create_pcap);
130         add_netdev(devs->name, devs->description, create_pcap);
131131         devs = devs->next;
132132      }
133133   }
src/osd/osdnet.c
r13514r13515
11#include "emu.h"
22#include "osdnet.h"
33
4typedef struct netdev_entry
5{
6   int id;
7   char name[256];
8   create_netdev func;
9   struct netdev_entry *m_next;
10} netdev_entry_t;
11
124static class simple_list<netdev_entry_t> netdev_list;
135
14void add_netdev(const char *name, create_netdev func)
6void add_netdev(const char *name, const char *description, create_netdev func)
157{
168   netdev_entry_t *entry = global_alloc_clear(netdev_entry_t);
179   entry->id = netdev_list.count();
1810   strncpy(entry->name, name, 255);
1911   entry->name[255] = '\0';
12   strncpy(entry->description, description, 255);
13   entry->description[255] = '\0';
2014   entry->func = func;
2115   netdev_list.append(*entry);
2216}
r13514r13515
2620   netdev_list.reset();
2721}
2822
23const netdev_entry_t *netdev_first() {
24   return netdev_list.first();
25}
26
2927class netdev *open_netdev(int id, class device_network_interface *ifdev, int rate)
3028{
3129   netdev_entry_t *entry = netdev_list.first();
r13514r13515
9795   return "\0\0\0\0\0\0";
9896}
9997
98int netdev_count()
99{
100   return netdev_list.count();
101}
src/emu/dinetwork.c
r13514r13515
88   m_dev = NULL;
99   m_bandwidth = bandwidth;
1010   set_mac("\0\0\0\0\0\0");
11   m_intf = 0;
1112}
1213
1314device_network_interface::~device_network_interface()
r13514r13515
4647void device_network_interface::set_interface(int id)
4748{
4849   m_dev = open_netdev(id, this, (int)(m_bandwidth*1000000/8.0/1500));
49   if(!m_dev)
50   if(!m_dev) {
5051      logerror("Network interface %d not found\n", id);
52      id = -1;
53   }
54   m_intf = id;
5155}
src/emu/dinetwork.h
r13514r13515
1515
1616   const char *get_mac() { return m_mac; }
1717   bool get_promisc() { return m_promisc; }
18   int get_interface() { return m_intf; }
1819
1920   int send(UINT8 *buf, int len);
2021   virtual void recv_cb(UINT8 *buf, int len);
r13514r13515
2526   char m_mac[6];
2627   float m_bandwidth;
2728   class netdev *m_dev;
29   int m_intf;
2830};
2931#endif
src/emu/network.c
r0r13515
1/***************************************************************************
2
3    network.c
4
5    Core network functions and definitions.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11#include <ctype.h>
12
13#include "emu.h"
14#include "emuopts.h"
15#include "network.h"
16#include "config.h"
17#include "xmlfile.h"
18
19/***************************************************************************
20    INITIALIZATION HELPERS
21***************************************************************************/
22
23static void network_load(running_machine &machine, int config_type, xml_data_node *parentnode)
24{
25   xml_data_node *node;
26   device_network_interface *network = NULL;
27   if ((config_type == CONFIG_TYPE_GAME) && (parentnode != NULL))
28   {
29      for (node = xml_get_sibling(parentnode->child, "device"); node; node = xml_get_sibling(node->next, "device"))
30      {
31         const char *tag = xml_get_attribute_string(node, "tag", NULL);
32
33         if ((tag != NULL) && (tag[0] != '\0'))
34         {
35            for (bool gotone = machine.devicelist().first(network); gotone; gotone = network->next(network))
36            {
37               if (!strcmp(tag, network->device().tag())) {
38                  int interface = xml_get_attribute_int(node, "interface", 0);
39                  network->set_interface(interface);
40                  const char *mac_addr = xml_get_attribute_string(node, "mac", NULL);
41                  if (mac_addr != NULL && strlen(mac_addr)==17) {
42                     char mac[7];
43                     unsigned int mac_num[6];
44                     sscanf (mac_addr,"%02x:%02x:%02x:%02x:%02x:%02x",&mac_num[0],&mac_num[1],&mac_num[2],&mac_num[3],&mac_num[4],&mac_num[5]);
45                     for (int i=0;i<6;i++) mac[i]=mac_num[i];
46                     network->set_mac(mac);
47                  }
48                 
49               }
50            }
51         }
52      }
53   }
54}
55
56static void network_save(running_machine &machine, int config_type, xml_data_node *parentnode)
57{
58   xml_data_node *node;
59   device_network_interface *network = NULL;
60
61   /* only care about game-specific data */
62   if (config_type == CONFIG_TYPE_GAME)
63   {
64      for (bool gotone = machine.devicelist().first(network); gotone; gotone = network->next(network))
65      {
66         node = xml_add_child(parentnode, "device", NULL);
67         if (node != NULL)
68         {
69            xml_set_attribute(node, "tag", network->device().tag());
70            xml_set_attribute_int(node, "interface", network->get_interface());
71            const char *mac = network->get_mac();
72            char mac_addr[6*3];
73            sprintf(mac_addr,"%02x:%02x:%02x:%02x:%02x:%02x",(UINT8)mac[0],(UINT8)mac[1],(UINT8)mac[2],(UINT8)mac[3],(UINT8)mac[4],(UINT8)mac[5]);
74            xml_set_attribute(node, "mac", mac_addr);
75         }
76      }
77   }
78}
79
80/***************************************************************************
81    INITIALIZATION
82***************************************************************************/
83
84/*-------------------------------------------------
85    network_init - start up the network system
86-------------------------------------------------*/
87
88void network_init(running_machine &machine)
89{
90   config_register(machine, "network", config_saveload_delegate(FUNC(network_load), &machine), config_saveload_delegate(FUNC(network_save), &machine));
91}
src/emu/network.h
r0r13515
1/***************************************************************************
2
3    network.h
4
5    Core network interface functions and definitions.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#pragma once
13
14#ifndef __EMU_H__
15#error Dont include this file directly; include emu.h instead.
16#endif
17
18#ifndef __NETWORK_H__
19#define __NETWORK_H__
20
21void network_init(running_machine &machine);
22
23#endif /* __NETWORK_H__ */
src/emu/emu.h
r13514r13515
114114#include "softlist.h"
115115#include "image.h"
116116
117// networking
118#include "network.h"
119
117120// the running machine
118121#include "machine.h"
119122#include "mame.h"
src/emu/machine.c
r13514r13515
308308   image_init(*this);
309309   tilemap_init(*this);
310310   crosshair_init(*this);
311   network_init(*this);
311312
312313   // initialize the debugger
313314   if ((debug_flags & DEBUG_FLAG_ENABLED) != 0)
src/emu/uimain.c
r13514r13515
1010*********************************************************************/
1111
1212#include "emu.h"
13#include "osdnet.h"
1314#include "emuopts.h"
1415#include "ui.h"
1516#include "rendutil.h"
r13514r13515
489490
490491
491492/*-------------------------------------------------
493    menu_network_devices_populate - populates the main
494    network device menu
495-------------------------------------------------*/
496
497static void menu_network_devices_populate(running_machine &machine, ui_menu *menu, void *state)
498{
499   device_network_interface *network = NULL;
500
501   /* cycle through all devices for this system */
502   for (bool gotone = machine.devicelist().first(network); gotone; gotone = network->next(network))
503   {
504      int curr = network->get_interface();
505      const char *title = NULL;
506      const netdev_entry_t *entry = netdev_first();
507      while(entry) {
508         if(entry->id==curr) {
509            title = entry->description;
510            break;
511         }         
512         entry = entry->m_next;
513      }
514     
515      menu->item_append(network->device().tag(),  (title) ? title : "------", MENU_FLAG_LEFT_ARROW | MENU_FLAG_RIGHT_ARROW, (void *)network);     
516   }
517}
518
519/*-------------------------------------------------
520    ui_menu_network_devices - menu that
521-------------------------------------------------*/
522
523static void ui_menu_network_devices(running_machine &machine, ui_menu *menu, void *parameter, void *state)
524{
525   const ui_menu_event *menu_event;
526
527   /* if the menu isn't built, populate now */
528   if (!menu->populated())
529   {
530      menu_network_devices_populate(machine, menu, state);
531   }
532
533   /* process the menu */
534   menu_event = menu->process(0);
535
536   if (menu_event != NULL && menu_event->itemref != NULL)
537   {
538      if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT) {
539         device_network_interface *network = (device_network_interface *)menu_event->itemref;
540         int curr = network->get_interface();
541         if (menu_event->iptkey == IPT_UI_LEFT) curr--; else curr++;
542         if (curr==-2) curr = netdev_count() - 1;
543         network->set_interface(curr);
544         menu->reset(UI_MENU_RESET_REMEMBER_REF);
545      }
546   }
547}
548
549/*-------------------------------------------------
492550    menu_main_populate - populate the main menu
493551-------------------------------------------------*/
494552
r13514r13515
558616      menu->item_append("Slot Devices", NULL, 0, (void*)ui_menu_slot_devices);
559617   }
560618
619   device_network_interface *network = NULL;
620   if (machine.devicelist().first(network))
621   {
622      /* add image info menu */
623      menu->item_append("Network Devices", NULL, 0, (void*)ui_menu_network_devices);
624   }
625
561626   /* add keyboard mode menu */
562627   if (input_machine_has_keyboard(machine) && inputx_can_post(machine))
563628      menu->item_append("Keyboard Mode", NULL, 0, (void *)ui_menu_keyboard_mode);
src/emu/emu.mak
r13514r13515
8686   $(EMUOBJ)/machine.o \
8787   $(EMUOBJ)/mconfig.o \
8888   $(EMUOBJ)/memory.o \
89   $(EMUOBJ)/network.o \
8990   $(EMUOBJ)/output.o \
9091   $(EMUOBJ)/render.o \
9192   $(EMUOBJ)/rendfont.o \
src/mess/machine/ne1000.c
r13514r13515
2828void ne1000_device::device_start() {
2929   char mac[7];
3030   UINT32 num = rand();
31   m_dp8390->set_interface(0); // XXX make user configurable
3231   memset(m_prom, 0x57, 16);
3332   sprintf(mac+2, "\x1b%c%c%c", (num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff);
3433   mac[0] = 0; mac[1] = 0;  // avoid gcc warning
3534   memcpy(m_prom, mac, 6);
35   m_dp8390->set_mac(mac);
3636   set_isa_device();
3737   m_isa->install_device(0x0300, 0x031f, 0, 0, read8_delegate(FUNC(ne1000_device::ne1000_port_r), this), write8_delegate(FUNC(ne1000_device::ne1000_port_w), this));
3838}
3939
4040void ne1000_device::device_reset() {
41   memcpy(m_prom, m_dp8390->get_mac(), 6);
4142}
4243
4344READ8_MEMBER(ne1000_device::ne1000_port_r) {
src/mess/machine/x68k_neptunex.c
r13514r13515
4949   UINT32 num = rand();
5050   address_space* space = cpu->memory().space(AS_PROGRAM);
5151   m_slot = dynamic_cast<x68k_expansion_slot_device *>(owner());
52   m_dp8390->set_interface(0); // XXX make user configurable
5352   memset(m_prom, 0x57, 16);
5453   sprintf(mac+2, "\x1b%c%c%c", (num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff);
5554   mac[0] = 0; mac[1] = 0;  // avoid gcc warning
5655   memcpy(m_prom, mac, 6);
56   m_dp8390->set_mac(mac);
5757   space->install_readwrite_handler(0xece000,0xece3ff,read16_delegate(FUNC(x68k_neptune_device::x68k_neptune_port_r),this),write16_delegate(FUNC(x68k_neptune_device::x68k_neptune_port_w),this),0xffffffff);
5858}
5959
60void x68k_neptune_device::device_reset() {
61   memcpy(m_prom, m_dp8390->get_mac(), 6);
62}
63
6064READ16_MEMBER(x68k_neptune_device::x68k_neptune_port_r)
6165{
6266   UINT16 data;
src/mess/machine/x68k_neptunex.h
r13514r13515
3636protected:
3737   // device-level overrides
3838   virtual void device_start();
39   virtual void device_reset() {};
39   virtual void device_reset();
4040    virtual void device_config_complete() { m_shortname = "x68k_neptunex"; }
4141
4242private:
src/mess/machine/3c503.c
r13514r13515
3030void el2_3c503_device::device_start() {
3131   char mac[7];
3232   UINT32 num = rand();
33   m_dp8390->set_interface(0); // XXX make user configurable
3433   memset(m_prom, 0x57, 16);
3534   sprintf(mac, "\x02\x60\x8c%c%c%c", (num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff);
3635   memcpy(m_prom, mac, 6);
3736   memset(m_rom, 0, 8*1024); // empty
38
37   m_dp8390->set_mac(mac);
3938   set_isa_device();
4039   m_isa->install_device(0x0300, 0x030f, 0, 0, read8_delegate(FUNC(el2_3c503_device::el2_3c503_loport_r), this), write8_delegate(FUNC(el2_3c503_device::el2_3c503_loport_w), this));
4140   m_isa->install_device(0x0700, 0x070f, 0, 0, read8_delegate(FUNC(el2_3c503_device::el2_3c503_hiport_r), this), write8_delegate(FUNC(el2_3c503_device::el2_3c503_hiport_w), this));
4241}
4342
4443void el2_3c503_device::device_reset() {
44   memcpy(m_prom, m_dp8390->get_mac(), 6);
4545   memset(&m_regs, 0, sizeof(m_regs));
4646   m_regs.bcfr = 0x80; // port 0x300
4747   m_regs.pcfr = 0x20; // address 0xcc000
src/mess/machine/ne2000.c
r13514r13515
2828void ne2000_device::device_start() {
2929   char mac[7];
3030   UINT32 num = rand();
31   m_dp8390->set_interface(0); // XXX make user configurable
3231   memset(m_prom, 0x57, 16);
3332   sprintf(mac+2, "\x1b%c%c%c", (num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff);
3433   mac[0] = 0; mac[1] = 0;  // avoid gcc warning
3534   memcpy(m_prom, mac, 6);
35   m_dp8390->set_mac(mac);
3636   set_isa_device();
37   m_isa->install16_device(0x0300, 0x031f, 0, 0, read16_delegate(FUNC(ne2000_device::ne2000_port_r), this), write16_delegate(FUNC(ne2000_device::ne2000_port_w), this));
37   m_isa->install16_device(0x0300, 0x031f, 0, 0, read16_delegate(FUNC(ne2000_device::ne2000_port_r), this), write16_delegate(FUNC(ne2000_device::ne2000_port_w), this));   
3838}
3939
4040void ne2000_device::device_reset() {
41   memcpy(m_prom, m_dp8390->get_mac(), 6);
4142}
4243
4344READ16_MEMBER(ne2000_device::ne2000_port_r) {
src/mess/machine/nubus_asntmc3b.c
r13514r13515
106106   UINT32 slotspace;
107107   char mac[7];
108108   UINT32 num = rand();
109   m_dp83902->set_interface(0); // XXX make user configurable
110109   memset(m_prom, 0x57, 16);
111110   sprintf(mac+2, "\x1b%c%c%c", (num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff);
112111   mac[0] = mac[1] = 0;  // avoid gcc warning
113112   memcpy(m_prom, mac, 6);
114
113   m_dp83902->set_mac(mac);
115114   // set_nubus_device makes m_slot valid
116115   set_nubus_device();
117116   install_declaration_rom(this, MAC8390_ROM_REGION, true);
r13514r13515
136135{
137136    m_dp83902->dp8390_reset(0);
138137    m_dp83902->dp8390_cs(0);
138   memcpy(m_prom, m_dp83902->get_mac(), 6);
139139}
140140
141141WRITE8_MEMBER( nubus_mac8390_device::asntm3b_ram_w )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team