Last active
December 30, 2022 01:01
-
-
Save sean3z/fbb1e73a85176e3fd75d4909cd7c359e to your computer and use it in GitHub Desktop.
Example throwing Fonts into our cpu.memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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