Skip to content

Commit

Permalink
Fix test to make them compile
Browse files Browse the repository at this point in the history
  • Loading branch information
rgiot committed Nov 16, 2021
1 parent 6b832e1 commit 2d9bbe3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions cpclib-image/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fn encode(pens: &[Vec<Pen>], mode: Mode) -> Vec<Vec<u8>> {
match mode {
Mode::Zero => pixels::mode0::pens_to_vec(input_row),
Mode::One => pixels::mode1::pens_to_vec(input_row),
Mode::Two => pixels::mode2::pens_to_vec(input_row),
_ => panic!("Unimplemented yet ..."),
}
};
Expand Down
23 changes: 23 additions & 0 deletions cpclib-image/src/pixels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ pub mod mode2 {
]
}


/// Convert a vector of pens into a vector of bytes
pub fn pens_to_vec(pens: &[Pen]) -> Vec<u8> {
assert!(pens.len() % 8 == 0);

let mut res = Vec::new();
for idx in 0..(pens.len() / 8) {
res.push(pens_to_byte(
pens[idx * 8 + 0],
pens[idx * 8 + 1],
pens[idx * 8 + 2],
pens[idx * 8 + 3],
pens[idx * 8 + 4],
pens[idx * 8 + 5],
pens[idx * 8 + 6],
pens[idx * 8 + 7],
));
}

res
}


pub fn pens_to_byte(pen0: Pen, pen1: Pen, pen2: Pen, pen3: Pen, pen4: Pen, pen5: Pen, pen6: Pen, pen7: Pen) -> u8 {
pen_to_pixel_byte(pen0, PixelPosition::First)
+ pen_to_pixel_byte(pen1, PixelPosition::Second)
Expand Down
1 change: 1 addition & 0 deletions cpclib-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/cpcsdk/rust.cpclib"

[dependencies]
cpclib-asm = "0.5.0"
cpclib-common = "0.5.0"

syn = "1.0.73"
quote = "1.0.9"
Expand Down
5 changes: 3 additions & 2 deletions cpclib-macros/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cpclib_asm::preamble::{
};
use proc_macro2::*;
use quote::TokenStreamExt;
use cpclib_common::smol_str::SmolStr;

fn upper_first(repr: &str) -> String {
format!("{}{}", repr[0..=0].to_uppercase(), repr[1..].to_lowercase())
Expand Down Expand Up @@ -47,9 +48,9 @@ impl MyToTokens for String {
}
}

impl MyToTokens for SmallStr {
impl MyToTokens for SmolStr {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append(Ident::new("SmallStr", Span::call_site()));
tokens.append(Ident::new("SmolStr", Span::call_site()));
tokens.append(Punct::new(':', Spacing::Joint));
tokens.append(Punct::new(':', Spacing::Joint));
tokens.append(Ident::new("new", Span::call_site()));
Expand Down
8 changes: 4 additions & 4 deletions cpclib-z80emu/src/emul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ mod test {
fn jp_symbol() {
let mut z80 = Z80::default();
let mut symbols = SymbolsTableCaseDependent::default();
symbols.set_symbol_to_value("LABEL", 0x4000);
symbols.set_symbol_to_value("LABEL", 0x4000u16);
z80.setup_symbol_table(&symbols);

z80.pc_mut().set(0x4000);
Expand All @@ -460,7 +460,7 @@ mod test {
z80.execute(&Token::OpCode(
Mnemonic::Jp,
None,
Some(DataAccess::Expression(Expr::Label("LABEL".to_owned()))),
Some(DataAccess::Expression(Expr::Label("LABEL".into()))),
None,
));

Expand All @@ -477,7 +477,7 @@ mod test {
z80.execute(&Token::OpCode(
Mnemonic::Jp,
None,
Some(DataAccess::Expression(Expr::Label("$".to_owned()))),
Some(DataAccess::Expression(Expr::Label("$".into()))),
None,
));

Expand All @@ -494,7 +494,7 @@ mod test {
z80.execute(&Token::OpCode(
Mnemonic::Jr,
None,
Some(DataAccess::Expression(Expr::Label("$".to_owned()))),
Some(DataAccess::Expression(Expr::Label("$".into()))),
None,
));

Expand Down

0 comments on commit 2d9bbe3

Please sign in to comment.