Skip to content

Commit

Permalink
osd/osdnet.cpp: Removed dependency from OSD network device to libemu.
Browse files Browse the repository at this point in the history
Minimal changes to get taptun working on Windows.
Other configurations may be broken.
  • Loading branch information
cuavas committed Feb 23, 2024
1 parent a27f84f commit b220d5b
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 125 deletions.
2 changes: 2 additions & 0 deletions scripts/src/osd/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function osdmodulesbuild()
MAME_DIR .. "src/osd/interface/inputman.h",
MAME_DIR .. "src/osd/interface/inputseq.cpp",
MAME_DIR .. "src/osd/interface/inputseq.h",
MAME_DIR .. "src/osd/interface/nethandler.cpp",
MAME_DIR .. "src/osd/interface/nethandler.h",
MAME_DIR .. "src/osd/modules/debugger/debug_module.h",
MAME_DIR .. "src/osd/modules/debugger/debuggdbstub.cpp",
MAME_DIR .. "src/osd/modules/debugger/debugimgui.cpp",
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bus/isa/3c503.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void el2_3c503_device::device_start() {
}

void el2_3c503_device::device_reset() {
memcpy(m_prom, m_dp8390->get_mac(), 6);
memcpy(m_prom, &m_dp8390->get_mac()[0], 6);
memset(&m_regs, 0, sizeof(m_regs));
m_regs.bcfr = 0x80; // port 0x300
m_regs.pcfr = 0x20; // address 0xcc000
Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/isa/ne1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void ne1000_device::device_add_mconfig(machine_config &config)
m_dp8390->mem_write_callback().set(FUNC(ne1000_device::ne1000_mem_write));
}

ne1000_device::ne1000_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, NE1000, tag, owner, clock),
ne1000_device::ne1000_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, NE1000, tag, owner, clock),
device_isa8_card_interface(mconfig, *this),
m_dp8390(*this, "dp8390d"),
m_irq(0)
Expand All @@ -38,7 +38,7 @@ void ne1000_device::device_start() {
}

void ne1000_device::device_reset() {
memcpy(m_prom, m_dp8390->get_mac(), 6);
memcpy(m_prom, &m_dp8390->get_mac()[0], 6);
m_irq = ioport("CONFIG")->read() & 3;
}

Expand Down
6 changes: 3 additions & 3 deletions src/devices/bus/isa/ne2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void ne2000_device::device_add_mconfig(machine_config &config)
m_dp8390->mem_write_callback().set(FUNC(ne2000_device::ne2000_mem_write));
}

ne2000_device::ne2000_device(const machine_config& mconfig, const char* tag, device_t* owner, uint32_t clock)
: device_t(mconfig, NE2000, tag, owner, clock),
ne2000_device::ne2000_device(const machine_config& mconfig, const char* tag, device_t* owner, uint32_t clock) :
device_t(mconfig, NE2000, tag, owner, clock),
device_isa16_card_interface(mconfig, *this),
m_dp8390(*this, "dp8390d"),
m_irq(0)
Expand All @@ -38,7 +38,7 @@ void ne2000_device::device_start() {
}

void ne2000_device::device_reset() {
memcpy(m_prom, m_dp8390->get_mac(), 6);
memcpy(m_prom, &m_dp8390->get_mac()[0], 6);
m_irq = ioport("CONFIG")->read() & 3;
}

Expand Down
2 changes: 1 addition & 1 deletion src/devices/bus/nubus/nubus_asntmc3b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void pdslc_macconilc_device::device_start()
void nubus_mac8390_device::device_reset()
{
m_dp83902->dp8390_reset(0);
memcpy(m_prom, m_dp83902->get_mac(), 6);
memcpy(m_prom, &m_dp83902->get_mac()[0], 6);
}

void nubus_mac8390_device::asntm3b_ram_w(offs_t offset, u8 data)
Expand Down
5 changes: 3 additions & 2 deletions src/devices/bus/x68k/x68k_neptunex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ void x68k_neptune_device::device_start()
m_slot->space().install_readwrite_handler(0xece000,0xece3ff, read16s_delegate(*this, FUNC(x68k_neptune_device::x68k_neptune_port_r)), write16s_delegate(*this, FUNC(x68k_neptune_device::x68k_neptune_port_w)), 0xffffffff);
}

