Skip to content

Commit 70fd859

Browse files
authored
Merge pull request #95 from Neotron-Compute/add-file-api
Add File I/O API
2 parents f278d7c + 78b64b9 commit 70fd859

File tree

5 files changed

+329
-50
lines changed

5 files changed

+329
-50
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ chrono = { version = "0.4", default-features = false }
4545
embedded-sdmmc = { version = "0.7", default-features = false }
4646
heapless = "0.7"
4747
menu = "0.3"
48-
neotron-api = "0.1"
48+
neotron-api = "0.2"
4949
neotron-common-bios = "0.12.0"
5050
neotron-loader = "0.1"
5151
pc-keyboard = "0.7"

src/commands/ram.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,27 @@ pub static HEXDUMP_ITEM: menu::Item<Ctx> = menu::Item {
2424
pub static RUN_ITEM: menu::Item<Ctx> = menu::Item {
2525
item_type: menu::ItemType::Callback {
2626
function: run,
27-
parameters: &[],
27+
parameters: &[
28+
menu::Parameter::Optional {
29+
parameter_name: "arg1",
30+
help: None,
31+
},
32+
menu::Parameter::Optional {
33+
parameter_name: "arg2",
34+
help: None,
35+
},
36+
menu::Parameter::Optional {
37+
parameter_name: "arg3",
38+
help: None,
39+
},
40+
menu::Parameter::Optional {
41+
parameter_name: "arg4",
42+
help: None,
43+
},
44+
],
2845
},
2946
command: "run",
30-
help: Some("Jump to start of application area"),
47+
help: Some("Run a program (with up to four arguments)"),
3148
};
3249

3350
pub static LOAD_ITEM: menu::Item<Ctx> = menu::Item {
@@ -90,8 +107,8 @@ fn hexdump(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], _ctx
90107
}
91108

92109
/// Called when the "run" command is executed.
93-
fn run(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], ctx: &mut Ctx) {
94-
match ctx.tpa.execute() {
110+
fn run(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &mut Ctx) {
111+
match ctx.tpa.execute(args) {
95112
Ok(0) => {
96113
osprintln!();
97114
}

src/fs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ impl File {
110110
FILESYSTEM.file_read(self, buffer)
111111
}
112112

113+
/// Write to a file
114+
pub fn write(&self, buffer: &[u8]) -> Result<(), Error> {
115+
FILESYSTEM.file_write(self, buffer)
116+
}
117+
113118
/// Are we at the end of the file
114119
pub fn is_eof(&self) -> bool {
115120
FILESYSTEM
@@ -202,6 +207,17 @@ impl Filesystem {
202207
Ok(bytes_read)
203208
}
204209

210+
/// Write to an open file
211+
pub fn file_write(&self, file: &File, buffer: &[u8]) -> Result<(), Error> {
212+
let mut fs = self.volume_manager.lock();
213+
if fs.is_none() {
214+
*fs = Some(embedded_sdmmc::VolumeManager::new(BiosBlock(), BiosTime()));
215+
}
216+
let fs = fs.as_mut().unwrap();
217+
fs.write(file.inner, buffer)?;
218+
Ok(())
219+
}
220+
205221
/// How large is a file?
206222
pub fn file_length(&self, file: &File) -> Result<u32, Error> {
207223
let mut fs = self.volume_manager.lock();

0 commit comments

Comments
 (0)