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