Skip to content

Commit a54419d

Browse files
committed
chore: fix linting errors
1 parent 85f364f commit a54419d

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

src/apu/pulse_register.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use bitfields::bitfield;
66
struct PulseEnvelope {
77
/// Duty Cycle
88
#[bits(2)]
9-
D: u8,
9+
d: u8,
1010
/// Envelope loop / length counter halt
11-
L: bool,
11+
l: bool,
1212
/// Constant volume/envelope flag
13-
C: bool,
13+
c: bool,
1414
/// Volume/envelope divider period
1515
#[bits(4)]
16-
V: u8,
16+
v: u8,
1717
}
1818

1919
/// PulseSweep
@@ -22,19 +22,19 @@ struct PulseEnvelope {
2222
// #[derive(Copy, Clone)] // Attributes are passed to the struct.
2323
struct PulseSweep {
2424
/// Enabled flag
25-
E: bool,
25+
e: bool,
2626
/// Period
2727
/// The divider's period is P + 1 half-frames
2828
#[bits(3)]
29-
P: u8,
29+
p: u8,
3030
/// Negate flag
3131
/// 0: add to period, sweeping toward lower frequencies
3232
/// 1: subtract from period, sweeping toward higher frequencies
33-
N: bool,
33+
n: bool,
3434
/// Shift count (number of bits).
3535
/// If SSS is 0, then behaves like E=0.
3636
#[bits(3)]
37-
S: u8,
37+
s: u8,
3838
}
3939

4040
/// https://www.nesdev.org/wiki/APU_Pulse
@@ -56,38 +56,38 @@ impl PulseRegister {
5656
// data[0]
5757

5858
fn duty_cycle(&self) -> u8 {
59-
PulseEnvelope::from_bits(self.data[0]).D()
59+
PulseEnvelope::from_bits(self.data[0]).d()
6060
}
6161

6262
fn is_length_counter_halted(&self) -> bool {
63-
PulseEnvelope::from_bits(self.data[0]).L()
63+
PulseEnvelope::from_bits(self.data[0]).l()
6464
}
6565

6666
fn is_constant_volume(&self) -> bool {
67-
PulseEnvelope::from_bits(self.data[0]).C()
67+
PulseEnvelope::from_bits(self.data[0]).c()
6868
}
6969

7070
fn envelope_period(&self) -> u8 {
71-
PulseEnvelope::from_bits(self.data[0]).V()
71+
PulseEnvelope::from_bits(self.data[0]).v()
7272
}
7373

7474
// data[1]
7575

7676
fn is_sweep_enabled(&self) -> bool {
7777
let s = PulseSweep::from_bits(self.data[1]);
78-
s.E() && s.S() > 0
78+
s.e() && s.s() > 0
7979
}
8080

8181
fn is_sweep_negated(&self) -> bool {
82-
PulseSweep::from_bits(self.data[1]).N()
82+
PulseSweep::from_bits(self.data[1]).n()
8383
}
8484

8585
fn sweep_period(&self) -> u8 {
86-
PulseSweep::from_bits(self.data[1]).P()
86+
PulseSweep::from_bits(self.data[1]).p()
8787
}
8888

8989
fn sweep_shift_count(&self) -> u8 {
90-
PulseSweep::from_bits(self.data[1]).S()
90+
PulseSweep::from_bits(self.data[1]).s()
9191
}
9292

9393
// data[2] and data[3]

src/cpu.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use crate::{
32
bus::Bus,
43
ops::{addressing_mode_to_size, is_official, lookup_opcode, OpName},
@@ -1862,4 +1861,26 @@ mod tests {
18621861
);
18631862
}
18641863
}
1864+
1865+
#[test]
1866+
fn test_stack_push_pop() {
1867+
let mut cpu = Cpu::new();
1868+
1869+
cpu.stack_push(0x12);
1870+
cpu.stack_push(0x34);
1871+
1872+
assert_eq!(cpu.stack_pop(), 0x34);
1873+
assert_eq!(cpu.stack_pop(), 0x12);
1874+
}
1875+
1876+
#[test]
1877+
fn test_stack_push_pop_u16() {
1878+
let mut cpu = Cpu::new();
1879+
1880+
cpu.stack_push_u16(0x1234);
1881+
cpu.stack_push_u16(0x2345);
1882+
1883+
assert_eq!(cpu.stack_pop_u16(), 0x2345);
1884+
assert_eq!(cpu.stack_pop_u16(), 0x1234);
1885+
}
18651886
}