void x68k_neptune_device::device_reset() {
memcpy(m_prom, m_dp8390->get_mac(), 6);
void x68k_neptune_device::device_reset()
{
memcpy(m_prom, &m_dp8390->get_mac()[0], 6);
}

uint16_t x68k_neptune_device::x68k_neptune_port_r(offs_t offset, uint16_t mem_mask)
Expand Down
4 changes: 2 additions & 2 deletions src/devices/machine/edlc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void seeq8003_device::device_reset()

// TODO: deassert RxDC and TxRET

if (m_dev)
if (has_net_device())
m_out_txrdy(1);

interrupt();
Expand Down Expand Up @@ -427,7 +427,7 @@ void seeq80c03_device::send_complete_cb(int result)
else
{
// assume transmit failure and no device means loss of carrier
if ((m_control & CTL_TNC) && !m_dev)
if ((m_control & CTL_TNC) && !has_net_device())
m_flags |= FLAGS_TNC;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/devices/machine/i82586.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool i82586_base_device::address_filter(u8 *mac)
}

// individual address
if (!memcmp(mac, get_mac(), cfg_address_length()))
if (!memcmp(mac, &get_mac()[0], cfg_address_length()))
{
LOGMASKED(LOG_FILTER, "address_filter accepted: individual address match\n");

Expand Down Expand Up @@ -950,7 +950,7 @@ bool i82586_device::cu_transmit(u32 command)
// optionally insert source, destination address and length (14 bytes)
if (!cfg_no_src_add_ins())
{
const char *mac = get_mac();
const std::array<u8, 6> &mac = get_mac();
u32 data;

// insert destination address (6 bytes)
Expand Down Expand Up @@ -1054,7 +1054,7 @@ bool i82586_device::cu_dump()
memcpy(&buf[0x00], &m_cfg_bytes[0], CFG_SIZE);

// individual address
memcpy(&buf[0x0c], get_mac(), 6);
memcpy(&buf[0x0c], &get_mac()[0], 6);

// hash register
*(u64 *)&buf[0x24] = m_mac_multi;
Expand Down Expand Up @@ -1584,7 +1584,7 @@ bool i82596_device::cu_transmit(u32 command)
// optionally insert destination, source and length (14 bytes)
if (!cfg_no_src_add_ins())
{
const char *mac = get_mac();
const std::array<u8, 6> &mac = get_mac();
u32 data;

// insert destination address (6 bytes)
Expand Down Expand Up @@ -1719,7 +1719,7 @@ bool i82596_device::cu_dump()
memcpy(&buf[0x02], &m_cfg_bytes[2], 9);

// individual address
memcpy(&buf[0x0c], get_mac(), 6);
memcpy(&buf[0x0c], &get_mac()[0], 6);

// hash register
*(u64 *)&buf[0x24] = m_mac_multi;
Expand All @@ -1730,7 +1730,7 @@ bool i82596_device::cu_dump()
memcpy(&buf[0x00], &m_cfg_bytes[2], 12);

// individual address
memcpy(&buf[0x0e], get_mac(), 6);
memcpy(&buf[0x0e], &get_mac()[0], 6);

// hash register
*(u64 *)&buf[0x26] = m_mac_multi;
Expand Down Expand Up @@ -1827,7 +1827,7 @@ u16 i82596_device::ru_execute(u8 *buf, int length)
// TODO: increment alignment error counter

// set multicast status
if (mode() != MODE_82586 && memcmp(buf, get_mac(), cfg_address_length()))
if (mode() != MODE_82586 && memcmp(buf, &get_mac()[0], cfg_address_length()))
status |= RFD_S_MULTICAST;

// fetch initial rbd address from rfd
Expand Down
65 changes: 47 additions & 18 deletions src/emu/dinetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@

#include "emu.h"
#include "dinetwork.h"

#include "osdnet.h"

#include <algorithm>


device_network_interface::device_network_interface(const machine_config &mconfig, device_t &device, u32 bandwidth, u32 mtu)
: device_interface(device, "network")
, m_poll_timer(nullptr)
, m_send_timer(nullptr)
, m_recv_timer(nullptr)
{
m_promisc = false;
// Convert to Mibps to Bps
m_bandwidth = bandwidth << (20 - 3);
m_mtu = mtu;
memset(m_mac, 0, 6);
m_intf = -1;
m_loopback_control = false;
}
Expand All @@ -21,14 +26,12 @@ device_network_interface::~device_network_interface()
{
}

void device_network_interface::interface_pre_start()
void device_network_interface::interface_post_start()
{
m_poll_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(device_network_interface::poll_device), this));
m_send_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(device_network_interface::send_complete), this));
m_recv_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(device_network_interface::recv_complete), this));
}

