lets try clippy

This commit is contained in:
2024-10-30 09:45:18 -04:00
parent dfce9bf9fe
commit 4fb2d6af29
10 changed files with 491 additions and 362 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ use log::{debug};
use crate::chip8::delay_timer::DelayTimer;
use crate::chip8::keypad::Keypad;
use crate::chip8::quirk_modes::QuirkMode;
use crate::chip8::quirk_modes::QuirkMode::Chip8;
use crate::chip8::registers::Chip8Registers;
use crate::chip8::sound_timer::SoundTimer;
use crate::chip8::stack::Chip8Stack;
@@ -101,7 +102,7 @@ impl Chip8Computer {
let low_byte = local_memory.peek(start_pc + 1) as u16;
let result = high_byte | low_byte;
let decoded_instruction =
Chip8CpuInstructions::decode(result);
Chip8CpuInstructions::decode(result, &self.quirk_mode);
// todo: THIS IS BAD AND IS A SIDE EFFECT
decoded_instruction.execute(self);
+47 -3
View File
@@ -8,6 +8,7 @@ use rand::{random, Rng};
use crate::chip8::computer::{Chip8Computer};
use crate::chip8::cpu_states::Chip8CpuStates::WaitingForKey;
use crate::chip8::instructions::Chip8CpuInstructions::*;
use crate::chip8::quirk_modes::QuirkMode;
use crate::chip8::util::InstructionUtil;
use crate::constants::{*};
@@ -259,6 +260,10 @@ pub enum Chip8CpuInstructions {
///
/// Load V0..VX from RPL user flags (X <= 7)
LIDR(u8),
/// 0xBxNN
///
/// Jump to Address XNN+Vx
JPX(u8, u16)
}
impl Chip8CpuInstructions {
@@ -308,12 +313,16 @@ impl Chip8CpuInstructions {
Chip8CpuInstructions::DIS => INST_DIS,
Chip8CpuInstructions::ENA => INST_ENA,
Chip8CpuInstructions::ORY(_, _) => INST_ORY,
JPX(_, _) => INST_JPX,
XXXXERRORINSTRUCTION => "XX ERROR XX",
}
}
pub fn operands(&self) -> String {
match self {
JPX(x, addr) => {
format!("0x{x:02x}, 0x{addr:04x}")
}
Chip8CpuInstructions::SYS(addr) |
Chip8CpuInstructions::JPI(addr) |
Chip8CpuInstructions::JPA(addr) |
@@ -528,6 +537,9 @@ impl Chip8CpuInstructions {
INST_LDD => {
LDD(param1 as u8)
}
INST_JPX => {
JPX(param1 as u8, param2)
}
_ => {
XXXXERRORINSTRUCTION
}
@@ -558,6 +570,7 @@ impl Chip8CpuInstructions {
Chip8CpuInstructions::SNEY(x_register, y_register) => 0x9000 | ((*x_register as u16) << 8) | ((*y_register as u16) << 4),
Chip8CpuInstructions::LDIA(addr) => 0xA000 | addr,
Chip8CpuInstructions::JPI(addr) => 0xB000 | addr,
JPX(x_register, addr)=> 0xB000u16 | ((*x_register as u16) << 12) | *addr ,
Chip8CpuInstructions::RND(x_register, byte) => 0xC000 | ((*x_register as u16) << 8) | (*byte as u16),
Chip8CpuInstructions::DRW(x_register, y_register, height) => {
0xD000 | ((*x_register as u16) << 8) | ((*y_register as u16) << 4) | (*height as u16)
@@ -585,7 +598,7 @@ impl Chip8CpuInstructions {
XXXXERRORINSTRUCTION => 0xFFFF
}
}
pub fn decode(input: u16) -> Chip8CpuInstructions {
pub fn decode(input: u16, quirk_mode: &QuirkMode) -> Chip8CpuInstructions {
let x_param = InstructionUtil::read_x_from_instruction(input);
let y_param = InstructionUtil::read_y_from_instruction(input);
let addr_param = InstructionUtil::read_addr_from_instruction(input);
@@ -596,10 +609,35 @@ impl Chip8CpuInstructions {
let last_nibble = (input & 0xF) as u8;
match input {
0x00C0..=0x00CF => Chip8CpuInstructions::SDN(last_nibble),
0x00C0..=0x00CF => {
match quirk_mode {
QuirkMode::Chip8 => {
XXXXERRORINSTRUCTION
}
QuirkMode::XOChip => {
SDN(last_nibble)
}
QuirkMode::SChipModern => {
SDN(last_nibble)
}
}
},
0x00E0 => Chip8CpuInstructions::CLS,
0x00EE => Chip8CpuInstructions::RET,
0x00FB => Chip8CpuInstructions::SRT,
0x00FB => {
match quirk_mode {
QuirkMode::Chip8 => {
// does not exist on Chip8
XXXXERRORINSTRUCTION
}
QuirkMode::XOChip => {
Chip8CpuInstructions::SRT
}
QuirkMode::SChipModern => {
Chip8CpuInstructions::SRT
}
}
},
0x00FC => Chip8CpuInstructions::SLF,
0x00FD => Chip8CpuInstructions::EXIT,
0x00FE => Chip8CpuInstructions::DIS,
@@ -856,6 +894,12 @@ impl Chip8CpuInstructions {
// The program counter is set to nnn plus the value of V0.
input.registers.poke_pc(input.registers.peek(0) as u16 + addr);
}
// 0xBxnn Jump to Xnn+Vx
JPX(vx_register, addr) => {
let x_reg_value: u16 = input.registers.peek(*vx_register) as u16;
let new_addr = *addr + x_reg_value;
input.registers.poke_i(new_addr);
}
Chip8CpuInstructions::RND(x, byte) => {
// Cxkk - RND Vx, byte
// Set Vx = random byte AND kk.
-1
View File
@@ -2,7 +2,6 @@
pub enum QuirkMode {
#[default]
Chip8,
SChipLegacy,
XOChip,
SChipModern
}
+1
View File
@@ -29,6 +29,7 @@ pub const INST_DRW: &str = "DRW";
pub const INST_EXIT: &str = "EXIT";
pub const INST_JPA: &str = "JPA";
pub const INST_JPI: &str = "JPI";
pub const INST_JPX: &str = "JPX";
pub const INST_BCD: &str = "BCD";
pub const INST_LDD: &str = "LDD";
pub const INST_LDF: &str = "LDF";