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

refactor: clippy changes

parent 3192d273
No related branches found
No related tags found
No related merge requests found
Pipeline #1504 passed
......@@ -51,7 +51,7 @@ impl GameBoy {
let timer = Timer::new();
let mmu = Mmu::new(ppu, pad, timer);
let cpu = Cpu::new(mmu);
Self { cpu: cpu }
Self { cpu }
}
pub fn reset(&mut self) {
......
use crate::cpu::Cpu;
pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &str); 256] = [
// 0x0 opcodes
(nop, 4, "NOP"),
(ld_bc_u16, 12, "LD BC, u16"),
......@@ -275,7 +275,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [
(rst_38h, 16, "RST 38h"),
];
pub const EXTENDED: [(fn(&mut Cpu), u8, &'static str); 256] = [
pub const EXTENDED: [(fn(&mut Cpu), u8, &str); 256] = [
// 0x0 opcodes
(rlc_b, 8, "RLC B"),
(rlc_c, 8, "RLC C"),
......
......@@ -119,11 +119,10 @@ impl Mmu {
0xe00 => self.ppu.oam[(addr & 0x009f) as usize],
0xf00 => match addr & 0x00ff {
0x0f => {
let value = if self.ppu.int_vblank() { 0x01 } else { 0x00 }
(if self.ppu.int_vblank() { 0x01 } else { 0x00 }
| if self.ppu.int_stat() { 0x02 } else { 0x00 }
| if self.timer.int_tima() { 0x04 } else { 0x00 }
| if self.pad.int_pad() { 0x10 } else { 0x00 };
value
| if self.pad.int_pad() { 0x10 } else { 0x00 })
}
0x80..=0xfe => self.ppu.hram[(addr & 0x007f) as usize],
0xff => self.ie,
......@@ -245,7 +244,7 @@ impl Mmu {
data.push(byte);
}
return data;
data
}
pub fn write_boot(&mut self, addr: u16, buffer: &[u8]) {
......
......@@ -93,7 +93,7 @@ impl Display for Tile {
for x in 0..8 {
buffer.push_str(format!("{}", self.get(x, y)).as_str());
}
buffer.push_str("\n");
buffer.push('\n');
}
write!(f, "{}", buffer)
}
......@@ -434,24 +434,22 @@ impl Ppu {
pub fn read(&mut self, addr: u16) -> u8 {
match addr & 0x00ff {
0x0040 => {
let value = if self.switch_bg { 0x01 } else { 0x00 }
(if self.switch_bg { 0x01 } else { 0x00 }
| if self.switch_obj { 0x02 } else { 0x00 }
| if self.obj_size { 0x04 } else { 0x00 }
| if self.bg_map { 0x08 } else { 0x00 }
| if self.bg_tile { 0x10 } else { 0x00 }
| if self.switch_window { 0x20 } else { 0x00 }
| if self.window_map { 0x40 } else { 0x00 }
| if self.switch_lcd { 0x80 } else { 0x00 };
value
| if self.switch_lcd { 0x80 } else { 0x00 })
}
0x0041 => {
let value = if self.stat_hblank { 0x08 } else { 0x00 }
(if self.stat_hblank { 0x08 } else { 0x00 }
| if self.stat_vblank { 0x10 } else { 0x00 }
| if self.stat_oam { 0x20 } else { 0x00 }
| if self.stat_lyc { 0x40 } else { 0x00 }
| if self.lyc == self.ly { 0x04 } else { 0x00 }
| (self.mode as u8 & 0x03);
value
| (self.mode as u8 & 0x03))
}
0x0042 => self.scy,
0x0043 => self.scx,
......@@ -673,9 +671,9 @@ impl Ppu {
0x02 => obj.tile = value,
0x03 => {
obj.palette = if value & 0x10 == 0x10 { 1 } else { 0 };
obj.xflip = if value & 0x20 == 0x20 { true } else { false };
obj.yflip = if value & 0x40 == 0x40 { true } else { false };
obj.priority = if value & 0x80 == 0x80 { false } else { true };
obj.xflip = value & 0x20 == 0x20;
obj.yflip = value & 0x40 == 0x40;
obj.priority = value & 0x80 != 0x80;
obj.index = obj_index as u8;
}
_ => (),
......@@ -866,7 +864,7 @@ impl Ppu {
tile = &self.tiles[obj.tile as usize & 0xfe];
} else {
tile = &self.tiles[obj.tile as usize | 0x01];
tile_offset = tile_offset - 8;
tile_offset -= 8;
}
}
// otherwise we're facing a 8x8 sprite and we should grab
......
......@@ -475,7 +475,7 @@ pub static MBC1: Mbc = Mbc {
// ROM bank selection 5 lower bits
0x2000 | 0x3000 => {
let mut rom_bank = value & 0x1f;
rom_bank = rom_bank & (rom.rom_bank_count * 2 - 1) as u8;
rom_bank &= (rom.rom_bank_count * 2 - 1) as u8;
if rom_bank == 0 {
rom_bank = 1;
}
......@@ -537,7 +537,7 @@ pub static MBC3: Mbc = Mbc {
// ROM bank selection
0x2000 | 0x3000 => {
let mut rom_bank = value & 0x7f;
rom_bank = rom_bank & (rom.rom_bank_count * 2 - 1) as u8;
rom_bank &= (rom.rom_bank_count * 2 - 1) as u8;
if rom_bank == 0 {
rom_bank = 1;
}
......@@ -592,7 +592,7 @@ pub static MBC5: Mbc = Mbc {
}
// ROM bank selection
0x2000 => {
let rom_bank = value & 0xff;
let rom_bank = value;
rom.set_rom_bank(rom_bank);
}
// RAM bank selection
......
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