Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:custom_oses:zh [2023/01/07 08:25]
yhn [什么可用?]
tutorial:custom_oses:zh [2023/12/03 10:56] (current)
hfsr [其他东西]
Line 1: Line 1:
-定义操作系统+编写操作系统
 =================== ===================
-从OpenComputers 1.3开始,计算机需要一个”操作系统才能运行 ​OpenOS不再内置。 从1.4(.2?) 您甚至需要在计算机使用EEPROM充当机器的BIOS。 虽然这使得组装计算机更麻烦,但为想要编写自己的操作系统的人开辟了更多可能这就是本文的全部内容+从OpenComputers 1.3开始,电脑需要操作系统才能运行OpenOS不再内置。 从1.4.2?)开始,您甚至需要在电脑安装EEPROM,以充当机器的BIOS。 虽然这使得组装电脑变麻烦了一点,但这也为想要编写自己的操作系统的人提供了更多可能;本文的主题就是编写操作系统
  
-引导+引导启动
 ------- -------
-现在唯一内置的是启动 BIOS 的“机器”。这个“机器”包装器是一个不可编辑的Lua脚本,负责设置沙箱和与“主机”端事物(即Java / Scala)的超低级交互。打开计算机后,将加载并运行该脚本。在稳定环境后,它会查找EEPROM,并尝试将其数据作为Lua脚本运行。如果失败,计算机将崩溃。否则,将运行该 BIOS。对于提供的Lua BIOS(使用EEPROM +手册制作),它将执行以前由机器本身完成的操作:+现在唯一内置的是用来启动BIOS的“机器”。这个“机器”包装器是一个不可编辑的Lua脚本,负责创建沙箱和与“主机”端事物(即Java / Scala)的特别底层的交互。电脑上电后,将加载并运行该脚本。在建立完成环境后,它会查找EEPROM,并尝试将其数据作为Lua脚本运行。如果失败,计算机将崩溃。否则,将运行该BIOS。对于模组提供的Lua BIOS(使用 EEPROM +手册制作),它将执行以前由机器本身完成的操作:
  
-  - 1.它查找文件系统并通过`computer.setBootAddress`设地址(通过`computer.getBootAddress`读取). +  - 1.它查找先前由`computer.setBootAddress`设定的地址对应的文件系统(可通过`computer.getBootAddress`读取此地址)。 
-  - 2.在该文件系统上,它尝试加载并执行名为`init.lua`的文件. +  - 2.在该文件系统上,它尝试加载并执行名为`init.lua`的文件 
-  - 3.如果成功了,现在由用户脚本控制。如果失败,它将遍历所有当前文件系统,再次执行步骤2,直到成功为止.+  - 3.如果成功了,那么任务完成,由用户脚本接管控制。如果失败,它将遍历所有当前文件系统,再次执行步骤2,直到成功为止
   - 4.如果没有找到可用的`init.lua`脚本。计算机将崩溃并显示`no bootable medium found`错误.   - 4.如果没有找到可用的`init.lua`脚本。计算机将崩溃并显示`no bootable medium found`错误.
  
Line 16: Line 16:
 什么可用? 什么可用?
 ----------------- -----------------
-wiki上记录了一些库,它们实际上是OpenOS的一部分,所以当你实现自己的操作系统时这些库不会由你使用。最值得注意的是,包括`io``package`和`filesystem`库. 有关 ​init 脚本中可用内容的明确参考,请查[[https://​github.com/​MightyPirates/​OpenComputers/​blob/​master-MC1.12/​src/​main/​resources/​assets/​opencomputers/​lua/​machine.lua|machine.lua ​script for your current OpenComputers version](英文). 以下列表不能保证完整或最新+Wiki 上记录了一些库,它们实际上是 OpenOS 的一部分,所以当你实现自己的操作系统时这些库无法使用。最值得注意的是,其中包括`io``package`和`filesystem`库。要获取init脚本中可用内容的明确参考,请查看系统内核代码或[[https://​github.com/​MightyPirates/​OpenComputers/​blob/​master-MC1.12/​src/​main/​resources/​assets/​opencomputers/​lua/​machine.lua|你当前OpenComputer模组版本对应的machine.lua脚本]英文)。 ​以下列表不能保证完整性与/时效性
  
 ```lua ```lua
Line 168: Line 168:
 unicode.wtrunc unicode.wtrunc
  
--- Lua 5.3 only:+-- Lua 5.3:
 coroutine.isyieldable coroutine.isyieldable
  
Line 191: Line 191:
 ``` ```
  
-Accessing components in BIOS+BIOS中访问组件
 ----------------- -----------------
-Unlike in OpenOS ​you don't have the primary system for components in BIOS. That means you cannot just write `component.redstone.setOutput`, you have to manually create your proxy for the component first. For several reasons the proxy system is provided via the machine itself, so you can still use that. To get a proxy, use the `component.proxy` ​method. It expects the address of the component to wrap. You can either write that down manually, or get the list of components using `component.list` ​and go from there.+OpenOS不同,BIOS没有首选组件系统。这意味着你不能只写`component.redstone.setOutput`,而是必须先手动为组件创建代理对象。出于多种原因,代理对象系统是通过机器本身提供的,因此您仍然可以使用它。若要获取代理对象,请使用`component.proxy`方法。此函数需要你提供打算包装的组件地址。 您可以手动写下来,或者用`component.list`来获得组件的列表并从中获取。
  
-For example, to get the first best redstone component, you can do the following:+比如说,要获得第一个红石组件,您可以执行以下操作:
 ```lua ```lua
 local r = component.proxy(component.list("​redstone"​)()) local r = component.proxy(component.list("​redstone"​)())
 ``` ```
-This works because ​`component.list` ​returns a Lua iterator: a function that can be called repeatedly to get the next element in whatever it iterates over, returning ​`nil` once there are no more elements.+这行代码可以工作,因为`component.list`返回一个 ​Lua 迭代器——一个可重复调用来获得下一个元素的函数,当没有元素时返回`nil`
  
-A few more things+其他东西
 ----------------- -----------------
-When an init script returns, the computer powers down, so you'll want to have a "main loop" in there, regardless of how you structure your OS otherwiseSignals must be processed using `computer.pullSignal`, you're free to use any model to provide this to programs running in your OS you please - this is what OpenOS' ​`event.pull` ​does, for example.+当`init.lua`脚本返回(结束运行)的时候,电脑将会关机,所以无论您如何构建操作系统,在脚本里都需要有一个“主循环”。 ​  
 +信号必须使用`computer.pullSignal`处理,您可以自由使用任何模块将此函数的功能提供给在操作系统中运行的程序——例如,OpenOS中的`event.pull`就是这么操作的。
  
-You'll also want to take care of setting up attached components during your OS' boot routine, such as binding GPUs to screens.+您还需要在操作系统的启动流程中设置连接到电脑的组件,例如将GPU绑定到屏幕。
  
-Aside from that, go crazy, be creative!+除此之外,发挥你最疯狂的想象吧!