最初是我自己设计的 cursed ISA 的移植版,Computed 为嵌入式系统引入了一个 32 位自定义指令集架构(ISA)……在 Minecraft 中!
它提供什么?
Computed 所使用的系统 (mippi2) 与其他模组相比更为“传统”。你不需要编写纯 Lua 代码,也不必依赖具有固定资源需求、可能会占用大量性能的自定义 ROM。你可以随心所欲地进行开发,无需额外负担。
基本上,你可以编写汇编语言的子集来创建更高效的设备。
- 所有 Computed 设备都是虚拟机,但机器码通过非 JIT 风格编译的方式执行,以保持一定的安全性;同时假设 JVM 自身的 JIT 编译器能够在可能的情况下使用最快的原生指令来提升性能。这有望将攻击面缩小至 JVM 缓冲区处理方面,一旦该部分被攻破,整个 Minecraft 多人游戏都将面临严重问题。(简而言之,该模拟器以安全为首要目标)
- 扩展卡实际上是用 Java 编写的,这是出于性能考虑以及能够在游戏与虚拟机之间进行“桥接”的需要。这种代码执行机制意味着扩展卡只能通过用户安装的模组来添加。
我能做出的最佳类比是 Mojang 在其 已取消的类似 Minecraft 的太空模拟游戏 0x10ᶜ, 飞船计算机中使用的 DCPU-16 架构,其概念非常相似。
在资源使用方面,mippi2 已在以下配置下经过测试:
- 频率:50kHz <-> 150MHz
- RAM:4kB <-> 2GiB(后续可进一步提升)
- 虚拟 Java TTY 和红石卡。
在此 Alpha 版本中,默认系统配置为 64K RAM 和 1MHz 时钟,并安装了一张红石卡。随着更多扩展硬件的开发,这一配置将会改变。
mippi2 基于简化设计运行,目前仅支持一次处理一个 IRQ。从技术角度来看,你实际上是在操作相当于 20 世纪 80 年代末/90 年代初 的硬件。
一份包含稍多技术信息的 PDF 文档 可在此处获取。
计算机
虽然 Computed 的生存模式功能尚未完全实现,但计算机的合成配方如下:

放置后,你会发现它似乎……没什么反应。这是因为需要对其进行编程!可以使用任何类型的书(包括已签名的书)来完成此操作。

记得备份你的代码!
指令表
寄存器在汇编器中表示为 r[数字]。地址可以使用普通数字或标签名称。
| 指令 |
参数 |
描述 |
NOP |
[] |
不执行任何操作。 |
LOAD |
[寄存器, 地址] |
从地址加载两个字节。 |
LOADI |
[寄存器, 值] |
加载你指定的立即数值。 |
LOADS |
[寄存器, 偏移量] |
类似于 LOAD,但使用相对偏移量。 |
STORE |
[寄存器, 地址] |
将寄存器存储到地址。 |
STORI |
[寄存器] |
在当前地址从寄存器写入 2 个字节。 |
STORS |
[寄存器, 偏移量] |
使用相对偏移量存储寄存器。 |
ADD |
[寄存器, 寄存器] |
等效于执行 A += B(有符号)。 |
ADDU |
[寄存器, 寄存器] |
等效于执行 A += B(无符号)。 |
SUBU |
[寄存器, 寄存器] |
等效于执行 A -= B。(无符号)。 |
XOR |
[寄存器, 寄存器] |
等效于执行 A ^= B。 |
OR |
[寄存器, 寄存器] |
等效于执行 A |= B。 |
AND |
[寄存器, 寄存器] |
等效于执行 A &= B。 |
JMP |
[地址] |
跳转到指定地址/标签 |
JMPR |
[寄存器, 寄存器] |
跳转到由 (整数) (A << 16) | B 形成的地址 |
BGT |
[寄存器, 寄存器, 地址] |
如果 A > B,则跳转到指定地址/标签 |
HALT |
[值] |
如果 > 0,暂停指定数量的周期。如果为 0,停止机器。 |
对于此类系统,一种常见的技巧是执行 B XOR A 类型的操作,因为这实际上相当于复制一个寄存器,并且在某些情况下可用于比 x86 mov 更快地将寄存器清零(A XOR A)。
有符号减法可以通过使用带有现有符号位的值轻松完成 ADD 操作。SUBU 的存在仅是为了允许无符号减法。
设备扩展
Computed 机器具有高度可配置性,尤其是当你想要创建新硬件时!
一个简单的 ExpansionCard 类可以扩展以实现当读取总线、写入总线或卡片自行运行时所执行的行为!
未来将添加示例 3D 视频卡。一旦 API 完全完善,这些可以作为物品提供给机器插入使用。
红石支持
红石支持目前由模组本身提供,尽管红石更新目前还比较混乱。
可以通过写入寄存器来设置方向(从地址 56565 开始)的高低电平来设置这些状态。要将东侧通道设置为满强度(15),可以编写如下片段:
; 创建一个用于跳转的标签
SETHIGH:
; 将 r1 设置为 15
LOADI r1 15
; 将东侧设置为强度 15
STORE r1 56575
管理员注意:汇编文件在编译前会临时存储在可用的临时目录中(并指示 JVM 在完成后删除)。这意味着如果不是在真正的 tmpfs 上,可能会被某人利用来耗尽存储空间。这种情况通常只会在服务器因 JVM 错误而反复崩溃时发生,且 99% 的服务器无需担心此问题。
设备模拟完全在 Java 中执行,因此所有架构无需单独编译即可正常运行。然而,JVM 处理字节缓冲区的方式 可能 会导致字节序(endianness)方面的冲突,不过我本人尚未对此进行测试。
Originally a port of my own cursed ISA, Computed introduces a 32-bit custom ISA for embedded systems... in Minecraft!
What does it offer?
The system used by Computed (mippi2) is more 'traditional' compared to other mods. Instead of writing pure Lua, or relying on custom ROMs with fixed resource requirements that might eat up more of your performance, you get to do whatever you want and leave it at that.
Basically, you can write a subset of assembly language to make more efficient devices.
- All Computed devices are virtual machines, however machine code is executed without JIT-style compilation to keep things a bit safer, and with the assumption that the JVM's own JIT can improve performance by using the fastest native instruction where possible. This hopefully should reduce the attack surface to JVM buffer handling, which if compromised would also mean that Minecraft Multiplayer in general is screwed. (TL:DR, the emulator aims to be safe instead)
- Expansion cards, however, are effectively written in Java for the sake of performance and being able to 'bridge' between the game and VM. This code execution is why cards can only be added via user-installed mods.
The best comparison I could make is Mojang's own DCPU-16 architecture on the ship computer in their cancelled Minecraft-like space sim, 0x10ᶜ, which has a very similar concept.
In terms of resource use, mippi2 is tested with the following configurations:
- Frequency: 50kHz <-> 150MHz
- RAM: 4kB <-> 2GiB (can be raised further later)
- Virtual Java TTY and Redstone Cards.
In this alpha release, the default system configuration is 64K of RAM alongside a 1MHz clock, with a Redstone Card installed. This will be changed once more expansion hardware is made.
mippi2 operates off of a simplified design with support for (currently) one IRQ at a time. Technologically, you're effectively working with hardware equivalent to the late 1980s/early 1990s.
A PDF with slightly more tech info is available here.
Computers
While the survival features of Computed aren't fully implemented, the recipe for a Computer is as follows:

