2 个版本
| 0.1.6 | 2022 年 6 月 7 日 |
|---|---|
| 0.1.5 | 2022 年 6 月 4 日 |
| 0.1.4 |
|
385 在 嵌入式开发 中
180KB
4K SLoC
psx-sdk-rs
这是一个基本的 SDK,可以在 PlayStation 1 上运行自定义 Rust 代码。它与 Rust nightly 版本 2022-06-03 或更高版本兼容。使用 rustup 按以下方式安装 Rust 工具链。
rustup update nightly
rustup component add rust-src --toolchain nightly
安装 cargo-psx
cargo-psx 是 cargo 的一个可选包装器,它设置了一些常用标志和参数,并将目标 JSON 复制到 crate 的目标目录。基本上,这允许你仅运行 cargo psx run 而不是
RUSTFLAGS="-Ccodegen-units=1 \
-Clink-arg=-Tpsexe.ld -Clink-arg=--oformat=binary" \
cargo run +psx -Zbuild-std=core \
-Zbuild-std-features=compiler-builtins-mem \
--target /path/to/mipsel-sony-psx.json
这需要创建和运行可执行文件所需的最少标志。
要安装
cargo install cargo-psx
要卸载
cargo uninstall cargo-psx
更多选项
cargo psx --help
用法
在 examples 目录中,有一些已经通过 mednafen、pcsx-redux 和/或 duckstation 中的 SCPH7001 NA BIOS 测试的演示。其他 BIOS 版本/区域可能也有效,但尚未经过测试。要尝试演示,首先请确保已在 examples/$DEMO/.cargo/config.toml 中安装了模拟器,然后从其目录运行 cargo psx run。
要在模拟器中手动选择可执行文件,首先使用 cargo psx build 构建项目,然后在 /path/to/crate/target/mipsel-sony-psx/release/ 目录中打开 .exe 文件。要使用 cargo psx run 与其他模拟器,请更改 mipsel-sony-psx 目标的 运行器。要将可执行文件打包成 ISO(例如,用于 CD-ROM 文件系统),请使用 mkpsxiso 或类似工具。
Mednafen
Mednafen 通常与以下 .cargo/config.toml 配置一起使用。获取标准输出可能需要将 psx.dbg_level 在 mednafen.cfg 中设置至少为 2。在加载 ISO 时似乎没有快速启动(跳过 BIOS)选项,因此 ISO 必须正确授权,因为 BIOS 会验证一些校验和。
[target.mipsel-sony-psx]
runner = "mednafen"
PCSX-Redux
PCSX-Redux 与以下 .cargo/config.toml 配置一起使用。请注意,-loadexe 必须是最后一个选项,因为 cargo psx run 在末尾传递可执行文件名。有关更多命令行选项,请参阅 此页面。
[target.mipsel-sony-psx]
runner = ["pcsx-redux", "-stdout", "-run", "-loadexe"]
要从命令行运行 ISO,请使用 pcsx-redux -stdout -run -iso $ISO_FILENAME。
DuckStation
DuckStation 用于调试非常有效,但它不与 cargo psx run 一起使用。问题在于命令将相对路径传递给运行器,但 DuckStation 仅接受命令行上的绝对路径。要使用 DuckStation,请使用 cargo psx build 构建项目,然后手动打开可执行文件。要运行 ISO,请使用 duckstation-qt -fastboot /full/path/to/$ISO_FILENAME。
程序模板
要创建一个新的程序,只需使用 cargo init 并将 psx = "*" 或 psx = { path = "/path/to/psx/crate" } 添加到 Cargo.toml 中的 [dependencies] 部分。然后替换 src/main.rs 中的以下模板
#![no_std]
#![no_main]
// This can be any import from the `psx` crate
// but there must be at least one.
use psx;
#[no_mangle]
fn main() {
}
no_std 是必需的,用于链接 core 包而不是 std 包。 no_main 通知 rustc 不要假设 程序的入口点。由于在 psx 包中定义的入口点期望调用一个 unmangled function,因此需要在 main 上设置属性。 main 函数不应返回,但返回类型可以是省略的(即 ())或 !。
文档
请参阅 docs.rs 以获取文档。要为 psx 的最新版本重新生成文档
cd psx
cargo doc --target mipsel-unknown-linux-gnu
然后在浏览器中打开 target/mipsel-unknown-linux-gnu/doc/psx/index.html。
有关 PlayStation 内部结构的文档,请参阅 nocash 规范。
测试
使用以下命令运行 psx 包中的测试。
cd psx/
cargo psx test