Address some of clippys concerns

This commit is contained in:
Kevin Hamacher 2020-02-20 20:10:19 +01:00
parent ab7ee0988f
commit 4cf6225133
6 changed files with 33 additions and 35 deletions

View File

@ -948,10 +948,8 @@ impl CPU {
// Check for interrupts.
if self.ime {
self.check_interrupts(true);
} else if self.halted {
if self.check_interrupts(false) {
self.halted = false;
}
} else if self.halted && self.check_interrupts(false) {
self.halted = false;
}
let mut cycles: u8 = 255;
@ -964,8 +962,8 @@ impl CPU {
"{:#06x}: [SP: {:#04X}] i={:02X}. ",
&self.ip, &self.sp, &instruction
);
for i in 0..6 {
print!("{}: {:02X} ", REG_NAMES[i], self.get_8bit_reg(i));
for (idx, reg) in REG_NAMES.iter().enumerate() {
print!("{}: {:02X} ", reg, self.get_8bit_reg(idx));
}
print!("A: {:02X} ", self.regs[REG_A]);
print!("I: {:02X} ", self.interconnect.read_byte(0xFFFF));
@ -1000,9 +998,10 @@ impl CPU {
let carry = val & 0x80 == 0x80;
self.set_clear_flag(FLAG_C, carry);
if !carry {
self.regs[REG_A] = self.regs[REG_A] << 1;
self.regs[REG_A] <<= 1;
} else {
self.regs[REG_A] = self.regs[REG_A] << 1 | 1;
self.regs[REG_A] <<= 1;
self.regs[REG_A] |= 1;
}
self.clear_flag(FLAG_Z);
self.clear_flag(FLAG_N);
@ -1038,9 +1037,10 @@ impl CPU {
let val = self.regs[REG_A];
self.set_clear_flag(FLAG_C, val & 1 == 1);
if val & 1 == 0 {
self.regs[REG_A] = self.regs[REG_A] >> 1;
self.regs[REG_A] >>= 1;
} else {
self.regs[REG_A] = self.regs[REG_A] >> 1 | 0x80;
self.regs[REG_A] >>= 1;
self.regs[REG_A] |= 0x80;
}
self.clear_flag(FLAG_Z);
self.clear_flag(FLAG_N);
@ -1069,9 +1069,10 @@ impl CPU {
let val = self.regs[REG_A];
self.set_clear_flag(FLAG_C, val & 0x80 == 0x80);
if !carry {
self.regs[REG_A] = self.regs[REG_A] << 1;
self.regs[REG_A] <<= 1;
} else {
self.regs[REG_A] = self.regs[REG_A] << 1 | 1;
self.regs[REG_A] <<= 1;
self.regs[REG_A] |= 1;
}
self.clear_flag(FLAG_Z);
self.clear_flag(FLAG_N);
@ -1108,9 +1109,10 @@ impl CPU {
let val = self.regs[REG_A];
self.set_clear_flag(FLAG_C, val & 1 == 1);
if !carry {
self.regs[REG_A] = self.regs[REG_A] >> 1;
self.regs[REG_A] >>= 1;
} else {
self.regs[REG_A] = self.regs[REG_A] >> 1 | 0x80;
self.regs[REG_A] >>= 1;
self.regs[REG_A] |= 0x80;
}
self.clear_flag(FLAG_Z);
self.clear_flag(FLAG_N);

View File

@ -65,7 +65,7 @@ const MONOCHROME_PALETTE: &'static [[u8; 3]; 4] = &[
#[derive(Copy, Clone)]
struct CgbPalette([u8; 8]);
impl CgbPalette {
fn get_color(&self, n: usize) -> sdl2::pixels::Color {
fn get_color(self, n: usize) -> sdl2::pixels::Color {
if n == 0 {
return sdl2::pixels::Color::RGB(255, 255, 255);
}
@ -405,7 +405,7 @@ impl Display {
}
self.windowx = val;
}
0xFF4f => self.vram_bank = val,
0xFF4F => self.vram_bank = val,
_ => panic!("Display: Write {:02X} to {:04X} unsupported", val, addr),
}
}
@ -560,15 +560,14 @@ impl Display {
}
}
fn render_sprites(&mut self, sprites: &Vec<Sprite>) {
fn render_sprites(&mut self, sprites: &[Sprite]) {
if self.control & CTRL_BG_SPRITE_ENABLE > 0 {
let mut num_rendered: u8 = 0;
for i in 0..39 {
for sprite in sprites.iter().take(39) {
// Gameboy limitation
if num_rendered >= 10 {
break;
}
let sprite = &sprites[i];
// Skip hidden sprites
if sprite.is_hidden() {
@ -583,10 +582,7 @@ impl Display {
// Is this sprite on the current line?
let wide_mode = self.control & CTRL_BG_SPRITE_SIZE > 0;
let actual_h = match wide_mode {
true => 16,
false => 8,
};
let actual_h = if wide_mode { 16 } else { 8 };
if sprite.is_y_flipped() {
panic!("Sorry, no y flip support yet");
@ -621,10 +617,7 @@ impl Display {
}
}
let x_maybe_flipped: u8 = match sprite.is_x_flipped() {
true => x_o ^ 7,
false => x_o,
};
let x_maybe_flipped: u8 = if sprite.is_x_flipped() { x_o ^ 7 } else { x_o };
b1 = (tile_line_1 & 1 << (7 - x_o)) > 0;
b2 = (tile_line_2 & 1 << (7 - x_o)) > 0;

View File

@ -82,7 +82,7 @@ pub struct Interconnect {
impl Interconnect {
pub fn new(bios: Box<[u8]>, rom: Box<[u8]>, save_file: Option<String>) -> Interconnect {
Interconnect {
bios: bios,
bios,
cartridge: cartridge::Cartridge::new(rom, save_file),
ram: vec![0; WRAM_SIZE].into_boxed_slice(),
hiram: vec![0; HIRAM_SIZE].into_boxed_slice(),

View File

@ -1,5 +1,7 @@
// let's try to write our own, awesome emulator.
// gameboy (color?)
// To make things more readable at points
#![allow(clippy::identity_op)]
use std::env;
use std::fs;
@ -24,10 +26,11 @@ fn main() {
} else {
let bios_path = &args[1];
let rom_path = &args[2];
let mut save_file: Option<String> = None;
if args.len() == 4 {
save_file = Some(args[3].clone());
}
let save_file = if args.len() == 4 {
Some(args[3].clone())
} else {
None
};
let bios = read_file(&bios_path).unwrap();
let rom = read_file(&rom_path).unwrap();

View File

@ -22,7 +22,7 @@ pub struct NoMBC {
impl NoMBC {
pub fn new(rom: Box<[u8]>, ram: Box<[u8]>) -> NoMBC {
NoMBC { rom: rom, ram: ram }
NoMBC { rom, ram }
}
}

View File

@ -6,11 +6,11 @@ use crate::sound::OUTPUT_SAMPLE_RATE;
struct SamplePair(u8);
impl SamplePair {
fn first(&self) -> u8 {
fn first(self) -> u8 {
self.0 >> 4
}
fn second(&self) -> u8 {
fn second(self) -> u8 {
self.0 & 0x0F
}
}