src/ppu.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ impl Ppu {
172172
assert!(which_nametable <= 3);
173173
let nt_start = which_nametable * 0x400;
174174

175-
let TILE_ROWS = 30;
176-
let TILE_COLS = 32;
175+
let tile_rows = 30;
176+
let tile_cols = 32;
177177
match self.mirroring {
178178
Mirroring::Vertical => {
179179
let x_scroll: usize = self.registers.scroll.x_scroll as usize;
@@ -189,18 +189,18 @@ impl Ppu {
189189
[0x400, 0x800]
190190
};
191191

192-
for tile_y in 0..TILE_ROWS {
192+
for tile_y in 0..tile_rows {
193193
for (nt_idx, &nt_start) in nts.iter().enumerate() {
194-
for tile_x in 0..TILE_COLS {
195-
let offset = tile_y * TILE_COLS + tile_x;
194+
for tile_x in 0..tile_cols {
195+
let offset = tile_y * tile_cols + tile_x;
196196
let tile_n = self.vram
197197
[self.mirror_vram_addr((nt_start + offset) as u16) as usize];
198198
let bgp_idx = self.palette_for_bg_tile((tile_x, tile_y), nt_start);
199199
let palette = self.lookup_palette(bgp_idx);
200200
frame.draw_bg_tile(
201201
pattern_table,
202202
tile_n as usize,
203-
(tile_x + TILE_COLS * nt_idx, tile_y),
203+
(tile_x + tile_cols * nt_idx, tile_y),
204204
x_scroll,
205205
0,
206206
palette,
@@ -218,18 +218,18 @@ impl Ppu {
218218
[0x800, 0]
219219
};
220220

221-
for tile_y in 0..TILE_ROWS {
221+
for tile_y in 0..tile_rows {
222222
for (nt_idx, &nt_start) in nts.iter().enumerate() {
223-
for tile_x in 0..TILE_COLS {
224-
let offset = tile_y * TILE_COLS + tile_x;
223+
for tile_x in 0..tile_cols {
224+
let offset = tile_y * tile_cols + tile_x;
225225
let tile_n = self.vram
226226
[self.mirror_vram_addr((nt_start + offset) as u16) as usize];
227227
let bgp_idx = self.palette_for_bg_tile((tile_x, tile_y), nt_start);
228228
let palette = self.lookup_palette(bgp_idx);
229229
frame.draw_bg_tile(
230230
pattern_table,
231231
tile_n as usize,
232-
(tile_x, tile_y + TILE_ROWS * nt_idx),
232+
(tile_x, tile_y + tile_rows * nt_idx),
233233
0,
234234
y_scroll,
235235
palette,

src/rom.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ impl Rom {
4343
let prg_rom_banks = header[4];
4444
let chr_rom_banks = header[5];
4545
let control_byte_1 = header[6];
46-
let control_byte_2 = header[7];
46+
// let control_byte_2 = header[7];
4747
// let size_of_prg_ram_times_8kb = header[8];
4848

4949
let has_trainer_bytes = control_byte_1 ^ (1 << 2) == 0;
5050
let is_four_screen = control_byte_1 & (1 << 3) > 0;
5151
let is_vertical_screen = control_byte_1 & 1 > 0;
5252

53-
let lo = (control_byte_1 & 0b1111_0000) >> 4;
54-
let hi = control_byte_2 & 0b1111_0000;
55-
let rom_mapper_type = hi + lo;
53+
// let lo = (control_byte_1 & 0b1111_0000) >> 4;
54+
// let hi = control_byte_2 & 0b1111_0000;
55+
// let rom_mapper_type = hi + lo;
5656

5757
let mapper = Mapper::Zero;
5858

0 commit comments

Comments
 (0)