Skip to content

Commit

Permalink
create sprites for all hexadecimal fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
gthvn1 committed Jan 25, 2024
1 parent 2086d46 commit 74e52f5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,37 @@ impl Framebuffer {
}

pub fn draw(&mut self) {
// SPACE INVADER SPRITE
// SPACE INVADER SPRITE. Size 8x6
let space_invader: Vec<u8> = vec![0xBA, 0x7C, 0xD6, 0xFE, 0x54, 0xAA];

for (i, v) in space_invader.iter().enumerate() {
self.set_sprite_line_at(i * WIDTH, v);
}

// 0
let zero: Vec<u8> = vec![0xF0, 0x90, 0x90, 0x90, 0xF0];
let un: Vec<u8> = vec![0x20, 0x60, 0x20, 0x20, 0x70];
let deux: Vec<u8> = vec![0xF0, 0x10, 0xF0, 0x80, 0xF0];
// TODO: This should be mapped in the memory of the chip8
// Fonts size is 8x5
let fonts: Vec<Vec<u8>> = vec![
vec![0xF0, 0x90, 0x90, 0x90, 0xF0], // 0
vec![0x20, 0x60, 0x20, 0x20, 0x70], // 1
vec![0xF0, 0x10, 0xF0, 0x80, 0xF0], // 2
vec![0xF0, 0x10, 0xF0, 0x10, 0xF0], // 3
vec![0x90, 0x90, 0xF0, 0x10, 0x10], // 4
vec![0xF0, 0x80, 0xF0, 0x10, 0xF0], // 5
vec![0xF0, 0x80, 0xF0, 0x90, 0xF0], // 6
vec![0xF0, 0x10, 0x20, 0x40, 0x40], // 7
vec![0xF0, 0x90, 0xF0, 0x90, 0xF0], // 8
vec![0xF0, 0x90, 0xF0, 0x10, 0xF0], // 9
vec![0xF0, 0x90, 0xF0, 0x90, 0x90], // A
vec![0xE0, 0x90, 0xE0, 0x90, 0xE0], // B
vec![0xF0, 0x80, 0x80, 0x80, 0xF0], // C
vec![0xE0, 0x90, 0x90, 0x90, 0xE0], // D
vec![0xF0, 0x80, 0xF0, 0x80, 0xF0], // E
vec![0xF0, 0x80, 0xF0, 0x80, 0x80], // F
];

let zero = &fonts[0];
let un = &fonts[1];
let deux = &fonts[2];

for (i, v) in zero.iter().enumerate() {
self.set_sprite_line_at(i * WIDTH + 0x8, v);
Expand Down

0 comments on commit 74e52f5

Please sign in to comment.