Skip to content

Repository files navigation

English | 中文

WASM Addon for OpenComputers mod on 1.7.10

This mod adds a new type of CPU for OpenComputers mod.

This CPU will boot from the first DiskDrive or FloppyDisk that has /init.wasm file on the root dir.

This mod uses a heavily modified version of chicory wasm engine and binary excutables of emscripten c/c++ to wasm compiler sdk.

This mod is design to work with GTNH fork of OpenComputers, might not work with other forks.

Why WASM?

Lua can operate only one direct call per tick.
WASM runs directly on main thread, so you can do complicated jobs in one single tick.

Main thread? Sounds unfriendly with TPS!

That's true.
So there's a opcodes-per-tick limit, the program will yield and continue to execute next tick if you reach the limit.
This mod is not to replace Lua-based CPU, use Lua if multiple direct calls per tick is not a rigid demand.

How to run .wasm in game

Code in game then compile it on server

If you're playing SP on windows, or playing on a windows server, the compiler is unpacked automically.
If not (or you used the -nowin version), you should setup emsdk yourself. see wiki.
Then install a Compiler Card and Compiler FloppyDisk in a Lua Computer Case.
Run install to install the Compiler FloppyDisk.
Then use emcc or em++ command to compile your c/c++ source file, just like you do outside the game.

Code outside the game then upload .wasm to server

To create a .wasm file outside the game, you should write in .c/.cpp then compile it with emscripten.
see wiki.

Rename this file to 'init.wasm', then upload it to the Opencomputers DiskDive root directory.
You can use install a SFTP Card on Computer Case with Lua CPU. Then run in Lua:

diskdrive=component.filesystrem -- the primary filesystrem might be your floppy disk
component.sftp.start(diskdrive.address,'username','passwd')

If it shows 'Started.', you can use a SFTP client MobaXterm/FileZilla/...) to upload/modify files.
Use the username and password you set in Lua to login, you can attach multiple filesystem, but the 'username' has to be unique.
Will use port 2222 by default, you can change it in config, or set it to -1 to disable SFTP.
Note: SFTP is not FTP, ftp://localhost:2222 won't work!

About

WASM support for Minecraft OpenComputers mod

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages