Skip to content

Commit

Permalink
embedded-sdmmc updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
thejpster committed Oct 1, 2023
1 parent 2439089 commit d4c84f1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ postcard = "1.0"
serde = { version = "1.0", default-features = false }
menu = "0.3"
chrono = { version = "0.4", default-features = false }
embedded-sdmmc = { version = "0.5", default-features = false }
embedded-sdmmc = { git = "https://github.com/rust-embedded-community/embedded-sdmmc-rs", default-features = false }
neotron-api = "0.1"
neotron-loader = "0.1"
vte = { git = "https://github.com/alacritty/vte", rev = "94e74f3a64f42d5dad4e3d42dbe8c23291038214" }
Expand Down
6 changes: 3 additions & 3 deletions src/commands/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ fn dir(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &
let time = crate::fs::BiosTime();
let mut mgr = embedded_sdmmc::VolumeManager::new(bios_block, time);
// Open the first partition
let volume = mgr.get_volume(VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(&volume)?;
let volume = mgr.open_volume(VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(volume)?;
let mut total_bytes = 0u64;
let mut num_files = 0;
mgr.iterate_dir(&volume, &root_dir, |dir_entry| {
mgr.iterate_dir(root_dir, |dir_entry| {
let padding = 8 - dir_entry.name.base_name().len();
for b in dir_entry.name.base_name() {
let ch = *b as char;
Expand Down
19 changes: 7 additions & 12 deletions src/commands/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn mixer(_menu: &menu::Menu<Ctx>, item: &menu::Item<Ctx>, args: &[&str], _ctx: &
neotron_common_bios::audio::Direction::Output => "Out",
};
if selected_mixer
.and_then(|s| Some(s == mixer_info.name.as_str()))
.map(|s| s == mixer_info.name.as_str())
.unwrap_or(true)
{
osprintln!(
Expand Down Expand Up @@ -123,23 +123,18 @@ fn play(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &m
let time = crate::fs::BiosTime();
let mut mgr = embedded_sdmmc::VolumeManager::new(bios_block, time);
// Open the first partition
let mut volume = mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(&volume)?;
let mut file = mgr.open_file_in_dir(
&mut volume,
&root_dir,
file_name,
embedded_sdmmc::Mode::ReadOnly,
)?;
let volume = mgr.open_volume(embedded_sdmmc::VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(volume)?;
let file = mgr.open_file_in_dir(root_dir, file_name, embedded_sdmmc::Mode::ReadOnly)?;

let api = API.get();

let mut buffer = &mut scratch[0..4096];
let buffer = &mut scratch[0..4096];
let mut bytes = 0;
let mut delta = 0;

while !file.eof() {
let bytes_read = mgr.read(&mut volume, &mut file, &mut buffer)?;
while !mgr.file_eof(file).unwrap() {
let bytes_read = mgr.read(file, buffer)?;
let mut buffer = &buffer[0..bytes_read];
while !buffer.is_empty() {
let slice = neotron_common_bios::FfiByteSlice::new(buffer);
Expand Down
45 changes: 18 additions & 27 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,18 @@ impl From<neotron_loader::Error<embedded_sdmmc::Error<neotron_common_bios::Error
/// Something the ELF loader can use to get bytes off the disk
struct FileSource {
mgr: core::cell::RefCell<embedded_sdmmc::VolumeManager<BiosBlock, BiosTime>>,
volume: embedded_sdmmc::Volume,
file: core::cell::RefCell<File>,
file: embedded_sdmmc::File,
buffer: core::cell::RefCell<[u8; Self::BUFFER_LEN]>,
offset_cached: core::cell::Cell<Option<u32>>,
}

impl FileSource {
const BUFFER_LEN: usize = 128;

fn new(
mgr: embedded_sdmmc::VolumeManager<BiosBlock, BiosTime>,
volume: embedded_sdmmc::Volume,
file: File,
) -> FileSource {
fn new(mgr: embedded_sdmmc::VolumeManager<BiosBlock, BiosTime>, file: File) -> FileSource {
FileSource {
mgr: core::cell::RefCell::new(mgr),
file: core::cell::RefCell::new(file),
volume,
file,
buffer: core::cell::RefCell::new([0u8; 128]),
offset_cached: core::cell::Cell::new(None),
}
Expand All @@ -91,10 +85,11 @@ impl FileSource {
out_buffer: &mut [u8],
) -> Result<(), embedded_sdmmc::Error<neotron_common_bios::Error>> {
osprintln!("Reading from {}", offset);
self.file.borrow_mut().seek_from_start(offset).unwrap();
self.mgr
.borrow_mut()
.read(&self.volume, &mut self.file.borrow_mut(), out_buffer)?;
.file_seek_from_start(self.file, offset)
.unwrap();
self.mgr.borrow_mut().read(self.file, out_buffer)?;
Ok(())
}
}
Expand All @@ -118,12 +113,13 @@ impl neotron_loader::traits::Source for &FileSource {
}

osprintln!("Reading from {}", offset);
self.file.borrow_mut().seek_from_start(offset).unwrap();
self.mgr.borrow_mut().read(
&self.volume,
&mut self.file.borrow_mut(),
self.buffer.borrow_mut().as_mut_slice(),
)?;
self.mgr
.borrow_mut()
.file_seek_from_start(self.file, offset)
.unwrap();
self.mgr
.borrow_mut()
.read(self.file, self.buffer.borrow_mut().as_mut_slice())?;
self.offset_cached.set(Some(offset));
chunk.copy_from_slice(&self.buffer.borrow()[0..chunk.len()]);

Expand Down Expand Up @@ -210,16 +206,11 @@ impl TransientProgramArea {
let time = crate::fs::BiosTime();
let mut mgr = embedded_sdmmc::VolumeManager::new(bios_block, time);
// Open the first partition
let mut volume = mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(&volume)?;
let file = mgr.open_file_in_dir(
&mut volume,
&root_dir,
file_name,
embedded_sdmmc::Mode::ReadOnly,
)?;

let source = FileSource::new(mgr, volume, file);
let volume = mgr.open_volume(embedded_sdmmc::VolumeIdx(0))?;
let root_dir = mgr.open_root_dir(volume)?;
let file = mgr.open_file_in_dir(root_dir, file_name, embedded_sdmmc::Mode::ReadOnly)?;

let source = FileSource::new(mgr, file);
let loader = neotron_loader::Loader::new(&source)?;

let mut iter = loader.iter_program_headers();
Expand Down

0 comments on commit d4c84f1

Please sign in to comment.