Skip to content

Instantly share code, notes, and snippets.

@simias
Last active Oct 25, 2017
Embed
What would you like to do?
fn main() {
let font =
[
[ /* space */
0b100,
0b001,
0b000,
0b000,
0b010,
],
[ /* ! */
0b010,
0b010,
0b010,
0b000,
0b010,
],
[ /* " */
0b101,
0b101,
0b000,
0b000,
0b000,
],
[ /* # */
0b101,
0b111,
0b101,
0b111,
0b101,
],
[ /* $ */
0b011,
0b110,
0b010,
0b011,
0b110,
],
[ /* % */
0b101,
0b001,
0b010,
0b100,
0b101,
],
[ /* & */
0b010,
0b101,
0b011,
0b110,
0b011,
],
[ /* ' */
0b010,
0b010,
0b000,
0b000,
0b000,
],
[ /* ( */
0b001,
0b010,
0b110,
0b010,
0b001,
],
[ /* ) */
0b100,
0b010,
0b011,
0b010,
0b100,
],
[ /* * */
0b000,
0b101,
0b010,
0b101,
0b000,
],
[ /* + */
0b000,
0b010,
0b111,
0b010,
0b000,
],
[ /* , */
0b000,
0b000,
0b000,
0b010,
0b100,
],
[ /* - */
0b000,
0b000,
0b111,
0b000,
0b000,
],
[ /* . */
0b000,
0b000,
0b000,
0b000,
0b010,
],
[ /* / */
0b001,
0b001,
0b010,
0b100,
0b100,
],
[ /* 0 */
0b111,
0b101,
0b101,
0b101,
0b111,
],
[ /* 1 */
0b010,
0b110,
0b010,
0b010,
0b111,
],
[ /* 2 */
0b110,
0b001,
0b010,
0b100,
0b111,
],
[ /* 3 */
0b110,
0b001,
0b110,
0b001,
0b110,
],
[ /* 4 */
0b101,
0b101,
0b111,
0b001,
0b001,
],
[ /* 5 */
0b111,
0b100,
0b111,
0b001,
0b111,
],
[ /* 6 */
0b111,
0b100,
0b111,
0b101,
0b111,
],
[ /* 7 */
0b111,
0b001,
0b010,
0b100,
0b100,
],
[ /* 8 */
0b010,
0b101,
0b010,
0b101,
0b010,
],
[ /* 9 */
0b111,
0b101,
0b111,
0b001,
0b111,
],
[ /* : */
0b000,
0b010,
0b000,
0b010,
0b000,
],
[ /* ; */
0b000,
0b010,
0b000,
0b010,
0b100,
],
[ /* < */
0b000,
0b010,
0b100,
0b010,
0b000,
],
[ /* = */
0b000,
0b111,
0b000,
0b111,
0b000,
],
[ /* > */
0b000,
0b010,
0b001,
0b010,
0b000,
],
[ /* ? */
0b111,
0b001,
0b011,
0b000,
0b010,
],
[ /* @ */
0b111,
0b101,
0b001,
0b111,
0b111,
],
[ /* A */
0b010,
0b101,
0b111,
0b101,
0b101,
],
[ /* B */
0b110,
0b101,
0b110,
0b101,
0b11,
],
[ /* C */
0b011,
0b100,
0b100,
0b100,
0b011,
],
[ /* D */
0b11,
0b101,
0b101,
0b101,
0b110,
],
[ /* E */
0b111,
0b100,
0b110,
0b100,
0b111,
],
[ /* F */
0b111,
0b100,
0b110,
0b100,
0b100,
],
[ /* G */
0b011,
0b100,
0b101,
0b101,
0b010,
],
[ /* H */
0b101,
0b101,
0b111,
0b101,
0b101,
],
[ /* I */
0b111,
0b010,
0b010,
0b010,
0b111,
],
[ /* J */
0b001,
0b001,
0b001,
0b101,
0b111,
],
[ /* K */
0b101,
0b101,
0b110,
0b101,
0b101,
],
[ /* L */
0b100,
0b100,
0b100,
0b100,
0b111,
],
[ /* M */
0b101,
0b111,
0b101,
0b101,
0b101,
],
[ /* N */
0b110,
0b101,
0b101,
0b101,
0b101,
],
[ /* O */
0b010,
0b101,
0b101,
0b101,
0b010,
],
[ /* P */
0b111,
0b101,
0b111,
0b100,
0b100,
],
[ /* Q */
0b111,
0b101,
0b101,
0b111,
0b001,
],
[ /* R */
0b111,
0b101,
0b111,
0b110,
0b101,
],
[ /* S */
0b111,
0b100,
0b111,
0b001,
0b111,
],
[ /* T */
0b111,
0b010,
0b010,
0b010,
0b010,
],
[ /* U */
0b101,
0b101,
0b101,
0b101,
0b111,
],
[ /* V */
0b101,
0b101,
0b101,
0b101,
0b010,
],
[ /* W */
0b101,
0b101,
0b101,
0b111,
0b101,
],
[ /* X */
0b101,
0b101,
0b010,
0b101,
0b101,
],
[ /* Y */
0b101,
0b101,
0b010,
0b010,
0b010,
],
[ /* Z */
0b111,
0b001,
0b010,
0b100,
0b111,
],
[ /* [ */
0b110,
0b100,
0b100,
0b100,
0b110,
],
[ /* \ */
0b100,
0b100,
0b010,
0b001,
0b001,
],
[ /* ] */
0b011,
0b001,
0b001,
0b001,
0b011,
],
[ /* ^ */
0b010,
0b101,
0b000,
0b000,
0b000,
],
[ /* _ */
0b000,
0b000,
0b000,
0b000,
0b111,
],
[ /* ` */
0b100,
0b010,
0b000,
0b000,
0b000,
],
[ /* a */
0b000,
0b010,
0b101,
0b101,
0b011,
],
[ /* b */
0b100,
0b100,
0b110,
0b101,
0b110,
],
[ /* c */
0b000,
0b011,
0b100,
0b100,
0b011,
],
[ /* */
0b001,
0b001,
0b011,
0b101,
0b011,
],
[ /* */
0b000,
0b010,
0b101,
0b110,
0b011,
],
[ /* f */
0b011,
0b010,
0b111,
0b010,
0b010,
],
[ /* g */
0b000,
0b010,
0b101,
0b011,
0b100,
],
[ /* h */
0b100,
0b100,
0b110,
0b101,
0b101,
],
[ /* i */
0b000,
0b010,
0b000,
0b010,
0b010,
],
[ /* j */
0b001,
0b000,
0b001,
0b001,
0b010,
],
[ /* k */
0b100,
0b100,
0b101,
0b110,
0b101,
],
[ /* l */
0b000,
0b010,
0b010,
0b010,
0b011,
],
[ /* m */
0b000,
0b111,
0b111,
0b101,
0b101,
],
[ /* n */
0b000,
0b110,
0b101,
0b101,
0b101,
],
[ /* o */
0b000,
0b010,
0b101,
0b101,
0b010,
],
[ /* p */
0b000,
0b110,
0b101,
0b110,
0b100,
],
[ /* q */
0b000,
0b011,
0b101,
0b011,
0b001,
],
[ /* r */
0b000,
0b100,
0b110,
0b100,
0b100,
],
[ /* s */
0b000,
0b010,
0b100,
0b010,
0b100,
],
[ /* t */
0b000,
0b010,
0b111,
0b010,
0b011,
],
[ /* u */
0b000,
0b101,
0b101,
0b101,
0b111,
],
[ /* v */
0b000,
0b101,
0b101,
0b101,
0b010,
],
[ /* w */
0b000,
0b101,
0b101,
0b111,
0b111,
],
[ /* x */
0b000,
0b101,
0b010,
0b010,
0b101,
],
[ /* y */
0b000,
0b101,
0b101,
0b010,
0b110,
],
[ /* z */
0b000,
0b111,
0b011,
0b110,
0b111,
],
[ /* { */
0b011,
0b010,
0b110,
0b010,
0b011,
],
[ /* | */
0b010,
0b010,
0b010,
0b010,
0b010,
],
[ /* } */
0b110,
0b010,
0b011,
0b010,
0b110,
],
[ /* ~ */
0b000,
0b001,
0b111,
0b100,
0b000,
],
];
/* Generate a 4bpp texture, 64 char per line */
/* one char */
let buf_bits = 3 * 5 * 4;
/* two lines of 64 chars */
let buf_bits = buf_bits * 64 * 2;
/* convert into bytes */
let buf_bytes = buf_bits / 8;
let mut buf = vec![0u8; buf_bytes];
for (i, c) in font.iter().enumerate() {
for (y, line) in c.iter().enumerate() {
for x in 0..3 {
let col =
if line & (0b100 >> x) != 0 {
1
} else {
0
};
let y = y + (i / 64) * 5;
let x = x + (i % 64) * 3;
let byte_x = x / 2;
let low_nibble = (x & 1) != 0;
buf[y * (3 * 64 / 2) + byte_x] |=
if low_nibble {
col << 4
} else {
col
};
}
}
}
for y in 0..10 {
for x in 0..((64 * 3) / 4) {
let b0 = buf[y * (64 * 3) / 2 + x * 2];
let b1 = buf[y * (64 * 3) / 2 + x * 2 + 1];
print!("0x{:02x}{:02x}, ", b1, b0);
if x % 8 == 7 {
println!("");
}
}
}
println!("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment