Skip to content

Commit

Permalink
call flushing from the cpu cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ava-silver committed Dec 30, 2023
1 parent ec6d810 commit db62e23
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ pub trait Cpu {

/// Execute a single instruction. Return the number of cycles elapsed.
fn tick(&mut self) -> u8;

/// Clean up any resources used by this CPU.
fn cleanup(&mut self) -> Result<(), &str>;
}
18 changes: 17 additions & 1 deletion src/cpu/mos6502/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod execute;
mod fetch;
mod registers;
use crate::memory::{ActiveInterrupt, Memory};
use crate::trace::TraceHandler;
use crate::trace::{CpuTrace, TraceHandler};
use execute::Execute;
use fetch::Fetch;
use registers::{flags, Registers};
Expand Down Expand Up @@ -171,6 +171,14 @@ impl Cpu for Mos6502 {
/// Execute a single instruction.
fn tick(&mut self) -> u8 {
let opcode = self.fetch();

if let Some(tracer) = &mut self.trace {
tracer.handle(&CpuTrace {
address: self.registers.pc.address(),
opcode,
});

Check warning on line 179 in src/cpu/mos6502/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/mos6502/mod.rs#L176-L179

Added lines #L176 - L179 were not covered by tests
}

match self.execute(opcode) {
Ok(cycles) => {
self.cycle_count += cycles as u64;
Expand Down Expand Up @@ -199,4 +207,12 @@ impl Cpu for Mos6502 {
}
}
}

fn cleanup(&mut self) -> Result<(), &str> {
if let Some(tracer) = &mut self.trace {
tracer.flush()

Check warning on line 213 in src/cpu/mos6502/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/mos6502/mod.rs#L211-L213

Added lines #L211 - L213 were not covered by tests
} else {
Ok(())

Check warning on line 215 in src/cpu/mos6502/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/mos6502/mod.rs#L215

Added line #L215 was not covered by tests
}
}

Check warning on line 217 in src/cpu/mos6502/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cpu/mos6502/mod.rs#L217

Added line #L217 was not covered by tests
}
2 changes: 1 addition & 1 deletion src/systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ pub trait System {

/// Clean up any resources used by this system.
fn cleanup(&mut self) -> Result<(), &str> {
Ok(())
self.get_cpu_mut().cleanup()

Check warning on line 46 in src/systems/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/mod.rs#L46

Added line #L46 was not covered by tests
}
}
4 changes: 3 additions & 1 deletion src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ pub trait TraceHandler {
fn handle(&mut self, trace: &CpuTrace);

/// Flush any existing resource buffers.
fn flush(&mut self) -> Result<(), &str>{ Ok(())}
fn flush(&mut self) -> Result<(), &str> {
Ok(())
}

Check warning on line 18 in src/trace/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/trace/mod.rs#L16-L18

Added lines #L16 - L18 were not covered by tests
}

0 comments on commit db62e23

Please sign in to comment.