Skip to content

Commit 0743f8b

Browse files
committed
chore: lint fixes (manual)
1 parent 6c5177e commit 0743f8b

File tree

3 files changed

+51
-53
lines changed

3 files changed

+51
-53
lines changed

src/core.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ impl<'a, 'b: 'a> Cpu<'a> {
253253
// MAIN
254254
//
255255

256+
// TODO: This is used in a test right now
257+
#[allow(dead_code)]
256258
pub fn load_rom(&mut self, rom: Rom) {
257259
self.set_bus(Bus::new(rom));
258260
}
@@ -1126,7 +1128,7 @@ mod tests {
11261128
#[test]
11271129
fn test_0xa0_lda_immediate_nonzero() {
11281130
let mut cpu = Cpu::new();
1129-
cpu.load_rom(Rom::new_test_rom(vec![0xa9, 0x55, 0x00]));
1131+
cpu._load_test_rom(vec![0xa9, 0x55, 0x00]);
11301132
cpu.reset();
11311133
cpu._run();
11321134
assert_eq!(cpu.a, 0x55);

src/main.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::Cpu;
22
use core::Mem;
3-
use std::collections::HashMap;
43
use std::env;
54
use std::error::Error;
65
use std::fs;
@@ -18,33 +17,32 @@ mod rom;
1817
mod utility;
1918

2019
use bus::Bus;
21-
use gamepad::GamepadButtons;
2220
use ppu::Frame;
2321
use rand::random;
2422
use rom::Rom;
2523
use sdl2::event::Event;
2624
use sdl2::keyboard::Keycode;
2725
use sdl2::pixels::PixelFormatEnum;
2826

29-
struct KeyboardInput {
30-
key_map: HashMap<Keycode, GamepadButtons>,
31-
}
27+
// struct KeyboardInput {
28+
// key_map: HashMap<Keycode, GamepadButtons>,
29+
// }
3230

33-
impl KeyboardInput {
34-
pub fn new() -> Self {
35-
let mut key_map = HashMap::new();
36-
key_map.insert(Keycode::Down, gamepad::GamepadButtons::Down);
37-
key_map.insert(Keycode::Up, gamepad::GamepadButtons::Up);
38-
key_map.insert(Keycode::Right, gamepad::GamepadButtons::Right);
39-
key_map.insert(Keycode::Left, gamepad::GamepadButtons::Left);
40-
key_map.insert(Keycode::Space, gamepad::GamepadButtons::Select);
41-
key_map.insert(Keycode::Return, gamepad::GamepadButtons::Start);
42-
key_map.insert(Keycode::A, gamepad::GamepadButtons::ButtonA);
43-
key_map.insert(Keycode::S, gamepad::GamepadButtons::ButtonB);
44-
45-
Self { key_map }
46-
}
47-
}
31+
// impl KeyboardInput {
32+
// pub fn new() -> Self {
33+
// let mut key_map = HashMap::new();
34+
// key_map.insert(Keycode::Down, gamepad::GamepadButtons::Down);
35+
// key_map.insert(Keycode::Up, gamepad::GamepadButtons::Up);
36+
// key_map.insert(Keycode::Right, gamepad::GamepadButtons::Right);
37+
// key_map.insert(Keycode::Left, gamepad::GamepadButtons::Left);
38+
// key_map.insert(Keycode::Space, gamepad::GamepadButtons::Select);
39+
// key_map.insert(Keycode::Return, gamepad::GamepadButtons::Start);
40+
// key_map.insert(Keycode::A, gamepad::GamepadButtons::ButtonA);
41+
// key_map.insert(Keycode::S, gamepad::GamepadButtons::ButtonB);
42+
43+
// Self { key_map }
44+
// }
45+
// }
4846

4947
fn main() -> Result<(), Box<dyn Error>> {
5048
env_logger::init();

src/ppu.rs

+30-32
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use bitflags::bitflags;
22

3-
use crate::{
4-
addr_register::AddrRegister,
5-
palette::{SYSTEM_PALETTE},
6-
rom::Mirroring,
7-
};
3+
use crate::{addr_register::AddrRegister, palette::SYSTEM_PALETTE, rom::Mirroring};
84

95
// TODO: move UI rendering stuff that ties to SDL2 out of PPU
106
pub struct Frame {
@@ -32,7 +28,6 @@ impl Frame {
3228

3329
// tile_n can be thought of as the offset in the pattern table (CHR ROM)
3430
// pos (*8) relates to the value in the name table.
35-
/// VRAM (also called "name tables")
3631
pub fn draw_bg_tile(
3732
&mut self,
3833
chr_rom: &[u8],
@@ -145,8 +140,8 @@ pub struct PpuRegisters {
145140
pub struct Ppu {
146141
/// CHR ROM (also called "pattern tables")
147142
chr_rom: Vec<u8>,
148-
/// VRAM (also called "name tables")
149143

144+
/// VRAM (also called "name tables")
150145
/// 1024 bytes make up a single "Frame"
151146
/// The PPU has 2048 bytes here, representing 2 frames.
152147
/// NOTE: the PPU is addressable via 4096 bytes, meaning there's some remapping of those additional bytes.
@@ -220,7 +215,7 @@ impl Ppu {
220215
let p_idx = palette_idx.0;
221216
assert!(p_idx < 8);
222217

223-
let start = (p_idx * 4);
218+
let start = p_idx * 4;
224219
[
225220
// The first entry is a special case
226221
if is_background { self.palettes[0] } else { 0 },
@@ -275,7 +270,6 @@ impl Ppu {
275270

276271
// tile_n can be thought of as the offset in the pattern table (CHR ROM)
277272
// pos (*8) relates to the value in the name table.
278-
/// VRAM (also called "name tables")
279273
pub fn draw_background(&self, frame: &mut Frame) {
280274
// Determine which nametable is being used for the current screen (by reading bit 0 and bit 1 from Control register)
281275
let which_nametable = self
@@ -506,7 +500,7 @@ impl Ppu {
506500
let name_table_idx = base / 0x0400;
507501

508502
// and ROM-configured mirroring
509-
503+
510504
match (self.mirroring, name_table_idx) {
511505
(Mirroring::Horizontal, 1) | (Mirroring::Horizontal, 2) => base - 0x0400,
512506
(Mirroring::Vertical, 2) | (Mirroring::Vertical, 3) | (Mirroring::Horizontal, 3) => {
@@ -692,9 +686,7 @@ mod tests {
692686

693687
assert_eq!(ppu.get_tick_status(), (0, 0));
694688
assert_eq!(ppu.nmi_interrupt, None);
695-
assert!(
696-
!ppu.registers.status.contains(StatusRegister::VBLANK_FLAG),
697-
);
689+
assert!(!ppu.registers.status.contains(StatusRegister::VBLANK_FLAG),);
698690
assert!(!ppu.is_vblank_nmi_enabled());
699691

700692
ppu.registers
@@ -858,36 +850,42 @@ mod tests {
858850
fn test_parse_sprite_from_oam_data() {
859851
let mut ppu = new_test_ppu();
860852

861-
let mut expected = Sprite::default();
862-
expected.palette_idx = PaletteIdx(4);
853+
let expected = Sprite {
854+
palette_idx: PaletteIdx(4),
855+
..Default::default()
856+
};
863857
assert_eq!(ppu.parse_sprite_from_oam_data(&[0, 0, 0, 0]), expected);
864858

865859
ppu.registers
866860
.control
867861
.insert(ControlRegister::SPRITE_PATTERN_ADDR);
868-
let mut expected = Sprite::default();
869-
expected.x = 5;
870-
expected.y = 10;
871-
expected.tile_idx = 123;
872-
expected.palette_idx = PaletteIdx(6);
873-
expected.flip_horizontal = true;
874-
expected.flip_vertical = true;
875-
expected.behind_background = true;
876-
expected.use_tile_bank_1 = true;
862+
let expected = Sprite {
863+
x: 5,
864+
y: 10,
865+
tile_idx: 123,
866+
palette_idx: PaletteIdx(6),
867+
flip_horizontal: true,
868+
flip_vertical: true,
869+
behind_background: true,
870+
use_tile_bank_1: true,
871+
..Default::default()
872+
};
877873
assert_eq!(
878874
ppu.parse_sprite_from_oam_data(&[10, 123, 0b1110_0010, 5]),
879875
expected
880876
);
881877

882878
ppu.registers.control.insert(ControlRegister::SPRITE_SIZE);
883-
let mut expected = Sprite::default();
884-
expected.x = 1;
885-
expected.y = 2;
886-
expected.tile_idx = 16;
887-
expected.palette_idx = PaletteIdx(7);
888-
expected.flip_vertical = true;
889-
expected.behind_background = true;
890-
expected.is_8_by_16 = true;
879+
let expected = Sprite {
880+
x: 1,
881+
y: 2,
882+
tile_idx: 16,
883+
palette_idx: PaletteIdx(7),
884+
flip_vertical: true,
885+
behind_background: true,
886+
is_8_by_16: true,
887+
..Default::default()
888+
};
891889
assert_eq!(
892890
ppu.parse_sprite_from_oam_data(&[2, 0b0001_0000, 0b1010_0011, 1]),
893891
expected

0 commit comments

Comments
 (0)