Skip to content

Commit

Permalink
nes: Remove unused arguments.
Browse files Browse the repository at this point in the history
snes: add cgram.
  • Loading branch information
tepperson2 committed Feb 8, 2024
1 parent 4211806 commit d724425
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
15 changes: 2 additions & 13 deletions nes/rust/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ pub trait NesControllerTrait {
fn read_data(
&mut self,
screen: &common_emulator::video::RgbImage,
ppux: u16,
ppuy: u16,
x: u16,
y: u16,
) -> u8;
Expand Down Expand Up @@ -579,14 +577,12 @@ impl NesControllerTrait for FourScore {
fn read_data(
&mut self,
screen: &common_emulator::video::RgbImage,
ppux: u16,
ppuy: u16,
x: u16,
y: u16,
) -> u8 {
match self.clock_counter {
0..=7 => self.controllers[0].read_data(screen, ppux, ppuy, x, y),
8..=15 => self.controllers[1].read_data(screen, ppux, ppuy, x, y),
0..=7 => self.controllers[0].read_data(screen, x, y),
8..=15 => self.controllers[1].read_data(screen, x, y),
16..=17 => 0,
18 => 0xFF,
19..=23 => 0,
Expand Down Expand Up @@ -638,8 +634,6 @@ impl NesControllerTrait for DummyController {
fn read_data(
&mut self,
screen: &common_emulator::video::RgbImage,
ppux: u16,
ppuy: u16,
x: u16,
y: u16,
) -> u8 {
Expand Down Expand Up @@ -705,8 +699,6 @@ impl NesControllerTrait for Zapper {
fn read_data(
&mut self,
screen: &common_emulator::video::RgbImage,
ppux: u16,
ppuy: u16,
x: u16,
y: u16,
) -> u8 {
Expand All @@ -717,7 +709,6 @@ impl NesControllerTrait for Zapper {
y: y as f32,
});
if color[0] > 200 && color[1] > 200 && color[2] > 200 {
println!("Detect color at {},{} {},{}", ppux, ppuy, x, y);
d |= 1 << 3;
}
}
Expand Down Expand Up @@ -896,8 +887,6 @@ impl NesControllerTrait for StandardController {
fn read_data(
&mut self,
screen: &common_emulator::video::RgbImage,
ppux: u16,
ppuy: u16,
x: u16,
y: u16,
) -> u8 {
Expand Down
4 changes: 0 additions & 4 deletions nes/rust/src/motherboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ impl NesMotherboard {
0x4016 => {
let d = self.controllers[0].read_data(
per.ppu.get_frame(),
per.ppu.column(),
per.ppu.row(),
self.x,
self.y,
) & 0x1f;
Expand All @@ -388,8 +386,6 @@ impl NesMotherboard {
0x4017 => {
let d = self.controllers[1].read_data(
per.ppu.get_frame(),
per.ppu.column(),
per.ppu.row(),
self.x,
self.y,
) & 0x1f;
Expand Down
14 changes: 5 additions & 9 deletions nes/rust/src/windows/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,17 +955,17 @@ impl TrackedWindow for MainNesWindow {
})
.sense(egui::Sense::click_and_drag()),
);
if (r.clicked() || r.dragged()) && !self.mouse {
self.mouse = true;
self.mouse_miss = false;
self.mouse_delay = 15;
} else if (r.clicked_by(egui::PointerButton::Secondary)
if (r.clicked_by(egui::PointerButton::Secondary)
|| r.dragged_by(egui::PointerButton::Secondary))
&& !self.mouse
{
self.mouse = true;
self.mouse_miss = true;
self.mouse_delay = 15;
} else if (r.clicked() || r.dragged()) && !self.mouse {
self.mouse = true;
self.mouse_miss = false;
self.mouse_delay = 15;
}
if r.hovered() {
if let Some(pos) = r.hover_pos() {
Expand All @@ -992,11 +992,7 @@ impl TrackedWindow for MainNesWindow {
&& pixel.b() > 100;

//println!("Hover at {:?}", pos - r.rect.left_top());
} else {
self.mouse_vision = false;
}
} else {
self.mouse_vision = false;
}
}
});
Expand Down
8 changes: 6 additions & 2 deletions snes/rust/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ impl SnesPpu {
#[non_exhaustive]
#[serde_with::serde_as]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct SnesPpu2 {}
pub struct SnesPpu2 {
/// Where palette data is stored
#[serde_as(as = "Bytes")]
cgram: [u8; 512],
}

impl SnesPpu2 {
/// Construct the struct
pub fn new() -> Self {
Self {}
Self { cgram: [0; 512] }
}

/// Read a register on the ppu
Expand Down
13 changes: 7 additions & 6 deletions snes/rust/src/windows/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,13 @@ impl TrackedWindow for MainSnesWindow {
})
.sense(egui::Sense::click_and_drag()),
);
if r.clicked() || r.dragged() {
if (r.clicked() || r.dragged()) && !self.mouse {
self.mouse = true;
self.mouse_miss = false;
self.mouse_delay = 10;
} else if r.clicked_by(egui::PointerButton::Secondary)
|| r.dragged_by(egui::PointerButton::Secondary)
} else if (r.clicked_by(egui::PointerButton::Secondary)
|| r.dragged_by(egui::PointerButton::Secondary))
&& !self.mouse
{
self.mouse = true;
self.mouse_miss = true;
Expand All @@ -906,9 +907,9 @@ impl TrackedWindow for MainSnesWindow {

let pixel = c.local.image.get_pixel(coord / zoom);
self.mouse_vision = !self.mouse_miss
&& pixel.r() > 10
&& pixel.g() > 10
&& pixel.b() > 10;
&& pixel.r() > 100
&& pixel.g() > 100
&& pixel.b() > 100;

//println!("Hover at {:?}", pos - r.rect.left_top());
} else {
Expand Down

0 comments on commit d724425

Please sign in to comment.