void device_network_interface::interface_post_start()
{
device().save_item(NAME(m_loopback_control));
}

Expand Down Expand Up @@ -65,6 +68,25 @@ int device_network_interface::send(u8 *buf, int len, int fcs)
return result;
}

TIMER_CALLBACK_MEMBER(device_network_interface::poll_device)
{
m_dev->poll();
}

void device_network_interface::start_net_device()
{
// Set device polling time to transfer time for one MTU
m_dev->start();
const attotime interval = attotime::from_hz(m_bandwidth / m_mtu);
m_poll_timer->adjust(interval, 0, interval);
}

void device_network_interface::stop_net_device()
{
m_poll_timer->reset();
m_dev->stop();
}

TIMER_CALLBACK_MEMBER(device_network_interface::send_complete)
{
send_complete_cb(param);
Expand All @@ -85,7 +107,7 @@ void device_network_interface::recv_cb(u8 *buf, int len)
{
// stop receiving more data from the network
if (m_dev)
m_dev->stop();
stop_net_device();

// schedule receive complete callback
m_recv_timer->adjust(attotime::from_ticks(len, m_bandwidth), result);
Expand All @@ -98,28 +120,35 @@ TIMER_CALLBACK_MEMBER(device_network_interface::recv_complete)

// start receiving data from the network again
if (m_dev && !m_loopback_control)
m_dev->start();
start_net_device();
}

void device_network_interface::set_promisc(bool promisc)
{
m_promisc = promisc;
if(m_dev) m_dev->set_promisc(promisc);
if (m_dev)
m_dev->set_promisc(promisc);
}

void device_network_interface::set_mac(const u8 *mac)
{
memcpy(m_mac, mac, 6);
if(m_dev) m_dev->set_mac(m_mac);
std::copy_n(mac, std::size(m_mac), std::begin(m_mac));
if (m_dev)
m_dev->set_mac(&m_mac[0]);
}

void device_network_interface::set_interface(int id)
{
if(m_dev)
m_dev->stop();
// Set device polling time to transfer time for one mtu
m_dev.reset(open_netdev(id, this, (int)(m_bandwidth / m_mtu)));
if(!m_dev) {
if (m_dev)
stop_net_device();

m_dev.reset(open_netdev(id, *this));
if (m_dev)
{
start_net_device();
}
else
{
device().logerror("Network interface %d not found\n", id);
id = -1;
}
Expand All @@ -136,8 +165,8 @@ void device_network_interface::set_loopback(bool loopback)
if (m_dev)
{
if (loopback)
m_dev->stop();
stop_net_device();
else if (!m_recv_timer->enabled())
m_dev->start();
start_net_device();
}
}
28 changes: 17 additions & 11 deletions src/emu/dinetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,56 @@
#ifndef MAME_EMU_DINETWORK_H
#define MAME_EMU_DINETWORK_H

class osd_netdev;
#include "interface/nethandler.h"

class device_network_interface : public device_interface

class osd_network_device;

class device_network_interface : public device_interface, public osd::network_handler
{
public:
device_network_interface(const machine_config &mconfig, device_t &device, u32 bandwidth, u32 mtu = 1500);
virtual ~device_network_interface();

void interface_pre_start() override;
void interface_post_start() override;

void set_interface(int id);
void set_promisc(bool promisc);
void set_mac(const u8 *mac);
void set_loopback(bool loopback);

const char *get_mac() const { return m_mac; }
bool get_promisc() const { return m_promisc; }
int get_interface() const { return m_intf; }

int send(u8 *buf, int len, int fcs = 0);

// TODO: de-virtualise this when existing devices implement delayed receive
virtual void recv_cb(u8 *buf, int len);
virtual void recv_cb(u8 *buf, int len) override;

// delayed transmit/receive handlers
virtual void send_complete_cb(int result) {}
virtual int recv_start_cb(u8 *buf, int len) { return 0; }
virtual void recv_complete_cb(int result) {}

protected:
TIMER_CALLBACK_MEMBER(send_complete);
TIMER_CALLBACK_MEMBER(recv_complete);
bool has_net_device() const noexcept { return bool(m_dev); }

bool m_promisc;
char m_mac[6];
// bandwidth in bytes per second
u32 m_bandwidth;
// maximum transmission unit, used for device polling time
u32 m_mtu;
std::unique_ptr<osd_netdev> m_dev;
int m_intf;
bool m_loopback_control;

private:
TIMER_CALLBACK_MEMBER(poll_device);
TIMER_CALLBACK_MEMBER(send_complete);
TIMER_CALLBACK_MEMBER(recv_complete);

void start_net_device();
void stop_net_device();

std::unique_ptr<osd_network_device> m_dev;
emu_timer *m_poll_timer;
emu_timer *m_send_timer;
emu_timer *m_recv_timer;
};
Expand Down
4 changes: 2 additions & 2 deletions src/emu/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ void network_manager::config_save(config_type cfg_type, util::xml::data_node *pa
{
node->set_attribute("tag", network.device().tag());
node->set_attribute_int("interface", network.get_interface());
const char *mac = network.get_mac();
const std::array<u8, 6> &mac = network.get_mac();
char mac_addr[6 * 3];
sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", u8(mac[0]), u8(mac[1]), u8(mac[2]), u8(mac[3]), u8(mac[4]), u8(mac[5]));
sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
node->set_attribute("mac", mac_addr);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/mame/apple/macquadra700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,12 @@ void macquadra_state::field_interrupts()

void macquadra_state::machine_start()
{
const u8 *MAC = (u8 *)m_sonic->get_mac();

m_dafb->set_turboscsi1_device(m_ncr1);
m_dafb->set_turboscsi2_device(nullptr);

// MAC PROM is stored with a bit swizzle and must match one of 2
// Apple-assigned OUI blocks 00:05:02 or 08:00:07
const std::array<u8, 6> &MAC = m_sonic->get_mac();
m_mac[0] = bitswap<8>(0x00, 0, 1, 2, 3, 7, 6, 5, 4);
m_mac[1] = bitswap<8>(0x05, 0, 1, 2, 3, 7, 6, 5, 4);
m_mac[2] = bitswap<8>(0x02, 0, 1, 2, 3, 7, 6, 5, 4);
Expand Down
2 changes: 1 addition & 1 deletion src/mame/apple/macquadra800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void quadra800_state::machine_start()
{
m_djmemc->set_ram_info((u32 *) m_ram->pointer(), m_ram->size());

const u8 *MAC = (u8 *)m_sonic->get_mac();
// MAC PROM is stored with a bit swizzle and must match one of 2
// Apple-assigned OUI blocks 00:05:02 or 08:00:07
const std::array<u8, 6> &MAC = m_sonic->get_mac();
m_mac[0] = bitswap<8>(0x08, 0, 1, 2, 3, 7, 6, 5, 4);
m_mac[1] = bitswap<8>(0x00, 0, 1, 2, 3, 7, 6, 5, 4);
m_mac[2] = bitswap<8>(0x07, 0, 1, 2, 3, 7, 6, 5, 4);
Expand Down
Loading

0 comments on commit b220d5b

Please sign in to comment.