Skip to content

Instantly share code, notes, and snippets.

@sean3z
Last active December 30, 2022 01:01
Show Gist options
  • Save sean3z/fbb1e73a85176e3fd75d4909cd7c359e to your computer and use it in GitHub Desktop.
Save sean3z/fbb1e73a85176e3fd75d4909cd7c359e to your computer and use it in GitHub Desktop.
Example throwing Fonts into our cpu.memory
impl Cpu {
pub fn new() -> Cpu {
let mut memory = [0; 4096];
// load fonts into memory
for i in 0..80 {
memory[i] = FONTS[i];
};
Cpu {
// ...
memory: memory,
// ...
}
}
pub fn load_game(&mut self, game: &str) { /* ... */ }
}
static FONTS: [u8; 80] = [
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment