#![feature(path_add_extension)] mod asm; mod run; mod formats; use switchboard::*; fn main() { let mut args = Switchboard::from_env(); args.named("help").short('h'); args.named("version"); args.named("verbose").short('v'); if args.get("help").as_bool() { print_help(); } if args.get("version").as_bool() { print_version(); } if args.get("verbose").as_bool() { log::set_log_level(log::LogLevel::Info); } match args.peek() { Some("run") => { args.pop(); run::main(args) }, Some("asm") => { args.pop(); asm::main(args) }, _ => run::main(args), } } fn print_help() -> ! { eprintln!("\ Usage: br [source] br asm [source] [destination] Integrated Bedrock assembler and emulator. Usage: To load a Bedrock program from a file, run `br `, where is the path to an assembled Bedrock program. To load a Bedrock program from piped input, run ` | br`, where is a command that generates Bedrock bytecode. To assemble a Bedrock program from a source file and write to an output file, run `br asm `, where is the path of the source file and is the path to write to. To assemble and run a Bedrock program without saving to a file, run `br asm | br`, where is the path of the source file. Environment variables: BEDROCK_PATH A list of colon-separated paths which will be searched to find a Bedrock program when the program doesn't exist in the current directory. This allows the user to run frequently-used programs from any directory. BEDROCK_LIBS A list of colon-separated paths which will be searched to find Bedrock source code files to use as libraries when assembling a Bedrock program. If a library file resolves an unresolved symbol in the program being assembled, the library file will be merged into the program. Arguments: [program] Path to a Bedrock program to run Switches: --fullscreen (-f) Start the program in fullscreen mode (toggle with F11) --size= (-s) Set the initial window size in the format x --zoom= (-z) Set the pixel size for the screen (change with F5/F6) --show-cursor (-c) Show the operating system cursor over the window --palette= Set a debug colour palette in the format ,... (toggle with F2) --debug, (-d) Show debug information while the program is running --decode-stdin (-i) Decode transmissions on standard input from text lines. --encode-stdout (-o) Encode transmissions on standard output as text lines. --help (-h) Print this help information --verbose, (-v) Print additional information --version Print the program version and exit Arguments (asm mode): [source] Bedrock source code file to assemble. [destination] Destination path for assembler output. Switches (asm mode): --dry-run (-n) Assemble and show errors only, don't write any output --extension File extension to identify source files (default is 'brc') --format= Output format to use for assembled program (default is 'binary') --no-project-libs Don't search for libraries in the source parent folder --no-env-libs Don't search for libraries in the BEDROCK_LIBS path variable --no-libs Combination of --no-project-libs and --no-env-libs --tree Display a tree visualisation of all included library files --with-symbols Also generate debug symbols file with extension '.sym' --help (-h) Print this help information --verbose, (-v) Print additional information --version Print the program version and exit "); std::process::exit(0); } fn print_version() -> ! { let name = env!("CARGO_PKG_NAME"); let version = env!("CARGO_PKG_VERSION"); eprintln!("{name} v{version}"); eprintln!("Written by Ben Bridle."); std::process::exit(0); }