When placed, you'll notice it doesn't really... do much. This is because it has to be programmed! This is done using any kind of text book, including signed ones.

Remember to back-up your code!
Instruction Table
Registers are written as r[number] in the assembler. Addresses use regular numbers OR a label name.
| Instruction |
Arguments |
Description |
NOP |
[] |
Does nothing. |
LOAD |
[register, address] |
Loads two bytes from the address. |
LOADI |
[register, value] |
Loads the immediate value you specify. |
LOADS |
[register, offset] |
like LOAD, but with relative offset. |
STORE |
[register, address] |
Store register to address. |
STORI |
[register] |
Writes 2 bytes from a register at current address. |
STORS |
[register, offset] |
Stores register with relative offset. |
ADD |
[register, register] |
Effectively does A += B (Signed). |
ADDU |
[register, register] |
Effectively does A += B (Unsigned). |
SUBU |
[register, register] |
Effectively does A -= B. (Unsigned). |
XOR |
[register, register] |
Effectively does A ^= B. |
OR |
[register, register] |
Effectively does A |= B. |
AND |
[register, register] |
Effectively does A &= B. |
JMP |
[address] |
Jump to address/label |
JMPR |
[register, register] |
Jump to address formed by (integer) (A << 16) | B |
BGT |
[register, register, address] |
Jump to address/label if A > B |
HALT |
[value] |
If > 0, halt for value's cycles. If 0, stop machine. |
A common hack for systems like this is to do a B XOR A style operation, as this effectively copies a register, and has been situationally used to zero a register (A XOR A) faster than an x86 mov.
Signed subtraction can easily be done via ADD using values with existing sign bits. SUBU exists only to allow for unsigned subtraction.
Device Expansion
Computed machines are very configurable, especially if you want to create new hardware!
A simple ExpansionCard class can be extended to implement behaviours when the card bus is read from, written to, or is just doing its own thing!
In the future, an example 3D video card will be added. These can be provided as items to insert into machines once the API is fully complete.
Redstone support
Redstone support is currently provided by the mod itself, although redstone updates are a messy for now.
These can be set by writing a register to set a direction (starting from address 56565) high/low. To turn the east channel to full (15) strength, write a snippet like:
; Make a label for jumping
SETHIGH:
; set r1 to 15
LOADI r1 15
; set east to strength 15
STORE r1 56575
Note for admins: assembly files are temporarily stored before compilation (with the JVM instructed to delete after) in whatever the available temporary directory is. This means that if not on a true tmpfs, this could be spammed by someone to use up storage. This only really occurs if your server repeatedly crashes with a JVM error, and 99% of servers won't have to worry about this.
The device emulation is entirely performed within Java, so all architectures will function without separate compilation. However there may be potential for how the JVM treats the byte buffer to cause conflicts regarding endianness, however I have not tested this myself.
评论 0
登录后参与评分
还没有评论,来抢沙发吧