Difference between revisions of "Guides:MAME - Networking"

From Wah!ki
Jump to navigation Jump to search
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
just notes here
+
== (Ether)net Networking in MAME ==
 +
Support was added back in ~2012 but the documentation is fragmented.
  
 +
Note alot of older posts say to compile with USE_NETWORK=1, this is no longer required as it became the default in [https://www.mamedev.org/releases/whatsnew_0156.txt 0.156]
  
compile with USE_NETWORK=1
+
Very basically you will
 +
* give the MAME machine a static ip internally,
 +
on the host
 +
* tweak some ipv4 network behavior
 +
* create a basic tap device
 +
* route traffic out the hosts eth int
  
OSD_NET_USE_TAPTUN=1 might be required as well to pull in the drive
+
MAME only looks at the /dev/net/tun device currently (0.229) with a specific naming convention so it wont support macvtap devices etc atm.
  
 +
The naming convention (commit [https://github.com/mamedev/mame/blob/2ca5f3a386a1ca63433d6d13bb66f5e46fb2a854/src/osd/modules/netdev/taptun.cpp 2ca5f3a]) of the tap device seems to be important, otherwise MAME doesn't seem to know what to use. Its not a parameter we can pass into the machine, this probably limits the possiblities of building networks between MAME machines
 
  <nowiki>
 
  <nowiki>
#if defined(OSD_NET_USE_TAPTUN)
+
/src/osd/modules/netdev/taptun.cpp
 +
91: sprintf(ifr.ifr_name, "tap-mess-%d-0", getuid());
 
</nowiki>
 
</nowiki>
  
mame -listnetworks (should show the available devices, not just TAP/TUN ?)
 
  
 +
=== List MAME Networks ===
 +
mame -listnetwork will display available devices as per below
 +
<nowiki>
 +
$ ./mame -listnetwork
 +
Available network adapters:
 +
    TAP/TUN Device
 +
</nowiki>
 +
 +
 +
=== tap device setup ===
 +
==== Review ====
 +
Check and record your current settings
 +
<nowiki>
 +
  $ cat /proc/sys/net/ipv4/ip_forward
 +
  $ cat /proc/sys/net/ipv4/conf/all/proxy_arp
 +
</nowiki>
  
 +
==== Manual setup ====
 +
# Allow forwarded traffic, and proxied arp requests
 +
# Create a tap device and route traffic across you host ethernet
 +
# confirm you have read access to the /dev/net/tun device
 +
<nowiki>
 +
  $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
 +
  $ echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/proxy_arp
 +
  $ sudo chmod 666 /dev/net/tun
  
tap/tun device
+
  $ MAMESTATIC=192.168.0.102
 +
  $ HOSTIP=192.168.0.200
 +
  $ TAP=tap-mess-$UID-0
 +
  $ USERNAME=$(whoami)
 +
  $ sudo ip tuntap add dev $TAP mode tap user $USERNAME
 +
  $ sudo ip link set $TAP up arp on
 +
  $ sudo ip addr replace dev $TAP $HOSTIP/32
 +
  $ sudo ip route replace $MAMESTATIC via $HOSTIP dev $TAP
  
 +
  $ ip link show $TAP
 +
  $ ip route
 +
</nowiki>
  
 +
==== MAME Script ====
 +
MAME has a script in the git repo /src/osd/sdl/taputil.sh
 +
 +
The format to execute this is
 +
<nowiki>
 +
sudo taputil.sh <mame user> <mame machine ip> <host machine ip>
 +
</nowiki>
  
dos ne2000
+
'''NOTE:''' be mindful of this script, it will not honor existing tap perms nor kernel settings see [https://github.com/mamedev/mame/issues/7877 #7877]
* ne2000.com 0x60
 
  
 +
==== MAME Setup ====
 +
In the in-game UI
 +
* open the Network Devices menu and select "TAP/TUN Device"
 +
* Confirm the IRQ under machine configuration is correct
  
Drivers/Software
+
===== IRQs =====
* https://dos.retro.software/downloads/category/300-ne2000-compatible-nic-drivers
+
Just a note on my config,
* https://www.brutman.com/mTCP/mTCP.html
+
* ISA1 svga_s1,
 +
* ISA2, sblaster_16 (IRQ5)
 +
* ISA4 ne2000.  
  
 +
The IRQ used by the ne2000 adapter would only work on IRQ2/9
  
 +
==== DOS Setup ====
 +
Load the ne2000 drivers from in autoexec.bat, try auto discovery first
 +
<nowiki>
 +
c:\PATH\TO\NE2000.COM 0x60
 +
</nowiki>
  
 +
To do a fixed IRQ that can be mapped in MAME machine configuration
 
  <nowiki>
 
  <nowiki>
sudo ip link add link enp4s0 name mametap0 type macvtap
+
c:\PATH\TO\NE2000.COM 0x60 3 0x300
sudo ip link set mametap0 address 00:00:1B:4A:3A:F2 up
 
ip link show mametap0
 
 
</nowiki>
 
</nowiki>
  
 +
The entry after the 0x60 is the target irq you then map in MAME machine configuration
 +
 +
A decent test suite of tools while getting setup is the mTCP project, refer to their doco to setup the config etc. but remove LEASE_TIME from the ip settings to set a static ip for use with the applications otherwise the applications will throw a lease expired warning and exit
 +
 +
=== When done ===
 +
==== Disable support ====
 +
# When you are done, you can leave the tuntap device around for later but I'd suggest disabling the ip_forward and proxy_arp while you're not using it.
 
  <nowiki>
 
  <nowiki>
sudo ip link delete mametap0
+
  $ echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
 +
  $ echo 0 | sudo tee /proc/sys/net/ipv4/conf/all/proxy_arp
 
</nowiki>
 
</nowiki>
  
 +
make sure you reenstate you're old settings you recorded if they are different
 +
 +
===== Remove the tuntap device =====
 
  <nowiki>
 
  <nowiki>
sudo ip tuntap del dev mametap0 mode tap group netdev
+
  $ sudo ip tuntap del $TAP mode tap
sudo ip tuntap del dev mametap0 mode tap
 
 
</nowiki>
 
</nowiki>
  
 +
== Drivers/Software ==
 +
* https://dos.retro.software/downloads/category/300-ne2000-compatible-nic-drivers
 +
* https://www.brutman.com/mTCP/mTCP.html
  
References
+
== References ==
 +
* https://www.brutman.com/mTCP/
 
* https://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=115314
 
* https://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=115314
 
* https://www.naturalborncoder.com/virtualization/2014/10/17/understanding-tun-tap-interfaces/
 
* https://www.naturalborncoder.com/virtualization/2014/10/17/understanding-tun-tap-interfaces/
Line 50: Line 123:
 
* https://github.com/mamedev/mame/tree/2ca5f3a386a1ca63433d6d13bb66f5e46fb2a854/src/osd/modules/netdev
 
* https://github.com/mamedev/mame/tree/2ca5f3a386a1ca63433d6d13bb66f5e46fb2a854/src/osd/modules/netdev
 
* https://dfarq.homeip.net/using-an-ne2000-network-card-in-dos/
 
* https://dfarq.homeip.net/using-an-ne2000-network-card-in-dos/
 +
* http://mess.redump.net/howto/apollo
 +
* https://www.brutman.com/Dos_Networking/dos_networking.html
 +
* https://www.stimpyrama.org/downloads/download/8-unsorted/666-xfs191

Latest revision as of 23:44, 5 March 2022

(Ether)net Networking in MAME

Support was added back in ~2012 but the documentation is fragmented.

Note alot of older posts say to compile with USE_NETWORK=1, this is no longer required as it became the default in 0.156

Very basically you will

  • give the MAME machine a static ip internally,

on the host

  • tweak some ipv4 network behavior
  • create a basic tap device
  • route traffic out the hosts eth int

MAME only looks at the /dev/net/tun device currently (0.229) with a specific naming convention so it wont support macvtap devices etc atm.

The naming convention (commit 2ca5f3a) of the tap device seems to be important, otherwise MAME doesn't seem to know what to use. Its not a parameter we can pass into the machine, this probably limits the possiblities of building networks between MAME machines

/src/osd/modules/netdev/taptun.cpp
91: sprintf(ifr.ifr_name, "tap-mess-%d-0", getuid());


List MAME Networks

mame -listnetwork will display available devices as per below

$ ./mame -listnetwork
Available network adapters:
    TAP/TUN Device


tap device setup

Review

Check and record your current settings

  $ cat /proc/sys/net/ipv4/ip_forward
  $ cat /proc/sys/net/ipv4/conf/all/proxy_arp

Manual setup

  1. Allow forwarded traffic, and proxied arp requests
  2. Create a tap device and route traffic across you host ethernet
  3. confirm you have read access to the /dev/net/tun device
  $ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
  $ echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/proxy_arp
  $ sudo chmod 666 /dev/net/tun

  $ MAMESTATIC=192.168.0.102
  $ HOSTIP=192.168.0.200
  $ TAP=tap-mess-$UID-0
  $ USERNAME=$(whoami)
  $ sudo ip tuntap add dev $TAP mode tap user $USERNAME
  $ sudo ip link set $TAP up arp on
  $ sudo ip addr replace dev $TAP $HOSTIP/32
  $ sudo ip route replace $MAMESTATIC via $HOSTIP dev $TAP 

  $ ip link show $TAP
  $ ip route

MAME Script

MAME has a script in the git repo /src/osd/sdl/taputil.sh

The format to execute this is

sudo taputil.sh <mame user> <mame machine ip> <host machine ip>

NOTE: be mindful of this script, it will not honor existing tap perms nor kernel settings see #7877

MAME Setup

In the in-game UI

  • open the Network Devices menu and select "TAP/TUN Device"
  • Confirm the IRQ under machine configuration is correct
IRQs

Just a note on my config,

  • ISA1 svga_s1,
  • ISA2, sblaster_16 (IRQ5)
  • ISA4 ne2000.

The IRQ used by the ne2000 adapter would only work on IRQ2/9

DOS Setup

Load the ne2000 drivers from in autoexec.bat, try auto discovery first

c:\PATH\TO\NE2000.COM 0x60

To do a fixed IRQ that can be mapped in MAME machine configuration

c:\PATH\TO\NE2000.COM 0x60 3 0x300

The entry after the 0x60 is the target irq you then map in MAME machine configuration

A decent test suite of tools while getting setup is the mTCP project, refer to their doco to setup the config etc. but remove LEASE_TIME from the ip settings to set a static ip for use with the applications otherwise the applications will throw a lease expired warning and exit

When done

Disable support

  1. When you are done, you can leave the tuntap device around for later but I'd suggest disabling the ip_forward and proxy_arp while you're not using it.
  $ echo 0 | sudo tee /proc/sys/net/ipv4/ip_forward
  $ echo 0 | sudo tee /proc/sys/net/ipv4/conf/all/proxy_arp

make sure you reenstate you're old settings you recorded if they are different

Remove the tuntap device
  $ sudo ip tuntap del $TAP mode tap

Drivers/Software

References