Skip to content

Commit 084cea3

Browse files
committed
Add snake program skelton.
1 parent 8a3c3ea commit 084cea3

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"./samples/panic/Cargo.toml",
55
"./samples/hello/Cargo.toml",
66
"./samples/fault/Cargo.toml",
7+
"./samples/snake/Cargo.toml",
78
"./Cargo.toml"
89
]
910
}

samples/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"fault",
44
"hello",
55
"input-test",
6+
"snake",
67
"panic",
78
]
89

samples/snake/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "snake"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT OR Apache-2.0"
6+
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
7+
description = "ANSI Snake for Neotron systems"
8+
9+
[dependencies]
10+
neotron-sdk = { path = "../.." }
11+
12+
# See workspace for profile settings

samples/snake/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
// Put `neotron-cortex-m.ld` in our output directory and ensure it's
8+
// on the linker search path.
9+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
10+
File::create(out.join("neotron-cortex-m.ld"))
11+
.unwrap()
12+
.write_all(include_bytes!("../neotron-cortex-m.ld"))
13+
.unwrap();
14+
println!("cargo:rustc-link-search={}", out.display());
15+
16+
// By default, Cargo will re-run a build script whenever
17+
// any file in the project changes. By specifying `neotron-cortex-m.ld`
18+
// here, we ensure the build script is only re-run when
19+
// `neotron-cortex-m.ld` is changed.
20+
println!("cargo:rerun-if-changed=../neotron-cortex-m.ld");
21+
}

samples/snake/src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![cfg_attr(target_os = "none", no_std)]
2+
#![cfg_attr(target_os = "none", no_main)]
3+
4+
#[cfg(not(target_os = "none"))]
5+
fn main() {
6+
neotron_sdk::init();
7+
}
8+
9+
#[no_mangle]
10+
extern "C" fn neotron_main() -> i32 {
11+
let stdout = neotron_sdk::stdout();
12+
if stdout.write(b"Hello, world\n").is_ok() {
13+
0
14+
} else {
15+
1
16+
}
17+
}

0 commit comments

Comments
 (0)