Skip to content

Commit 83fb430

Browse files
committed
Load segments with uncached reads.
Bypassing the cache means bigger blocks so it goes much faster.
1 parent 34dc28e commit 83fb430

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/program.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Program Loading and Execution
22
33
use embedded_sdmmc::File;
4-
use neotron_loader::traits::Source;
54

65
use crate::{
76
fs::{BiosBlock, BiosTime},
@@ -85,6 +84,19 @@ impl FileSource {
8584
offset_cached: core::cell::Cell::new(None),
8685
}
8786
}
87+
88+
fn uncached_read(
89+
&self,
90+
offset: u32,
91+
out_buffer: &mut [u8],
92+
) -> Result<(), embedded_sdmmc::Error<neotron_common_bios::Error>> {
93+
println!("Reading from {}", offset);
94+
self.file.borrow_mut().seek_from_start(offset).unwrap();
95+
self.mgr
96+
.borrow_mut()
97+
.read(&self.volume, &mut self.file.borrow_mut(), out_buffer)?;
98+
Ok(())
99+
}
88100
}
89101

90102
impl neotron_loader::traits::Source for &FileSource {
@@ -99,7 +111,7 @@ impl neotron_loader::traits::Source for &FileSource {
99111
{
100112
// Do a fast copy from the cache
101113
let start = (offset - offset_cached) as usize;
102-
let end = (start as usize) + chunk.len();
114+
let end = start + chunk.len();
103115
chunk.copy_from_slice(&self.buffer.borrow()[start..end]);
104116
return Ok(());
105117
}
@@ -220,7 +232,7 @@ impl TransientProgramArea {
220232
for b in ram.iter_mut() {
221233
*b = 0;
222234
}
223-
(&source).read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
235+
source.uncached_read(ph.p_offset(), &mut ram[0..ph.p_filesz() as usize])?;
224236
}
225237
}
226238

0 commit comments

Comments
 (0)