Skip to content

Commit

Permalink
Move network code to common_emulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
tepperson2 committed Feb 2, 2024
1 parent 9f321d3 commit 131fa70
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 1,693 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-channel = "2.0.0"
asynchronous-codec = "0.7.0"
bincode = "1.3.3"
chrono = "0.4.31"
compile-time = "0.2.0"
egui-multiwin = { version = "0.3.1", features = ["serde"] }
futures = "0.3.28"
gilrs = {version = "0.10.2", features = ["serde-serialize"]}
gstreamer = "0.21.1"
gstreamer-app = "0.21.1"
gstreamer-audio = "0.21.1"
gstreamer-video = "0.21.1"
libp2p = { version = "0.53", features = ["tokio", "dns", "macros", "noise", "tcp", "upnp", "yamux", "serde"] }
memmap2 = "0.9.0"
ringbuf = "0.3.3"
serde = {version = "1.0.189", features = ["derive"]}
serde_with = "3.3"
strum = { version = "0.25", features = ["derive"] }
tokio = "1.33.0"
walkdir = "2.4"
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
pub mod audio;
pub mod event;
pub mod input;
pub mod network;
pub mod recording;
pub mod rom_status;
pub mod romlist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ use libp2p::{
InboundUpgrade, OutboundUpgrade, PeerId, StreamProtocol,
};

use crate::controller::ButtonCombination;
use common_emulator::audio::AudioProducerWithRate;
use crate::audio::AudioProducerWithRate;

use super::NodeRole;

use common_emulator::streaming::{StreamingIn, StreamingOut};
use crate::streaming::{StreamingIn, StreamingOut};

/// Represents a message that can be sent to and from other nodes in the network.
#[derive(Debug, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -578,9 +577,9 @@ pub struct Behavior {

impl Behavior {
/// Construct a new Self
pub fn new() -> Self {
pub fn new(s: &'static str) -> Self {
Self {
config: Config::new("/nes/0.0.1"),
config: Config::new(s),
messages: VecDeque::new(),
waker: Arc::new(Mutex::new(None)),
clients: HashSet::new(),
Expand Down
92 changes: 46 additions & 46 deletions nes/rust/src/network/mod.rs → common/src/network/mod.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion nes/rust/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod cpu;
mod emulator_data;
mod genie;
mod motherboard;
mod network;
mod ppu;
pub mod windows;

Expand Down
2 changes: 1 addition & 1 deletion nes/rust/src/emulator_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub struct LocalEmulatorData {
/// The object for interfacing with joysticks.
pub gilrs: gilrs::Gilrs,
/// The network object for interacting with other emulators
pub network: Option<crate::network::Network>,
pub network: Option<common_emulator::network::Network>,
}

impl Default for LocalEmulatorData {
Expand Down
1 change: 0 additions & 1 deletion nes/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod cpu;
mod emulator_data;
mod genie;
mod motherboard;
mod network;
mod ppu;

use emulator_data::NesEmulatorData;
Expand Down
3 changes: 2 additions & 1 deletion nes/rust/src/windows/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use std::io::Write;

use crate::{
controller::{ButtonCombination, NesControllerTrait},
network::NodeRole,
NesEmulatorData,
};

use common_emulator::network::NodeRole;

use common_emulator::audio::AudioProducerWithRate;
use common_emulator::recording::Recording;

Expand Down
3 changes: 2 additions & 1 deletion nes/rust/src/windows/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ impl TrackedWindow for Window {
let mut button = crate::controller::ButtonCombination::new();
button.clear_buttons();
let button = bincode::serialize(&button).unwrap();
olocal.network = Some(crate::network::Network::new(
olocal.network = Some(common_emulator::network::Network::new(
proxy,
c.local.get_sound_rate(),
button,
"/nes/0.0.1",
));
}
}
Expand Down
1 change: 0 additions & 1 deletion snes/rust/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod cpu;
mod emulator_data;
mod genie;
mod motherboard;
mod network;
mod ppu;
pub mod windows;

Expand Down
4 changes: 2 additions & 2 deletions snes/rust/src/emulator_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub struct LocalEmulatorData {
/// The object for interfacing with joysticks.
pub gilrs: gilrs::Gilrs,
/// The network object for interacting with other emulators
pub network: Option<crate::network::Network>,
pub network: Option<common_emulator::network::Network>,
}

impl Default for LocalEmulatorData {
Expand Down Expand Up @@ -542,8 +542,8 @@ impl SnesEmulatorData {
self.ppu_clock_counter += 1;
if self.ppu_clock_counter >= 4 {
self.ppu_clock_counter = 0;
self.cpu_peripherals.ppu.cycle(&mut self.mb);
self.cpu_peripherals.ppu2.cycle(&mut self.mb);
self.cpu_peripherals.ppu.cycle(&mut self.mb);
}

let nmi = self.nmi[2];
Expand Down
1 change: 0 additions & 1 deletion snes/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod cpu;
mod emulator_data;
mod genie;
mod motherboard;
mod network;
mod ppu;

use emulator_data::SnesEmulatorData;
Expand Down
17 changes: 13 additions & 4 deletions snes/rust/src/motherboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub struct SnesMotherboard {
ram: Box<[u8; 128 * 1024]>,
/// The ppu vram, physically outside the ppu, so this makes perfect sense.
#[serde_as(as = "Bytes")]
vram: [u8; 2048],
vram1: [u8; 32768],
/// The ppu vram, physically outside the ppu, so this makes perfect sense.
#[serde_as(as = "Bytes")]
vram2: [u8; 32768],
/// The palette ram for the ppu, technically belongs in the ppu.
ppu_palette_ram: [u8; 32],
/// The vram address fromm the last ppu address cycle
Expand All @@ -46,8 +49,13 @@ impl SnesMotherboard {
*i = rand::random();
}

let mut vram: [u8; 2048] = [0; 2048];
for i in vram.iter_mut() {
let mut vram1: [u8; 32768] = [0; 32768];
for i in vram1.iter_mut() {
*i = rand::random();
}

let mut vram2: [u8; 32768] = [0; 32768];
for i in vram2.iter_mut() {
*i = rand::random();
}

Expand All @@ -58,7 +66,8 @@ impl SnesMotherboard {
Self {
cart: None,
ram: main_ram,
vram,
vram1,
vram2,
ppu_palette_ram: pram,
vram_address: None,
last_ppu_cycle: 2,
Expand Down
Loading

0 comments on commit 131fa70

Please sign in to comment.