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

refactor: more clippy refactor

parent ff4e1f87
No related branches found
No related tags found
No related merge requests found
...@@ -381,7 +381,7 @@ impl Cpu { ...@@ -381,7 +381,7 @@ impl Cpu {
pub fn read_u16(&mut self) -> u16 { pub fn read_u16(&mut self) -> u16 {
let byte1 = self.read_u8(); let byte1 = self.read_u8();
let byte2 = self.read_u8(); let byte2 = self.read_u8();
byte1 as u16 | ((byte2 as u16) << 8) byte1 as u16 | ((byte2 as u16) << 8)
} }
...@@ -406,7 +406,6 @@ impl Cpu { ...@@ -406,7 +406,6 @@ impl Cpu {
#[inline(always)] #[inline(always)]
pub fn pop_word(&mut self) -> u16 { pub fn pop_word(&mut self) -> u16 {
self.pop_byte() as u16 | ((self.pop_byte() as u16) << 8) self.pop_byte() as u16 | ((self.pop_byte() as u16) << 8)
} }
......
...@@ -13,7 +13,7 @@ use crate::{ ...@@ -13,7 +13,7 @@ use crate::{
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use crate::ppu::{Pixel, Palette}; use crate::ppu::{Palette, Pixel};
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use std::{ use std::{
...@@ -206,7 +206,7 @@ impl GameBoy { ...@@ -206,7 +206,7 @@ impl GameBoy {
self.cpu.timer() self.cpu.timer()
} }
pub fn frame_buffer(&mut self) -> &Box<[u8; FRAME_BUFFER_SIZE]> { pub fn frame_buffer(&mut self) -> &[u8; FRAME_BUFFER_SIZE] {
&(self.ppu().frame_buffer) &(self.ppu().frame_buffer)
} }
...@@ -292,3 +292,9 @@ pub fn hook_impl(info: &PanicInfo) { ...@@ -292,3 +292,9 @@ pub fn hook_impl(info: &PanicInfo) {
let message = info.to_string(); let message = info.to_string();
panic(message.as_str()); panic(message.as_str());
} }
impl Default for GameBoy {
fn default() -> Self {
Self::new()
}
}
use crate::cpu::Cpu; use crate::cpu::Cpu;
pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &str); 256] = [ pub const INSTRUCTIONS: [Instruction; 256] = [
// 0x0 opcodes // 0x0 opcodes
(nop, 4, "NOP"), (nop, 4, "NOP"),
(ld_bc_u16, 12, "LD BC, u16"), (ld_bc_u16, 12, "LD BC, u16"),
...@@ -275,7 +275,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &str); 256] = [ ...@@ -275,7 +275,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &str); 256] = [
(rst_38h, 16, "RST 38h"), (rst_38h, 16, "RST 38h"),
]; ];
pub const EXTENDED: [(fn(&mut Cpu), u8, &str); 256] = [ pub const EXTENDED: [Instruction; 256] = [
// 0x0 opcodes // 0x0 opcodes
(rlc_b, 8, "RLC B"), (rlc_b, 8, "RLC B"),
(rlc_c, 8, "RLC C"), (rlc_c, 8, "RLC C"),
...@@ -550,6 +550,8 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &str); 256] = [ ...@@ -550,6 +550,8 @@ pub const EXTENDED: [(fn(&mut Cpu), u8, &str); 256] = [
(set_7_a, 8, "SET 7, A"), (set_7_a, 8, "SET 7, A"),
]; ];
pub type Instruction = (fn(&mut Cpu), u8, &'static str);
fn nop(_cpu: &mut Cpu) {} fn nop(_cpu: &mut Cpu) {}
fn illegal(_cpu: &mut Cpu) { fn illegal(_cpu: &mut Cpu) {
...@@ -1040,9 +1042,7 @@ fn ccf(cpu: &mut Cpu) { ...@@ -1040,9 +1042,7 @@ fn ccf(cpu: &mut Cpu) {
cpu.set_carry(!cpu.get_carry()); cpu.set_carry(!cpu.get_carry());
} }
fn ld_b_b(cpu: &mut Cpu) { fn ld_b_b(_cpu: &mut Cpu) {}
cpu.b = cpu.b;
}
fn ld_b_c(cpu: &mut Cpu) { fn ld_b_c(cpu: &mut Cpu) {
cpu.b = cpu.c; cpu.b = cpu.c;
...@@ -1077,9 +1077,7 @@ fn ld_c_b(cpu: &mut Cpu) { ...@@ -1077,9 +1077,7 @@ fn ld_c_b(cpu: &mut Cpu) {
cpu.c = cpu.b; cpu.c = cpu.b;
} }
fn ld_c_c(cpu: &mut Cpu) { fn ld_c_c(_cpu: &mut Cpu) {}
cpu.c = cpu.c;
}
fn ld_c_d(cpu: &mut Cpu) { fn ld_c_d(cpu: &mut Cpu) {
cpu.c = cpu.d; cpu.c = cpu.d;
...@@ -1114,9 +1112,7 @@ fn ld_d_c(cpu: &mut Cpu) { ...@@ -1114,9 +1112,7 @@ fn ld_d_c(cpu: &mut Cpu) {
cpu.d = cpu.c; cpu.d = cpu.c;
} }
fn ld_d_d(cpu: &mut Cpu) { fn ld_d_d(_cpu: &mut Cpu) {}
cpu.d = cpu.d;
}
fn ld_d_e(cpu: &mut Cpu) { fn ld_d_e(cpu: &mut Cpu) {
cpu.d = cpu.e; cpu.d = cpu.e;
...@@ -1151,9 +1147,7 @@ fn ld_e_d(cpu: &mut Cpu) { ...@@ -1151,9 +1147,7 @@ fn ld_e_d(cpu: &mut Cpu) {
cpu.e = cpu.d; cpu.e = cpu.d;
} }
fn ld_e_e(cpu: &mut Cpu) { fn ld_e_e(_cpu: &mut Cpu) {}
cpu.e = cpu.e;
}
fn ld_e_h(cpu: &mut Cpu) { fn ld_e_h(cpu: &mut Cpu) {
cpu.e = cpu.h; cpu.e = cpu.h;
...@@ -1188,9 +1182,7 @@ fn ld_h_e(cpu: &mut Cpu) { ...@@ -1188,9 +1182,7 @@ fn ld_h_e(cpu: &mut Cpu) {
cpu.h = cpu.e; cpu.h = cpu.e;
} }
fn ld_h_h(cpu: &mut Cpu) { fn ld_h_h(_cpu: &mut Cpu) {}
cpu.h = cpu.h;
}
fn ld_h_l(cpu: &mut Cpu) { fn ld_h_l(cpu: &mut Cpu) {
cpu.h = cpu.l; cpu.h = cpu.l;
...@@ -1225,9 +1217,7 @@ fn ld_l_h(cpu: &mut Cpu) { ...@@ -1225,9 +1217,7 @@ fn ld_l_h(cpu: &mut Cpu) {
cpu.l = cpu.h; cpu.l = cpu.h;
} }
fn ld_l_l(cpu: &mut Cpu) { fn ld_l_l(_cpu: &mut Cpu) {}
cpu.l = cpu.l;
}
fn ld_l_mhl(cpu: &mut Cpu) { fn ld_l_mhl(cpu: &mut Cpu) {
let byte = cpu.mmu.read(cpu.hl()); let byte = cpu.mmu.read(cpu.hl());
...@@ -1299,9 +1289,7 @@ fn ld_a_mhl(cpu: &mut Cpu) { ...@@ -1299,9 +1289,7 @@ fn ld_a_mhl(cpu: &mut Cpu) {
cpu.a = byte; cpu.a = byte;
} }
fn ld_a_a(cpu: &mut Cpu) { fn ld_a_a(_cpu: &mut Cpu) {}
cpu.a = cpu.a;
}
fn add_a_b(cpu: &mut Cpu) { fn add_a_b(cpu: &mut Cpu) {
cpu.a = add_set_flags(cpu, cpu.a, cpu.b); cpu.a = add_set_flags(cpu, cpu.a, cpu.b);
......
...@@ -230,9 +230,9 @@ impl Mmu { ...@@ -230,9 +230,9 @@ impl Mmu {
} }
} }
pub fn write_many(&mut self, addr: u16, data: &Vec<u8>) { pub fn write_many(&mut self, addr: u16, data: &[u8]) {
for index in 0..data.len() { for (index, byte) in data.iter().enumerate() {
self.write(addr + index as u16, data[index]) self.write(addr + index as u16, *byte)
} }
} }
......
...@@ -53,21 +53,20 @@ impl Pad { ...@@ -53,21 +53,20 @@ impl Pad {
pub fn read(&mut self, addr: u16) -> u8 { pub fn read(&mut self, addr: u16) -> u8 {
match addr & 0x00ff { match addr & 0x00ff {
0x0000 => { 0x0000 => {
let mut value; let mut value = match self.selection {
match self.selection {
PadSelection::Action => { PadSelection::Action => {
value = if self.a { 0x00 } else { 0x01 } (if self.a { 0x00 } else { 0x01 }
| if self.b { 0x00 } else { 0x02 } | if self.b { 0x00 } else { 0x02 }
| if self.select { 0x00 } else { 0x04 } | if self.select { 0x00 } else { 0x04 }
| if self.start { 0x00 } else { 0x08 } | if self.start { 0x00 } else { 0x08 })
} }
PadSelection::Direction => { PadSelection::Direction => {
value = if self.right { 0x00 } else { 0x01 } (if self.right { 0x00 } else { 0x01 }
| if self.left { 0x00 } else { 0x02 } | if self.left { 0x00 } else { 0x02 }
| if self.up { 0x00 } else { 0x04 } | if self.up { 0x00 } else { 0x04 }
| if self.down { 0x00 } else { 0x08 } | if self.down { 0x00 } else { 0x08 })
} }
} };
value |= if self.selection == PadSelection::Direction { value |= if self.selection == PadSelection::Direction {
0x10 0x10
} else { } else {
...@@ -141,3 +140,9 @@ impl Pad { ...@@ -141,3 +140,9 @@ impl Pad {
self.set_int_pad(false); self.set_int_pad(false);
} }
} }
impl Default for Pad {
fn default() -> Self {
Self::new()
}
}
...@@ -882,12 +882,11 @@ impl Ppu { ...@@ -882,12 +882,11 @@ impl Ppu {
tile = &self.tiles[obj.tile as usize]; tile = &self.tiles[obj.tile as usize];
} }
let tile_row: &[u8]; let tile_row = if obj.yflip {
if obj.yflip { tile.get_row((7 - tile_offset) as usize)
tile_row = tile.get_row((7 - tile_offset) as usize);
} else { } else {
tile_row = tile.get_row((tile_offset) as usize); tile.get_row((tile_offset) as usize)
} };
for x in 0..TILE_WIDTH { for x in 0..TILE_WIDTH {
let is_contained = let is_contained =
...@@ -936,3 +935,9 @@ impl Ppu { ...@@ -936,3 +935,9 @@ impl Ppu {
|| self.stat_hblank && self.mode == PpuMode::HBlank || self.stat_hblank && self.mode == PpuMode::HBlank
} }
} }
impl Default for Ppu {
fn default() -> Self {
Self::new()
}
}
...@@ -412,6 +412,12 @@ impl Cartridge { ...@@ -412,6 +412,12 @@ impl Cartridge {
} }
} }
impl Default for Cartridge {
fn default() -> Self {
Self::new()
}
}
impl Display for Cartridge { impl Display for Cartridge {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!( write!(
......
...@@ -100,3 +100,9 @@ impl Timer { ...@@ -100,3 +100,9 @@ impl Timer {
self.set_int_tima(false); self.set_int_tima(false);
} }
} }
impl Default for Timer {
fn default() -> Self {
Self::new()
}
}
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