Most linting

This commit is contained in:
2022-02-20 12:58:52 -06:00
parent 99b39239ba
commit 6acd127fef
4 changed files with 12 additions and 14 deletions
+2 -2
View File
@@ -8,8 +8,8 @@ impl From<u32> for Word {
fn from(a: u32) -> Self { Self(a & 0xffffff) }
}
impl Into<u32> for Word {
fn into(self) -> u32 { self.0 }
impl From<Word> for u32 {
fn from(word: Word) -> Self { word.0 }
}
impl std::ops::Add<i32> for Word {
+4 -3
View File
@@ -5,6 +5,7 @@ use crate::address::Word;
use crate::memory::PeekPoke;
use std::convert::TryFrom;
#[allow(clippy::upper_case_acronyms)]
struct CPU {
memory: Memory, // Main memory, all of it
pc: Word, // program counter, address of the low byte of the instruction
@@ -80,7 +81,7 @@ impl CPU {
let arg_length = instruction & 3;
if arg_length == 0 {
Ok(Instruction {
opcode: opcode,
opcode,
arg: None,
length: 1
})
@@ -88,11 +89,11 @@ impl CPU {
let mut arg = 0u32;
for n in 0..arg_length {
let mut b: u32 = self.memory.peek(self.pc + (n + 1) as i32) as u32;
b = b << (8 * n);
b <<= 8 * n;
arg += b;
}
Ok(Instruction {
opcode: opcode,
opcode,
arg: Some(arg),
length: arg_length + 1
})
+4 -7
View File
@@ -11,12 +11,9 @@ use winit::{
dpi::LogicalSize
};
use pixels::{Error, Pixels, SurfaceTexture};
use pixels::{Pixels, SurfaceTexture};
use rand::RngCore;
use rand::prelude::ThreadRng;
use std::time::{Instant, Duration};
use pixels::wgpu::Instance;
use std::convert::TryInto;
use std::time::Instant;
fn main() {
let event_loop = EventLoop::new();
@@ -50,7 +47,7 @@ fn main() {
let start = Instant::now();
draw(pixels.get_frame());
let draw_time = Instant::now() - start;
pixels.render();
pixels.render().expect("Problem displaying framebuffer");
let total_time = Instant::now() - start;
println!("Tick took {} total, {} to draw", total_time.as_micros(), draw_time.as_micros());
}
@@ -63,7 +60,7 @@ fn draw(frame: &mut [u8]) {
assert_eq!(frame.len(), 640 * 480 * 4);
let mut rng = rand::thread_rng();
for (i, pixel) in frame.chunks_exact_mut(4).enumerate() {
for (_, pixel) in frame.chunks_exact_mut(4).enumerate() {
let p = rng.next_u32();
let [low, mid, high, _] = p.to_le_bytes();
pixel[0] = low;
+2 -2
View File
@@ -61,8 +61,8 @@ pub trait PeekPoke {
}
impl PeekPoke for Memory {
fn peek(&self, addr: Word) -> u8 { self[addr.into()] }
fn poke(&mut self, addr: Word, val: u8) { self[addr.into()] = val; }
fn peek(&self, addr: Word) -> u8 { self[addr] }
fn poke(&mut self, addr: Word, val: u8) { self[addr] = val; }
}
#[cfg(test)]