Skip to content
Snippets Groups Projects
Verified Commit 9cdbc0fe authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial support for conditional quirks

parent 0d210fb3
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ crate-type = ["cdylib", "rlib"]
[features]
wasm = ["wasm-bindgen"]
quirks = []
[dependencies]
getrandom = { version = "0.2", features = ["js"] }
......
......@@ -35,6 +35,12 @@ You can check a working version of the emulator at **[chip-ahoyto.joao.me](https
| Cloudfare | `True` | [prod.chip-ahoyto.pages.dev](https://prod.chip-ahoyto.pages.dev) |
| Cloudfare | `False` | [master.chip-ahoyto.pages.dev](https://master.chip-ahoyto.pages.dev) |
## Crate Features
| Name | Description |
| -------- | ------------------------------------------------------------------------ |
| `quirks` | Allows CHIP-8 quirks runtime evaluation, comes at a performance penalty. |
## Build
### WASM for Node.js
......
......@@ -18,6 +18,24 @@ const KEYS_SIZE: usize = 16;
/// the initial PC position for execution.
const ROM_START: usize = 0x200;
#[cfg(feature = "quirks")]
macro_rules! shifting {
( $self:expr, $x:expr, $y:expr, $shift:tt ) => {
if $self.quirks.shifting {
$self.regs[$x] = $self.regs[$x] $shift 1;
} else {
$self.regs[$x] = $self.regs[$y] $shift 1;
}
}
}
#[cfg(not(feature = "quirks"))]
macro_rules! shifting {
( $self:expr, $x:expr, $y:expr, $shift:tt ) => {
$self.regs[$x] = $self.regs[$y] $shift 1;
}
}
#[derive(PartialEq)]
enum WaitVblank {
NotWaiting,
......@@ -255,11 +273,7 @@ impl Chip8 for Chip8Neo {
}
0x6 => {
self.regs[0xf] = self.regs[x] & 0x01;
if self.quirks.shifting {
self.regs[x] >>= 1;
} else {
self.regs[x] = self.regs[y] >> 1;
}
shifting!(self, x, y, >>);
}
0x7 => {
self.regs[0xf] = (self.regs[y] > self.regs[x]) as u8;
......@@ -267,11 +281,7 @@ impl Chip8 for Chip8Neo {
}
0xe => {
self.regs[0xf] = (self.regs[x] & 0x80) >> 7;
if self.quirks.shifting {
self.regs[x] <<= 1;
} else {
self.regs[x] = self.regs[y] << 1;
}
shifting!(self, x, y, <<);
}
_ => panic!(
"unimplemented instruction 0x8000, instruction 0x{:04x}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment