diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-09-19 14:43:47 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-09-19 14:43:47 +1200 |
commit | 014aa3639223e0656834d7d469faad40291dd2aa (patch) | |
tree | 372dbc6c9e77b00d9fc86e785fb3463a3f8e40e2 | |
parent | 967866ca2ec7d066e510b287522c8f69de2c3232 (diff) | |
download | bedrock-pc-014aa3639223e0656834d7d469faad40291dd2aa.zip |
Allow building Bedrock programs as standalone executables
This commit adds a run_program() function to the root of the library.
Any Bedrock program can be compiled as a standalone native executable
by creating a thin Rust program that calls only that function, passing
in the bytecode of the program and a configuration object.
-rw-r--r-- | src/lib.rs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -29,3 +29,25 @@ pub const DEFAULT_SCREEN_SCALE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked( pub type ScreenPosition = geometry::Point<u16>; pub type ScreenDimensions = geometry::Dimensions<u16>; + + +pub fn run_program(bytecode: &[u8], config: EmulatorConfig) { + let mut args = switchboard::Switchboard::from_env(); + args.named("verbose").short('v'); + if args.get("verbose").as_bool() { + log::set_log_level(log::LogLevel::Info); + } + + match Phosphor::new() { + Ok(phosphor) => { + info!("Starting graphical emulator"); + let mut emulator = GraphicalEmulator::new(config, false); + emulator.load_program(&bytecode); + emulator.run(phosphor, true); + } + Err(err) => { + eprintln!("EventLoopError: {err:?}"); + fatal!("Could not start graphical event loop"); + } + } +} |