Skip to content

Commit 78bde4b

Browse files
committed
Run command takes arguments.
1 parent f278d7c commit 78bde4b

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
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/program.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Program Loading and Execution
22
3-
use crate::{osprint, osprintln, FILESYSTEM};
3+
use crate::{osprintln, FILESYSTEM};
44

55
#[allow(unused)]
66
static CALLBACK_TABLE: neotron_api::Api = neotron_api::Api {
@@ -230,15 +230,23 @@ impl TransientProgramArea {
230230
/// an exit code that is non-zero is not considered a failure from the point
231231
/// of view of this API. You wanted to run a program, and the program was
232232
/// run.
233-
pub fn execute(&mut self) -> Result<i32, Error> {
233+
pub fn execute(&mut self, args: &[&str]) -> Result<i32, Error> {
234234
if self.last_entry == 0 {
235235
return Err(Error::NothingLoaded);
236236
}
237237

238+
// We support a maximum of four arguments.
239+
let ffi_args = [
240+
neotron_api::FfiString::new(args.get(0).unwrap_or(&"")),
241+
neotron_api::FfiString::new(args.get(1).unwrap_or(&"")),
242+
neotron_api::FfiString::new(args.get(2).unwrap_or(&"")),
243+
neotron_api::FfiString::new(args.get(3).unwrap_or(&"")),
244+
];
245+
238246
let result = unsafe {
239-
let code: extern "C" fn(*const neotron_api::Api) -> i32 =
247+
let code: neotron_api::AppStartFn =
240248
::core::mem::transmute(self.last_entry as *const ());
241-
code(&CALLBACK_TABLE)
249+
code(&CALLBACK_TABLE, args.len(), ffi_args.as_ptr())
242250
};
243251

244252
self.last_entry = 0;
@@ -278,17 +286,6 @@ impl TransientProgramArea {
278286
}
279287
}
280288

281-
/// Application API to print things to the console.
282-
#[allow(unused)]
283-
extern "C" fn print_fn(data: *const u8, len: usize) {
284-
let slice = unsafe { core::slice::from_raw_parts(data, len) };
285-
if let Ok(s) = core::str::from_utf8(slice) {
286-
osprint!("{}", s);
287-
} else {
288-
// Ignore App output - not UTF-8
289-
}
290-
}
291-
292289
/// Open a file, given a path as UTF-8 string.
293290
///
294291
/// If the file does not exist, or is already open, it returns an error.

0 commit comments

Comments
 (0)