Fix warnings and formating
This commit is contained in:
parent
27585d6440
commit
3c05bfdcaa
@ -154,6 +154,7 @@ impl Peripheral for FileBus {
|
|||||||
|
|
||||||
impl FileBus {
|
impl FileBus {
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
FileBus {
|
FileBus {
|
||||||
mem: Ram::from_file("6502_functional_test.bin"),
|
mem: Ram::from_file("6502_functional_test.bin"),
|
||||||
|
|||||||
@ -208,7 +208,7 @@ impl<M: Mapper> Cpu<M> {
|
|||||||
// println!("0x{:0>4X}: {:0>2X}", self.pc-1, opcode);
|
// println!("0x{:0>4X}: {:0>2X}", self.pc-1, opcode);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let cycles = parse_opcode!(self, opcode,
|
let _cycles = parse_opcode!(self, opcode,
|
||||||
0x69 => adc(mode_immediate),
|
0x69 => adc(mode_immediate),
|
||||||
0x65 => adc(mode_zero_page),
|
0x65 => adc(mode_zero_page),
|
||||||
0x75 => adc(mode_zero_page_x),
|
0x75 => adc(mode_zero_page_x),
|
||||||
|
|||||||
@ -29,6 +29,7 @@ struct EmulatorState {
|
|||||||
pub screen: Rc<RefCell<DisplayBuffer>>,
|
pub screen: Rc<RefCell<DisplayBuffer>>,
|
||||||
pub screen_sprite: TextureSprite,
|
pub screen_sprite: TextureSprite,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub pattern_table: Rc<RefCell<DisplayBuffer>>,
|
pub pattern_table: Rc<RefCell<DisplayBuffer>>,
|
||||||
pub pattern_sprite: TextureSprite,
|
pub pattern_sprite: TextureSprite,
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ impl Application<EmulatorState> for NesEmulator {
|
|||||||
pattern_sprite.set_position(Position {x: 100, y: 50});
|
pattern_sprite.set_position(Position {x: 100, y: 50});
|
||||||
let pattern_table = Rc::new(RefCell::new(DisplayBuffer::from_texture(pattern_texture)));
|
let pattern_table = Rc::new(RefCell::new(DisplayBuffer::from_texture(pattern_texture)));
|
||||||
|
|
||||||
let mut fps_text = canvas.create_text_sprite("00", Size {w: 20, h: 20}, 20.0);
|
let mut fps_text = canvas.create_text_sprite("00", Size {w: 30, h: 20}, 20.0);
|
||||||
fps_text.set_center(Center::TopLeft);
|
fps_text.set_center(Center::TopLeft);
|
||||||
fps_text.set_position(Position {x:0, y:720});
|
fps_text.set_position(Position {x:0, y:720});
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct Ppu<M: Mapper> {
|
pub struct Ppu<M: Mapper> {
|
||||||
vbus: Rc<RefCell<M>>,
|
vbus: Rc<RefCell<M>>,
|
||||||
ppu_ctrl: PpuCtrl,
|
ppu_ctrl: PpuCtrl,
|
||||||
@ -76,7 +77,7 @@ impl<M: Mapper> Peripheral for Ppu<M> {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_addr(&mut self, addr: u16, data: u8) {
|
fn write_addr(&mut self, _addr: u16, _data: u8) {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
src/utils.rs
75
src/utils.rs
@ -1,8 +1,6 @@
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
use rusttype::{point, Font, Scale, VMetrics};
|
|
||||||
|
|
||||||
mod display_buffer;
|
mod display_buffer;
|
||||||
pub use display_buffer::DisplayBuffer;
|
pub use display_buffer::DisplayBuffer;
|
||||||
|
|
||||||
@ -124,76 +122,3 @@ impl From<&PixelBuffer> for Vec<[u8; 4]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
/* FontRenderer struct */
|
|
||||||
|
|
||||||
pub struct FontRenderer {
|
|
||||||
font: Font<'static>, scale: Scale, v_metrics: VMetrics, color: [u8; 3],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FontRenderer {
|
|
||||||
|
|
||||||
pub fn new(size: f32, color: [u8; 3]) -> Self {
|
|
||||||
|
|
||||||
// Load the font
|
|
||||||
let font = {
|
|
||||||
let font_data = include_bytes!("../fonts/DejaVuSansMono.ttf");
|
|
||||||
// This only succeeds if collection consists of one font
|
|
||||||
Font::try_from_bytes(font_data as &[u8]).expect("Error constructing Font")
|
|
||||||
};
|
|
||||||
|
|
||||||
let scale = Scale::uniform(size);
|
|
||||||
let v_metrics = font.v_metrics(scale);
|
|
||||||
|
|
||||||
FontRenderer {
|
|
||||||
font,
|
|
||||||
scale,
|
|
||||||
v_metrics,
|
|
||||||
color,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw(&mut self, buffer: &mut PixelBuffer, text: &str, origin: [usize; 2],
|
|
||||||
size: [usize; 2]) {
|
|
||||||
|
|
||||||
let line_offset = (self.v_metrics.line_gap + self.v_metrics.ascent
|
|
||||||
- self.v_metrics.descent) as usize;
|
|
||||||
|
|
||||||
// split text along '\n'
|
|
||||||
text.split('\n')
|
|
||||||
.enumerate()
|
|
||||||
.for_each(|(id, line)| {
|
|
||||||
|
|
||||||
// layout the glyphs in a line with 20 pixels padding
|
|
||||||
let glyphs: Vec<_> = self.font
|
|
||||||
.layout(line, self.scale, point(origin[0] as f32,
|
|
||||||
origin[1] as f32 + self.v_metrics.ascent))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Loop through the glyphs in the text, positing each one on a line
|
|
||||||
for glyph in glyphs {
|
|
||||||
if let Some(bounding_box) = glyph.pixel_bounding_box() {
|
|
||||||
// Draw the glyph into the image per-pixel by using the draw closure
|
|
||||||
glyph.draw(|x, y, v| {
|
|
||||||
let x_pos = (x + bounding_box.min.x as u32) as usize;
|
|
||||||
let y_pos = (y + bounding_box.min.y as u32) as usize + id * line_offset;
|
|
||||||
|
|
||||||
if x_pos < origin[0] + size[0] && y_pos < origin[1] + size[1] {
|
|
||||||
buffer.put_pixel(
|
|
||||||
x_pos,
|
|
||||||
y_pos,
|
|
||||||
// Turn the coverage into an alpha value
|
|
||||||
Pixel::rgba(
|
|
||||||
self.color[0],
|
|
||||||
self.color[1],
|
|
||||||
self.color[2],
|
|
||||||
(v * 255.0) as u8),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user