#chip #challenge #ide #lox #cpu #mystery #chip8

nightly bin+lib chip_lox

(占位符) 神秘、挑战、游戏、IDE 👁️‍🗨️

1个不稳定版本

0.2.0 2022年2月28日

#16 in #mystery

MIT/ApacheLGPL-3.0+

2MB
1.5K SLoC

包含 (ELF exe/lib, 3.5MB) src/lang/tokens/mod, (ELF exe/lib, 3.5MB) src/lang/tokens/use

chip lox ide

chip实现了CHIP-8虚拟机 - 维基百科

在这里尝试浏览器的chip游戏

chip是用

有趣的书籍 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 开发

此功能为实验性,需要夜间渠道。请参阅此处 此处夜间必须包含:rls, rust-src, rust-analysis有时夜间无法构建这些组件。请在此处查看最新状态:此处或在此处查看:此处例如,在2021-01-10,rls在夜间最后一次构建是在2021-12-05,因此:"rust-client.channel": "nightly-2021-12-05",

用法

chip读取包含要在虚拟机上运行的程序的输入文件。要从命令提示符启动程序,请输入以下指令。

chip8 [PATH_TO_CHIP8_FILE]

许可协议

请参阅名为LICENSE的文件。

联系方式

依赖项

~60MB
~1M SLoC