Compare commits

..

No commits in common. "dec36156df67a2d718c54c54bde3671738868bd3" and "27585d64409532a1d2f17557f626d3800c83d8fd" have entirely different histories.

11 changed files with 231 additions and 173 deletions

View File

@ -1,5 +0,0 @@
[*.rs]
indent_style = tab
indent_size = 4
max_line_length = 100

9
.gitignore vendored
View File

@ -1,15 +1,6 @@
/target
/cgmath
*.log
*.bin
*.bin.*
*.bkp
*.perf
*.svg
*.lock
perf.*
tags

View File

@ -154,7 +154,6 @@ impl Peripheral for FileBus {
impl FileBus {
#[allow(dead_code)]
pub fn new() -> Self {
FileBus {
mem: Ram::from_file("6502_functional_test.bin"),

View File

@ -208,7 +208,7 @@ impl<M: Mapper> Cpu<M> {
// 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),
0x65 => adc(mode_zero_page),
0x75 => adc(mode_zero_page_x),

View File

@ -29,7 +29,6 @@ struct EmulatorState {
pub screen: Rc<RefCell<DisplayBuffer>>,
pub screen_sprite: TextureSprite,
#[allow(dead_code)]
pub pattern_table: Rc<RefCell<DisplayBuffer>>,
pub pattern_sprite: TextureSprite,
@ -67,7 +66,7 @@ impl Application<EmulatorState> for NesEmulator {
pattern_sprite.set_position(Position {x: 100, y: 50});
let pattern_table = Rc::new(RefCell::new(DisplayBuffer::from_texture(pattern_texture)));
let mut fps_text = canvas.create_text_sprite("00", Size {w: 30, h: 20}, 20.0);
let mut fps_text = canvas.create_text_sprite("00", Size {w: 20, h: 20}, 20.0);
fps_text.set_center(Center::TopLeft);
fps_text.set_position(Position {x:0, y:720});

View File

@ -48,7 +48,6 @@ bitflags! {
}
}
#[allow(dead_code)]
pub struct Ppu<M: Mapper> {
vbus: Rc<RefCell<M>>,
ppu_ctrl: PpuCtrl,
@ -77,7 +76,7 @@ impl<M: Mapper> Peripheral for Ppu<M> {
unimplemented!();
}
fn write_addr(&mut self, _addr: u16, _data: u8) {
fn write_addr(&mut self, addr: u16, data: u8) {
unimplemented!();
}
}

View File

@ -1,6 +1,8 @@
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use rusttype::{point, Font, Scale, VMetrics};
mod display_buffer;
pub use display_buffer::DisplayBuffer;
@ -122,3 +124,76 @@ 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),
)
}
});
}
}
});
}
}