1 个不稳定版本
0.2.0 | 2022年2月28日 |
---|
#16 in #mystery
2MB
1.5K SLoC
包含 (ELF 可执行文件/库, 3.5MB) src/lang/tokens/mod, (ELF 可执行文件/库, 3.5MB) src/lang/tokens/use
chip lox ide
chip 实现了 CHIP-8 虚拟机 - 维基百科
在这里浏览器中尝试 chip 游戏
chip 使用
- Rust In Action 第五章程序实现初始 cpu、运行、调用和操作码
[0000,00EE,2NNN,8XY4,_]
。 - CHIP-8 虚拟机描述 [维基百科]
- jlmbaka/chip8 的说明 [GitHub]
- google copilot 提示
- Cowgod 的 Chip-8 技术参考 v1.0 - C8TECH10.HTM
- 制作 CHIP-8 解释器的指南
- 精通 SuperChip
- Chip-8 设计规范 - 哥伦比亚大学
- CHIP-8 虚拟机规范
- 简易编程系统(1978年)
- Dream 6800 存档网站(1978年)
- 待办:理解 Verilog 实现 https://flint.cs.yale.edu/cs421/papers/x86-asm/asm.html https://bevy.rust-lang.net.cn/learn/book <- 简单的,新的应该更详细一些 https://deterministic.space/bevy-labels.html https://web.archive.org/web/20160514030144/http://chip8.com/downloads/Chip-8%20Pack.zip https://arzg.github.io/lang/19/ https://createlang.rs/ https://adriann.github.io/rust_parser.html https://domenicquirl.github.io/blog/parsing-basics/ https://github.com/jauhien/iron-kaleidoscope https://github.com/cdisselkoen/llvm-ir/blob/main/tests/basic_tests.rs
https://crates.io/crates/nom https://blog.adamchalmers.com/nom-chars/ https://github.com/clap-rs/clap https://bevy-cheatbook.github.io/ https://docs.rs/bevy/0.6.0/bevy/ https://matklad.github.io/2020/04/15/from-pratt-to-dijkstra.html https://blog.evanchen.cc/2015/03/14/writing/ https://danielkeep.github.io/tlborm/book
有趣的书籍 Rust in Action 编译解释器 https://craftinginterpreters.fullstack.org.cn/contents.html Rust for Rustaceans http://cliffle.com/p/dangerust/ https://docs.rust-embedded.org/book/intro/no-std.html 编程 Rust 2021 Rust 书 https://doc.rust-lang.net.cn/book/ https://doc.rust-lang.net.cn/nomicon https://github.com/Ixrec/rust-orphan-rules https://oswalt.dev/2021/06/polymorphism-in-rust/ http://forum.6502.org/viewtopic.php?p=69553&sid=72158e18396819d71eecdbd7c5ddd140#p69553 这 https://eater.net/8bit
设置
-
安装 rust >=1.59 (或启用 nightly/feature(destructuring_assignment))
-
克隆仓库~
-
进入仓库
-
对于 bevy 和快速编译直到一个单独的 crate,需要以下内容
sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev sudo apt-get install libwayland-dev libxkbcommon-dev sudo apt install mesa-vulkan-drivers sudo apt install lld sudo apt install clang cargo install -f cargo-binutils rustup component add llvm-tools-preview
-
有关具体说明,请参阅 bevy 书籍
-
此安装是为带有 nvidia gtx 的 ubuntu 笔记本电脑进行的。我相信其中一些是不必要的。
-
为了使用默认的稳定 rust 和 g++/默认的链接器,
-
您可能需要修改或删除
./.cargo/config.toml
-
在发布时,必须在
Cargo.toml
中禁用bevy
的 'dynamic
' 功能 -
cargo run
指令集
CHIP-8 有 35 个指令,都是两个字节长,以大端格式存储。
符号表
指令表中的指令列中的符号可以解释如下
符号 | 说明 |
---|---|
NNN | 地址 |
KK | 8 位常数 |
N | 4 位常数 |
X | 4 位寄存器标识符 |
Y | 4 位寄存器标识符 |
PC | 程序计数器 |
I | 16 位寄存器(用于内存地址)(类似于空指针) |
VN | 16 个可用变量之一。N 可以是 0 到 F(十六进制) |
指令表
下表列出了 35 个 CHIP-8 指令,以十六进制表示。
在这些指令中,1/35 已在 chip 中实现(表情符号表示实现状态。)
| Implemented | Opcode | Explanation |
| ----------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 🌱 | 0000 | Returns the program. |
| | 00E0 | Clears the screen. |
| | 00EE | Returns from a subroutine. |
| | 0NNN | Calls RCA 1802 program at address NNN. Not necessary for most ROMs. |
| | 1NNN | Jumps to address NNN. |
| | 2NNN | Calls subroutine at NNN. |
| | 3XNN | Skips the next instruction if VX equals NN. |
| | 4XNN | Skips the next instruction if VX doesn't equal NN. |
| | 5XY0 | Skips the next instruction if VX equals VY. |
| | 6XNN | Sets VX to NN. |
| | 7XNN | Adds NN to VX. |
| | 8XY0 | Sets VX to the value of VY. |
| | 8XY1 | Sets VX to VX or VY. |
| | 8XY2 | Sets VX to VX and VY. |
| | 8XY3 | Sets VX to VX xor VY. |
| 🌱 | 8XY4 | Adds VY to VX. VF is set to 1 when there's a carry, and to 0 when there isn't. |
| | 8XY5 | VY is subtracted from VX. VF is set to 0 when there's a borrow, and 1 when there isn't. |
| | 8XY6 | Shifts VX right by one. VF is set to the value of the least significant bit of VX before the shift. |
| | 8XY7 | Sets VX to VY minus VX. VF is set to 0 when there's a borrow, and 1 when there isn't. |
| | 8XYE | Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift. |
| | 9XY0 | Skips the next instruction if VX doesn't equal VY. |
| | ANNN | Sets I to the address NNN. |
| | BNNN | Jumps to the address NNN plus V0. |
| | CXNN | Sets VX to the result of a bitwise and operation on a random number and NN. |
| | DXYN | Sprites stored in memory at location in index register (I), 8bits wide. Wraps around the screen. If when drawn, clears a pixel, register VF is set to 1 otherwise it is zero. All drawing is XOR drawing (i.e. | it toggles the screen pixels). Sprites are drawn starting at position VX, VY. N is the number of 8bit rows that need to be drawn. If N is greater than 1, second line continues at position VX, VY+1, and so on. |
| | EX9E | Skips the next instruction if the key stored in VX is pressed. |
| | EXA1 | Skips the next instruction if the key stored in VX isn't pressed. |
| | FX07 | Sets VX to the value of the delay timer. |
| | FX0A | A key press is awaited, and then stored in VX. |
| | FX15 | Sets the delay timer to VX. |
| | FX18 | Sets the sound timer to VX. |
| | FX1E | Adds VX to I.</sup> |
| | FX29 | Sets I to the location of the sprite for the character in VX. Characters 0-F (in hexadecimal) are represented by a 4x5 font. |
| | FX33 | Stores the Binary-coded decimal representation of VX, with the most significant of three digits at the address in I, the middle digit at I plus 1, and the least significant digit at I plus 2. (In other | words, take the decimal representation of VX, place the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2.) |
| | FX55 | Stores V0 to VX in memory starting at address I.</sup> |
| | FX65 | Fills V0 to VX with values from memory starting at address I.</sup> |
| 🌱 | _ | Panic. |
有关 CHIP-8 的更多信息,可以在 维基百科 上找到。
安装
由于程序以源代码形式提供,因此您需要将其编译到目标平台。因此,您需要拥有完全工作的 Rust 安装。一旦程序编译完成,您就可以从命令提示符中运行它,而无需安装。有关使用说明,请参阅下一节。
Rust Nightly 开发
此功能为实验性,需要夜间渠道。请参阅https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html https://github.com/rust-lang/rfcs/issues/372。夜间必须包含:rls, rust-src, rust-analysis。有时夜间不一定构建这些组件。请在此处查看最新状态:https://rust-lang-nursery.github.io/rust-toolstate/ 或在此处查看:https://rust-lang.github.io/rustup-components-history/ 例如,在2021-01-10,rls在夜间构建的最新时间是2021-12-05,因此:"rust-client.channel": "nightly-2021-12-05",
用法
chip读取一个包含要运行的虚拟机上的程序的输入文件的程序。要从命令提示符启动程序,请输入以下指令。
chip8 [PATH_TO_CHIP8_FILE]
许可
请参阅名为LICENSE的文件。
联系方式
- [email protected]
- dezren39
依赖关系
~60MB
~1M SLoC