bedrock-pc

bedrock-pc is an assembler and emulator for the Bedrock computer system that runs on Windows and Linux computers, written in Rust.

Installation

Source code can be found at code.benbridle.com/bedrock-pc.

The latest release is available as pre-built executables for Windows or Linux:

Build from source

To build bedrock-pc from source, first install the Rust compiler from www.rust-lang.org/tools/install, and then run cargo build --release inside the bedrock-pc source code directory.

The compiled binary will be created at ./target/release/br.

Usage

The following commands assume that the bedrock-pc program is available under the name br. The program will act as a Bedrock emulator when invoked as br ..., and will act as a Bedrock assembler when invoked as br asm ..., with different help and version information printed when in either mode.

To assemble a source code file program.brc and save the result as the program program.br, run the command:

br asm program.brc program.br

To run an assembled program program.br, run the command:

br program.br

If no program path is passed to br, the program will be read from standard input, and if no destination path is passed to br asm, the assembled program will be written to standard output. This means that on Linux computers, a program can be assembled and run with the following command:

br asm program.brc | br

To change the zoom level of the program window, either pass the flag -z to the emulator or use the F5 and F6 keys when the program is running.

The file device is sandboxed by default to the C:\Users\<user>\AppData\Roaming\bedrock\<program> directory on Windows, or the /home/<user>/.config/bedrock/<program> directory on Linux.

To see the full list of available flags, run br asm --help or br --help.

Development

The assembler is fully implemented. The emulator implements the system, memory, math, clock, input, and screen devices, and partially implements the stream and file devices.

License

bedrock-pc is licensed under the MIT License. Feel free to use it, change it, and share it however you want.

Troubleshooting

If you have any difficulties getting it to run, send an email to ben@derelict.engineering and I’ll give you a hand.

Running under NixOS

You’ll have to compile Bedrock yourself under NixOS because the Nix package model frowns on running pre-built dynamically linked executables. I’m not familiar with Nix, but I’m told by someone in the know that the URL git+https://codeberg.org/ctstk/nixos#bedrock should more or less get it going. Their package definition file for bedrock-pc can be found at codeberg.org/ctstk/nixos/src/branch/main/packages/bedrock/default.nix.

The issue that we ran into was that the program was unable to find and load the system Wayland and XKB libraries, which are needed to create and access the program window in graphical mode under Wayland. The critical line in the package definition that fixes this issue is:

fixupPhase = with pkgs; "wrapProgram $out/bin/br --prefix LD_LIBRARY_PATH : ${wayland}/lib --prefix LD_LIBRARY_PATH : ${libxkbcommon}/lib";

The remainder of this section will be context for the issues we faced.

When running in graphical mode (either explicitly with --mode=graphical or by starting in dynamic mode and then accessing the input or screen devices), bedrock-pc will attempt to open a window via the winit Rust library, which involves starting a graphical event loop. To intiantiate the event loop under Wayland, winit will use the dlopen Linux system call to load the Wayland system library (either libwayland-client.so.0 or libwayland-client.so) and the XKB system library (libxkbcommon.so.0 or libxkbcommon.so). In our case, dlopen wasn’t able to find these libraries by itself, but we were able to manually find these library files and then add their paths to the LD_LIBRARY_PATH environment variable (which is checked by dlopen when looking for libraries).

You’ll be able to check if you have any of these issues by running the following command and observing the output:

$ echo "" | br asm | br --verbose --mode=graphical
[INFO]: Reading program from standard input...
[INFO]: Loaded program from standard input (0 bytes)
[INFO]: Program does not contain metadata
[FATAL]: Could not start graphical event loop