Skip to content

Commit

Permalink
slidedeck: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rrbutani committed Dec 16, 2019
1 parent f86ea36 commit 282cf1a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
Binary file removed slidedeck/slides.mem
Binary file not shown.
49 changes: 38 additions & 11 deletions slidedeck/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Helper functions and the actual slide deck LC-3 program.
use lc3_isa::{self, Addr, Word, SignedWord, util::{AssembledProgram, MemoryDump}};
use lc3_isa::{
self,
util::{AssembledProgram, MemoryDump},
Addr, SignedWord, Word,
};
use lc3_os::OS_IMAGE;

use std::convert::TryInto;
Expand All @@ -19,17 +23,33 @@ pub const STARTING: Addr = 0x3100;
///
/// If permissive is true, extra characters are ignored and unspecified
/// characters are uninitialized in memory (i.e. they're just `'\0'`).
fn slide((width, height): (usize, usize), mut addr: Addr, slide: &str, permissive: bool) -> Vec<(Addr, Word)> {
fn slide(
(width, height): (usize, usize),
mut addr: Addr,
slide: &str,
permissive: bool,
) -> Vec<(Addr, Word)> {
if !permissive {
assert_eq!(slide.len(), width * height, "size mismatch (expected {}, got {}) on: `{}`", width * height, slide.len(), slide);
assert_eq!(
slide.len(),
width * height,
"size mismatch (expected {}, got {}) on: `{}`",
width * height,
slide.len(),
slide
);
}

slide.chars().take(width * height).map(|c| {
let a = addr;
addr += 1;
slide
.chars()
.take(width * height)
.map(|c| {
let a = addr;
addr += 1;

(a, c as u16)
}).collect()
(a, c as u16)
})
.collect()
}

#[allow(clippy::cognitive_complexity)]
Expand Down Expand Up @@ -135,7 +155,8 @@ fn base_program((width, height): (usize, usize), num_slides: Word) -> AssembledP
@NEG_SLIDE_LEN .FILL #(
(-(TryInto::<SignedWord>::try_into(height * width).unwrap())) as Word
);
}).into()
})
.into()
}

/// Given a slide deck and some dimensions, this produces an image containing
Expand All @@ -151,10 +172,16 @@ pub fn make_image(dimensions: (usize, usize), slides: &[&str], permissive: bool)
let mut image = OS_IMAGE.clone();
let slide_len = dimensions.0 * dimensions.1;

let _ = image.layer_loadable(base_program(dimensions, slides.len().try_into().unwrap()).into_iter());
let _ = image
.layer_loadable(base_program(dimensions, slides.len().try_into().unwrap()).into_iter());

slides.iter().enumerate().for_each(|(idx, s)| {
let _ = image.layer_loadable(slide(dimensions, STARTING + TryInto::<Addr>::try_into(idx * slide_len).unwrap(), s, permissive));
let _ = image.layer_loadable(slide(
dimensions,
STARTING + TryInto::<Addr>::try_into(idx * slide_len).unwrap(),
s,
permissive,
));
});

image
Expand Down
1 change: 1 addition & 0 deletions slidedeck/src/ferris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub const WIDTH: usize = 31;
/// by [Diggsey](https://github.com/Diggsey).
///
/// Non-ASCII characters were replaced (just `¬` -> `~`).
#[rustfmt::skip]
pub static SLIDES: [& str; 68] = [
concat!(
r#" "#,
Expand Down
3 changes: 2 additions & 1 deletion slidedeck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ mod misc;
fn main() {
FileBackedMemoryShim::with_initialized_memory("slides.mem", ferris::slide_deck())
.flush()
.map_err(|_| std::io::Error::last_os_error()).unwrap();
.map_err(|_| std::io::Error::last_os_error())
.unwrap();
}
1 change: 1 addition & 0 deletions slidedeck/src/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 282cf1a

Please sign in to comment.