Download OC-Wasm — Minecraft Mods — MetaMods

OC-Wasm

Active

Downloads

0

Last update

1 year ago
Client
Technological
Addons

Overview of OC-Wasm

OC-Wasm is a CPU architecture for the OpenComputers mod designed to execute WebAssembly binary files.

Getting Started

To run a basic "hello world"-type application using OC-Wasm, follow these essential steps:

Building a Computer OC-Wasm doesn't add new items—standard OpenComputers components are used, just as when creating a Lua computer. After crafting a CPU or APU, hold it in your hand and press Shift+Right-Click to switch architectures—similar to switching between Lua 5.2 and 5.3. In the list of available architectures, select WebAssembly.

Installing BIOS Like any computer, a WebAssembly system requires a BIOS. If your program is very small (≤4 KB), it can be written directly to an EEPROM and used as a BIOS. However, programs are often too large for EEPROM, so a BIOS capable of loading the program from a disk is needed. OC-Wasm-BIOS solves this task: it loads the program from the /init.wasm file on the disk (similar to how the Lua BIOS loads /init.lua).

Since there is no ready-made item with a BIOS, you'll need to download the BIOS to a working computer (likely running Lua, for example using wget) and flash it to an EEPROM (e.g., with the flash command). Here is a one-line command for this:

wget https://gitlab.com/api/v4/projects/27476164/jobs/artifacts/main/raw/packed.wasm?job=Compile -O bios.wasm && flash bios.wasm OC-Wasm-BIOS

Creating an Application Application development is typically done outside Minecraft using standard programming tools. After compiling a .wasm file, name it init.wasm and place it in the root directory of a hard drive or floppy disk. This can be done in several ways:

  • Upload the program to the internet, insert the disk into a working computer, download the file using wget, and transfer the disk to the new computer.
  • Place the file directly in the appropriate location in your Minecraft save game folder if you have access to it. It is recommended to set bufferChanges to false in the filesystem section of your OpenComputers config file if you frequently use this method.

Booting the Computer After completing the preparatory steps, all that's left is to boot the computer!

Development in Rust

For convenient writing of OC-Wasm programs in Rust, a number of crates are available:

  • OC-Wasm-Cassette — simplifies using the Cassette async executor to run an async fn as the main function.
  • OC-Wasm-Sys — provides low-level FFI bindings. It is usually not used directly and serves as the foundation for other crates.
  • OC-Wasm-Safe — a set of wrappers over OC-Wasm-Sys that ensure memory safety, proper handling of opaque value descriptors, and mutual exclusion for system calls that cannot be executed concurrently.
  • OC-Wasm-Futures — a set of async futures that simplify writing OC-Wasm programs using async and await.
  • OC-Wasm-OpenComputers — high-level wrappers for component APIs supported by standard OpenComputers (e.g., redstone API, filesystem API, GPU API, etc.). + OC-Wasm-Immersive — high-level wrappers for component APIs supported by machines from the Immersive Engineering and Immersive Technology mods.

At the time of writing, the OC-Wasm-OpenComputers crate is not yet complete, and there are few libraries for high-level interaction with other mods (e.g., via the adapter). However, the community is encouraged to actively participate in the project's development—pull requests to OC-Wasm-OpenComputers and suggestions for new crates for other mods' content are welcome.

Development in Zig

A member of the OpenComputers community under the nickname AmandaC has started work on a repository with a Zig library and several small examples for OC-Wasm.

Other Versions

DCNick3 created a port of OC-Wasm for Minecraft 1.7.10. If you encounter issues while using it, report them in the corresponding repository, not here.

Technical Details

If you plan to work with a language that doesn't yet have support libraries, or simply want to understand the internal workings of the system, check out the OC-Wasm Javadoc.

Project members
Hawk778

Hawk778

Created: 6 Apr 2024

ID: 90457