This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
JackMacWindows's profile picture

CraftOS-PC 2: A small & speedy ComputerCraft emulator written in native code

Started by JackMacWindows, 07 August 2019 - 05:50 AM
JackMacWindows #1
Posted 07 August 2019 - 07:50 AM

Current Version: v2.2.6
After completing CraftOS-PC and using it for a while, I noticed that it runs relatively slowly compared to other real terminals. I also didn't like that it was tied to the JVM, which can use up quite a bit of my system's resources. (I'm also more on the new side when it comes to Java programming.) I started to ponder the idea of writing a ComputerCraft interpreter entirely in C. I first wrote a proof-of-concept called LinuxCC that used an ncurses terminal and ran in the root of the hard drive. After discovering how easy it was to write (not without ending up adding some C++ into the mix), I decided to bring it to a full product as a successor to the original CraftOS-PC. CraftOS-PC 2 uses the original Lua 5.1 API and SDL to create a terminal that runs CraftOS quickly while eliminating many of the bugs in LuaJ that plagued CraftOS. I've designed CraftOS-PC 2 to emulate ComputerCraft as close as possible.

CraftOS-PC 2's features:
  • Emulates an advanced computer with touch support, or a standard computer
  • Full support of ComputerCraft's API
  • Full support of CraftOS-PC Classic's API, including:
  • periphemu API for attaching peripherals (monitor, printer, drive, modem, debugger)
  • mounter API for mounting local drives inside ComputerCraft
  • Terminal graphics mode for direct pixel writing
  • config API for adjusting the internal ComputerCraft configuration
  • Resizable terminals
  • HTTP server support
In addition, I've added some new features exclusive to CraftOS-PC 2:
  • Screenshot & GIF recording support (thanks for the idea, SquidDev)
  • 256-color graphics mode support
  • Debugger featuring GDB-style commands and profiler
  • More features soon?
I have also ported features from other ComputerCraft extensions:
  • CC: Tweaked: WebSocket support
  • CC: Tweaked: Native IO API
  • CCEmuX: Multiple computer support
  • CCEmuX: modem peripheral
The main selling point of CraftOS-PC 2 is its speed. CraftOS-PC 2 is up to 2x faster than CraftOS-PC Classic and 90% faster than CCEmuX[1]. It boots to the CraftOS shell immediately. And it's light on system resources: it only uses between 10~30 MB of memory while running, while CraftOS-PC Classic and CCEmuX both use over 100 MB of memory at startup. Since CraftOS-PC 2 doesn't have to rely on a JVM or intermediate bytecode, it can run much faster than its Java-based competitors. Lastly, CraftOS-PC 2 only takes up about 7 MB of space on disk, which is very lightweight compared to CraftOS-PC Classic's JAR size of 20 MB.
You can download the latest version of CraftOS-PC 2 on the official website or on GitHub. I have included both Windows and Mac builds in the release; Ubuntu users can install craftos-pc from the official PPA (ppa:jackmacwindows/ppa).
CraftOS-PC 2 is licensed under the MIT license: see LICENSE in the repository for more information.
[1]Based on SciMark test results on CraftOS-PC Classic, CCEmuX, and CraftOS-PC 2 (results here). Benchmarks performed on an Intel Core i5 system clocked at 3.7 GHz with 16 GB RAM installed; running on Windows 10 1903 with no apps running. Synthetic benchmarks may not accurately represent actual performance gain.
Edited on 16 March 2020 - 06:01 AM
SquidDev #2
Posted 07 August 2019 - 12:31 PM
Always nice to see another emulator, goodness knows CCEmuX needs the competition. Very happy to see you're looking into adding some of CC:T's features too.

One thing I'd love to see in an emulator (AFAIK, only copy-cat does this, and it's not super usable), is built-in support for taking screenshots and screen recordings. Obviously it's possible to do this already - recgif and your OS's screenshot tools suffice, but building it into the emulator would be very cool.

while eliminating many of the bugs in LuaJ that plagued CraftOS. I've designed CraftOS-PC 2 to emulate ComputerCraft as close as possible.
This is always a bit of a tricky one - some LuaJ bugs (mostly tail-calling "C" functions) are depended on by a fair few CC programs. Would definitely be interesting to see if any programs out-right break using PUC Lua.

The main selling point of CraftOS-PC 2 is its speed. CraftOS-PC 2 is up to 2x faster than CraftOS-PC Classic and 90% faster than CCEmuX[1]. It boots to the CraftOS shell immediately.
One day when Graal is stable, we'll be able to AOT compile CCEmuX, and at least it will start up fast :)/>.
Edited on 07 August 2019 - 10:31 AM
JackMacWindows #3
Posted 13 August 2019 - 06:23 AM
Beta 2 is now released on GitHub. It adds support for the rest of the CraftOS-PC Classic APIs, as well as some new features and bugfixes.

One thing I'd love to see in an emulator (AFAIK, only copy-cat does this, and it's not super usable), is built-in support for taking screenshots and screen recordings. Obviously it's possible to do this already - recgif and your OS's screenshot tools suffice, but building it into the emulator would be very cool.
That is a good idea! I've added screenshot support to the latest beta (press F2), and I plan to add GIF recording support in the future.

while eliminating many of the bugs in LuaJ that plagued CraftOS. I've designed CraftOS-PC 2 to emulate ComputerCraft as close as possible.
This is always a bit of a tricky one - some LuaJ bugs (mostly tail-calling "C" functions) are depended on by a fair few CC programs. Would definitely be interesting to see if any programs out-right break using PUC Lua.
I might add a configuration option to emulate the bugs in LuaJ for compatibility with programs that rely on them, though it might not be implemented until after the 2.0 release.
Lignum #4
Posted 13 August 2019 - 07:13 AM
The emulator doesn't run on Windows since the installer doesn't seem to include SDL2. I'm guessing the same goes for Lua.
JackMacWindows #5
Posted 14 August 2019 - 12:27 AM
The emulator doesn't run on Windows since the installer doesn't seem to include SDL2. I'm guessing the same goes for Lua.
Forgot the Windows SDL & Lua libraries are dynamically linked. I updated the installer to include the DLLs.