From 6e77dfd2a053689483cee2d4eafe9b04b43b75bd Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Wed, 28 Jun 2023 17:41:42 -0700 Subject: [PATCH] Added generator short commit hash to end of reserved space for all ROMs --- docs/format.md | 1 + support/Cargo.lock | 51 ++++++++++++++++++++++++++++++++++++ support/Cargo.toml | 5 ++++ support/build.rs | 8 ++++++ support/src/encode_format.rs | 15 ++++++++++- 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 support/build.rs diff --git a/docs/format.md b/docs/format.md index 276c236..c38ab98 100644 --- a/docs/format.md +++ b/docs/format.md @@ -12,6 +12,7 @@ First bit is version. Spec V1 is as follows: 0x0: [version 8 bits (01)][mpu 8 bits][screen configuration 8 bits][screen width|screen height 24 bits][reserved 16 bits] 0x8: input mapping 40 bytes - [s0 config 4 bytes][s1 config 4 bytes] ... [s7 config 4 bytes][b config 1 byte][ba config 1 byte][acl config 1 byte][grounded port index 1 byte][reserved 4 bytes] 0x30: Start of reserved space - This is reserved for future functionality +0x79: [generator tool commit (ascii) 7 bytes] 0x80: Start of byte interleaved images 0x17BB80: [mask config 0x2DB40 bytes] End of images, start of mask config 0x1A96C0: ROM data diff --git a/support/Cargo.lock b/support/Cargo.lock index 65dc81f..fcdbf52 100644 --- a/support/Cargo.lock +++ b/support/Cargo.lock @@ -57,6 +57,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + [[package]] name = "arrayref" version = "0.3.7" @@ -434,6 +440,7 @@ dependencies = [ "sha1", "svg", "tiny-skia-path", + "vergen", "zip", ] @@ -918,6 +925,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" + [[package]] name = "rustybuzz" version = "0.7.0" @@ -1134,6 +1147,33 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +dependencies = [ + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +dependencies = [ + "time-core", +] + [[package]] name = "tiny-skia" version = "0.9.0" @@ -1280,6 +1320,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "vergen" +version = "8.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3c89c2c7e50f33e4d35527e5bf9c11d6d132226dbbd1753f0fbe9f19ef88c6" +dependencies = [ + "anyhow", + "rustversion", + "time", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/support/Cargo.toml b/support/Cargo.toml index 838cacb..94475c0 100644 --- a/support/Cargo.toml +++ b/support/Cargo.toml @@ -3,6 +3,8 @@ name = "fpga-gnw-romgenerator" version = "0.1.0" edition = "2021" +build = "build.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -21,3 +23,6 @@ sha1 = "0.10.5" svg = "0.13.1" tiny-skia-path = "0.9" zip = { version = "0.6", features = ["deflate"], default-features = false } + +[build-dependencies] +vergen = { version = "8.2.1", features = ["git", "gitcl"] } \ No newline at end of file diff --git a/support/build.rs b/support/build.rs new file mode 100644 index 0000000..edec687 --- /dev/null +++ b/support/build.rs @@ -0,0 +1,8 @@ +use std::error::Error; +use vergen::EmitBuilder; + +fn main() -> Result<(), Box> { + // Emit the instructions + EmitBuilder::builder().git_sha(true).emit()?; + Ok(()) +} diff --git a/support/src/encode_format.rs b/support/src/encode_format.rs index d3ee549..4a8a31c 100644 --- a/support/src/encode_format.rs +++ b/support/src/encode_format.rs @@ -255,10 +255,23 @@ fn build_config(platform: &PlatformSpecification) -> Result, String> { } // Reserved space - for _ in 0..0xD0 { + for _ in 0..0xC9 { config.push(0); } + let sha = env!("VERGEN_GIT_SHA"); + + if sha.len() < 1 { + println!("Unknown git SHA"); + + vec![0 as u8; 7].iter().for_each(|c| config.push(*c)); + } else { + sha.chars() + .take(7) + .map(|c| c as u8) + .for_each(|c| config.push(c)); + }; + Ok(config) }